21#include "../terminal/terminal.hpp"
37 return vector<wxString>();
40 vector<int> vMatch =
FindAll(
"procedure", wxSTC_NPRC_COMMAND, 0,
m_editor->GetLastPosition(),
false);
43 return vector<wxString>();
45 vector<wxString> vProcDef;
49 for (
size_t i = 0; i < vMatch.size(); i++)
51 int pos = vMatch[i]+9;
56 if (pos == wxSTC_INVALID_POSITION)
87 if (!sSymbol.length())
93 nStyle = wxSTC_NSCR_IDENTIFIER;
96 while ((nCurrentPos =
m_editor->FindText(nStartPos, nEndPos, sSymbol, wxSTC_FIND_MATCHCASE | wxSTC_FIND_WHOLEWORD)) != wxSTC_INVALID_POSITION)
98 nStartPos = nCurrentPos+1;
101 if (
m_editor->GetCharAt(nCurrentPos-1) !=
'.'
102 && (
m_editor->GetStyleAt(nCurrentPos) == nStyle
105 vMatches.push_back(nCurrentPos);
122 int startPosition =
m_editor->WordStartPosition(charpos,
true);
123 int endPosition =
m_editor->WordEndPosition(charpos,
true);
125 wxString clickedWord =
m_editor->GetTextRange(startPosition, endPosition);
160 int startPosition =
m_editor->WordStartPosition(charpos,
true);
161 int endPosition =
m_editor->WordEndPosition(startPosition + 1,
true);
164 while (startPosition &&
m_editor->GetStyleAt(startPosition - 1) == wxSTC_NSCR_INCLUDES &&
m_editor->GetCharAt(startPosition - 1) !=
'@')
168 if (
m_editor->GetCharAt(startPosition) ==
'"')
173 while (endPosition < m_editor->GetLastPosition() &&
m_editor->GetStyleAt(endPosition) == wxSTC_NSCR_INCLUDES &&
m_editor->GetCharAt(endPosition) !=
':' &&
m_editor->GetCharAt(endPosition) !=
'"')
177 wxString clickedWord =
m_editor->GetTextRange(startPosition, endPosition);
181 if (clickedWord.find(
'<') != string::npos)
183 if (clickedWord.find(
"<>") != string::npos)
186 if (clickedWord.find(
"<this>") != string::npos)
187 clickedWord.replace(clickedWord.find(
"<this>"), 6,
m_editor->
GetFileName().GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
189 if (clickedWord.find(
"<loadpath>") != string::npos)
192 if (clickedWord.find(
"<savepath>") != string::npos)
195 if (clickedWord.find(
"<scriptpath>") != string::npos)
198 if (clickedWord.find(
"<procpath>") != string::npos)
201 if (clickedWord.find(
"<plotpath>") != string::npos)
206 if (clickedWord.length() > 2 && ((isalpha(clickedWord[0]) && clickedWord[1] ==
':') || clickedWord[0] ==
'.'))
245 int startPosition =
m_editor->WordStartPosition(charpos,
true);
246 int endPosition =
m_editor->WordEndPosition(charpos,
true);
249 while (startPosition &&
m_editor->GetStyleAt(startPosition - 1) == wxSTC_NSCR_PROCEDURES)
253 while (endPosition < m_editor->GetLastPosition()
254 &&
m_editor->GetStyleAt(endPosition) == wxSTC_NSCR_PROCEDURES
255 &&
m_editor->GetCharAt(endPosition) !=
'\r'
256 &&
m_editor->GetCharAt(endPosition) !=
'\n')
261 if (ignoreDefinitions)
263 wxString currentline =
m_editor->GetLine(
m_editor->LineFromPosition(startPosition));
265 if (currentline.find(
"procedure") != string::npos && currentline[currentline.find_first_not_of(
' ', currentline.find(
"procedure") + 9)] ==
'$')
270 wxString clickedWord =
m_editor->GetTextRange(startPosition, endPosition);
276 clickedWord.insert(1,
"thisfile~");
288 if (!sNameSpace.length() && !ignoreDefinitions)
293 if (sNameSpace.length())
295 if (clickedWord[0] ==
'$')
296 clickedWord.insert(1, sNameSpace +
"~");
298 clickedWord =
"$" + sNameSpace +
"~" + clickedWord;
306 if (clickedWord.find(
'~') != string::npos)
307 clickedWord.erase(1, clickedWord.rfind(
'~'));
309 if (clickedWord[0] !=
'$')
310 clickedWord.insert(0, 1,
'$');
313 return clickedWord +
"()";
335 int maxpos = charpos;
342 vector<int> namespaces =
FindAll(
"namespace", wxSTC_NPRC_COMMAND, minpos, maxpos,
false);
346 if (namespaces.size())
369 wxString sThisFileProcedures;
372 for (
int i = 0; i <
m_editor->GetLineCount(); i++)
374 wxString currentline =
m_editor->GetLine(i);
377 if (currentline.find(
"procedure") != string::npos
378 && currentline.find(
'$', currentline.find(
"procedure")) != string::npos
382 currentline.erase(0, currentline.find(
'$') + 1);
384 if (currentline.find(
'(') == string::npos)
387 currentline.erase(currentline.find(
'('));
390 if (currentline.substr(0, sFirstChars.length()) == sFirstChars)
395 if (sSelectedNameSpace.length())
396 return sThisFileProcedures;
418 wxString procedurename = pathname.substr(pathname.rfind(
'~') + 1);
421 if (pathname.find(
"$this~") != string::npos)
425 pathname.replace(pathname.find(
"$this~"), 6, thispath.substr(0, thispath.rfind(
'\\') + 1));
427 while (pathname.find(
'~') != string::npos)
428 pathname[pathname.find(
'~')] =
'\\';
430 else if (pathname.find(
"$thisfile~") != string::npos)
438 if (pathname.find(
"$main~") != string::npos)
439 pathname.erase(pathname.find(
"$main~") + 1, 5);
441 while (pathname.find(
'~') != string::npos)
442 pathname[pathname.find(
'~')] =
'/';
445 if (pathname[0] ==
'$' && pathname.find(
':') == string::npos)
446 pathname.replace(0, 1, vPaths[
PROCPATH] +
"/");
447 else if (pathname.find(
':') == string::npos)
448 pathname.insert(0, vPaths[
PROCPATH]);
452 pathname = pathname.substr(pathname.find(
'\'') + 1, pathname.rfind(
'\'') - pathname.find(
'\'') - 1);
457 while (procedurename.find(
'\'') != string::npos)
458 procedurename.erase(procedurename.find(
'\''), 1);
460 if (procedurename.find(
'/') != string::npos)
461 procedurename =
"$" + procedurename.substr(procedurename.rfind(
'/') + 1);
463 if (procedurename.find(
'\\') != string::npos)
464 procedurename =
"$" + procedurename.substr(procedurename.rfind(
'\\') + 1);
466 if (procedurename[0] !=
'$')
467 procedurename.insert(0, 1,
'$');
492 wxString procedureline;
497 m_editor->SetWrapMode(wxSTC_WRAP_WORD);
498 m_editor->SetWrapMode(wxSTC_WRAP_NONE);
503 vector<int> procedures =
FindAll(
"procedure", wxSTC_NSCR_COMMAND, 0,
m_editor->GetLastPosition(),
false);
506 for (
size_t i = 0; i < procedures.size(); i++)
508 procedureline =
m_editor->GetLine(
m_editor->LineFromPosition(procedures[i]));
510 if (procedureline.find(
"$" + procedurename) != string::npos && procedureline[procedureline.find_first_not_of(
' ', procedureline.find(
"$" + procedurename) + procedurename.length() + 1)] ==
'(')
512 if (
getMatchingParenthesis(procedureline.substr(procedureline.find(
"$" + procedurename)).ToStdString()) == string::npos)
516 string sProcDef = procedureline.substr(procedureline.find(
"$" + procedurename),
getMatchingParenthesis(procedureline.substr(procedureline.find(
"$" + procedurename)).ToStdString()) + 1).ToStdString();
517 size_t nFirstParens = sProcDef.find(
'(');
518 string sArgList = sProcDef.substr(nFirstParens + 1,
getMatchingParenthesis(sProcDef.substr(nFirstParens)) - 1);
519 sProcDef.erase(nFirstParens + 1);
522 while (sArgList.length())
526 if (currentarg.front() ==
'_')
527 currentarg.erase(0, 1);
529 sProcDef += currentarg;
531 if (sArgList.length())
535 sProcDef +=
") :: local";
538 if (procedureline.find(
"::") != string::npos)
540 string sFlags = procedureline.substr(procedureline.find(
"::") + 2).ToStdString();
542 if (sFlags.find(
"##") != string::npos)
543 sFlags.erase(sFlags.find(
"##"));
545 if (sFlags.find_first_of(
"\r\n") != string::npos)
546 sFlags.erase(sFlags.find_first_of(
"\r\n"));
549 sProcDef +=
" " + sFlags;
552 wxString sDocumentation;
556 for (
int docline =
m_editor->LineFromPosition(procedures[i])-1; docline >= 0; docline--)
561 if (docline < m_editor->LineFromPosition(procedures[i])-1)
563 for (
int curline = docline+1; curline <
m_editor->LineFromPosition(procedures[i]); curline++)
565 wxString curdocline =
m_editor->GetLine(curline);
566 curdocline.erase(0, curdocline.find_first_not_of(
" \t#*!"));
567 curdocline.erase(curdocline.find_first_of(
"\r\n"));
569 if (curdocline.find(
"*#") != string::npos)
570 curdocline.erase(curdocline.find(
"*#"));
581 if (!sDocumentation.length())
583 for (
int docline =
m_editor->LineFromPosition(procedures[i])+1; docline < m_editor->GetLineCount(); docline++)
588 if (docline >
m_editor->LineFromPosition(procedures[i])+1)
590 for (
int curline =
m_editor->LineFromPosition(procedures[i])+1; curline < docline; curline++)
592 wxString curdocline =
m_editor->GetLine(curline);
593 curdocline.erase(0, curdocline.find_first_not_of(
" \t#*!"));
594 curdocline.erase(curdocline.find_first_of(
"\r\n"));
608 if (sDocumentation.length())
610 if (sDocumentation.substr(0, 3) ==
"-> ")
611 sProcDef +=
" " + sDocumentation.ToStdString();
613 sProcDef +=
"\n" + sDocumentation.ToStdString();
649 static bool bBeginEnd =
false;
651 if (sNewDocLine.find_first_not_of(
" \t") == string::npos)
653 if (sDocumentation.length())
654 sDocumentation +=
"\n ";
660 if (sNewDocLine.find(
"\\begin{") != string::npos && sNewDocLine.find(
"\\end{") == string::npos)
662 if (sDocumentation.length() && sDocumentation[sDocumentation.length()-1] !=
'\n')
663 sDocumentation +=
"\n ";
667 else if (sNewDocLine.find(
"\\begin{") == string::npos && sNewDocLine.find(
"\\end{") != string::npos)
669 if (sDocumentation.length() && sDocumentation[sDocumentation.length()-1] !=
'\n')
670 sDocumentation +=
"\n ";
674 else if ((sNewDocLine.length()
675 && (sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 2) ==
"- "
676 || sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 7) ==
"\\param "
677 || sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"), 8) ==
"\\remark ")) || bBeginEnd)
679 if (sDocumentation.length() && sDocumentation[sDocumentation.length()-1] !=
'\n')
680 sDocumentation +=
"\n ";
684 if (sDocumentation.length() && sDocumentation[sDocumentation.length()-1] !=
' ')
685 sDocumentation +=
" ";
688 sDocumentation += sNewDocLine.substr(sNewDocLine.find_first_not_of(
" \t"));
689 size_t nPos = sDocumentation.find(
"\\procedure{");
691 if (nPos != string::npos)
692 sDocumentation.erase(nPos, sDocumentation.find(
'}', nPos)+1 - nPos);
693 else if ((nPos = sDocumentation.find(
"\\procedure ")) != string::npos)
695 size_t nPos2 = nPos + 10;
696 nPos2 = sDocumentation.find_first_not_of(
" \r\n", nPos2);
697 nPos2 = sDocumentation.find_first_of(
" \r\n", nPos2);
698 sDocumentation.erase(nPos, nPos2-nPos);
714 string sDocumentation = __sDoc.ToStdString();
715 std::string sReturns;
717 if (sDocumentation.find_first_not_of(
" \n") != string::npos)
720 sDocumentation.erase(0, sDocumentation.find_first_not_of(
" \n"));
722 if (sDocumentation.back() ==
' ' || sDocumentation.back() ==
'\n')
723 sDocumentation.erase(sDocumentation.find_last_not_of(
" \n")+1);
725 size_t nPos = sDocumentation.find(
"\\param ");
728 if (nPos != string::npos)
731 if (nPos > 5 && sDocumentation.substr(nPos-5, 5) !=
"\n ")
736 while ((nPos = sDocumentation.find(
"\\param ")) != string::npos)
738 sDocumentation.replace(nPos, 6,
"-");
739 size_t spacePos = sDocumentation.find(
' ', sDocumentation.find_first_not_of(
' ', nPos+1));
741 if (spacePos == std::string::npos)
744 sDocumentation.insert(spacePos,
":");
746 if (sDocumentation[sDocumentation.find_first_not_of(
' ', nPos+1)] ==
'_')
747 sDocumentation.erase(sDocumentation.find_first_not_of(
' ', nPos+1), 1);
752 while ((nPos = sDocumentation.find(
"\\return ")) != string::npos)
756 size_t newReturn =
std::min(sDocumentation.find(
"\\return ", nPos+1), sDocumentation.find(
"\\remark ", nPos+1));
761 std::string sCurrReturn = sDocumentation.substr(nPos+8, newReturn-nPos-8);
762 sDocumentation.erase(nPos, newReturn-nPos);
764 while (sDocumentation.front() ==
' ')
765 sDocumentation.erase(0, 1);
767 if (sReturns.length())
770 sReturns += sCurrReturn.substr(0, sCurrReturn.find(
' '));
774 while ((nPos = sDocumentation.find(
"\\remark ")) != string::npos)
778 while ((nPos = sDocumentation.find(
"!!")) != string::npos)
779 sDocumentation.erase(nPos, 2);
786 while ((nMatch = sDocumentation.find(
"\\begin{")) != string::npos)
788 sDocumentation.erase(nMatch, sDocumentation.find(
'}', nMatch) + 1 - nMatch);
790 if (sDocumentation.substr(nMatch, 5) ==
"\n ")
791 sDocumentation.erase(nMatch, 5);
794 while ((nMatch = sDocumentation.find(
"\\end{")) != string::npos)
796 sDocumentation.erase(nMatch, sDocumentation.find(
'}', nMatch) + 1 - nMatch + 1);
805 if (sReturns.length())
807 if (sReturns.find(
',') == std::string::npos)
808 sDocumentation.insert(0,
"-> " + sReturns +
"\n");
810 sDocumentation.insert(0,
"-> {" + sReturns +
"}\n");
814 sDocumentation.clear();
816 return sDocumentation;
831 vector<int> procedureheads;
836 procedureheads =
FindAll(
"procedure", wxSTC_NSCR_COMMAND, 0, pos,
false);
838 procedureheads =
FindAll(
"function", wxSTC_MATLAB_KEYWORD, 0, pos,
false);
841 if (procedureheads.size())
842 return procedureheads.back();
863 for (
int i = 0; i <
m_editor->LineFromPosition(
m_editor->GetLastPosition()); i++)
865 wxString currentline =
m_editor->GetLine(i);
867 if (currentline.find(
"procedure") != string::npos && currentline.find(sNamingProcedure) != string::npos)
869 int linepos =
m_editor->PositionFromLine(i);
872 while (currentline.find(
"procedure", offset) != string::npos &&
m_editor->GetStyleAt(linepos + currentline.find(
"procedure", offset) + 1) != wxSTC_NPRC_COMMAND)
873 offset = currentline.find(
"procedure", offset) + 10;
876 if (currentline.find(
"procedure", offset) != string::npos &&
m_editor->GetStyleAt(linepos + currentline.find(
"procedure", offset) + 1) == wxSTC_NPRC_COMMAND)
878 int procloc = currentline.find(
"procedure", offset) + 9;
880 while (currentline.find(sNamingProcedure, procloc) != string::npos &&
m_editor->GetStyleAt(linepos + currentline.find(sNamingProcedure, procloc) + 1) != wxSTC_NPRC_PROCEDURES)
881 procloc = currentline.find(sNamingProcedure, procloc) + 1 + sNamingProcedure.length();
884 if (currentline.find(sNamingProcedure, procloc) != string::npos &&
m_editor->GetStyleAt(linepos + currentline.find(sNamingProcedure) + 1) == wxSTC_NPRC_PROCEDURES)
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
std::string addLinebreaks(const std::string &sLine, bool onlyDocumentation=false)
Adds linebreaks to the call tip language strings.
bool isStyleType(StyleType _type, int nPos)
Determine the syntax style type at the selected position.
wxString m_clickedInclude
wxString m_clickedProcedure
FileFilterType m_fileType
size_t m_clickedWordLength
@ STYLE_COMMENT_SECTION_BLOCK
@ STYLE_COMMENT_SECTION_LINE
wxString GetFileNameAndPath()
std::string getNameSpaceAutoCompList(std::string sFirstChars)
This function returns the autocompletion list for the namespaces.
std::vector< std::string > getPathSettings()
Returns the standard paths as a STL vector.
void AppendToDocumentation(wxString &sDocumentation, const wxString &sNewDocLine)
Appends the text to the current documentation.
std::vector< int > FindAll(const wxString &sSymbol, int nStyle, int nStartPos=0, int nEndPos=-1, bool bSearchInComments=false)
Finds all occurences of a code symbol considering the style.
int FindNamingProcedure()
Searches the file for the naming procedure.
wxString FindProceduresInCurrentFile(wxString sFirstChars, wxString sSelectedNameSpace)
Finds procedures, which might match the passed word start.
wxString FindMarkedProcedure(int charpos, bool ignoreDefinitions=true)
Extracts the procedure call at the selected position.
wxString FindNameSpaceOfProcedure(int charpos)
Finds the current namespace for the procedure call.
std::string CleanDocumentation(const wxString &__sDoc)
Checks layout and finishes styling of the documentation string.
wxString GetNameOfNamingProcedure()
Returns the required procedure name for the current file.
wxString FindProcedureDefinition()
Searches the definition below the cursor.
wxString FindProcedureDefinitionInLocalFile(const wxString &procedurename)
Search the procedure definition in the local file.
wxString FindMarkedInclude(int charpos)
Constructs the file name of the included file.
NumeReTerminal * m_terminal
wxString FindClickedProcedure()
Gets the name of the clicked procedure.
wxString FindClickedInclude()
Gets the name of the clicked include file.
std::vector< wxString > getProceduresInFile()
Creates a list of procedures in the current file.
int FindCurrentProcedureHead(int pos)
Find the procedure head line for the selected position.
wxString FindClickedWord()
Returns the word under the cursor while clicking.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
CallTip FindProcedureDefinition(const std::string &pathname, const std::string &procedurename)
Search the procedure definition in a global file.
CallTip addLinebreaks(CallTip _cTip, size_t maxLineLength)
Adds the necessary linebreaks to the documentation part of the CallTip to fit inside the desired maxi...
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure contains the data for a single calltip, which might be shown in the editor or the term...
std::string sDocumentation
std::string toString(int)
Converts an integer to a string without the Settings bloat.