- fix: when show function tips, can't correctly calcuate the current position in the function param list
This commit is contained in:
parent
3fca3e7216
commit
02813587fd
1
NEWS.md
1
NEWS.md
|
@ -5,6 +5,7 @@ Red Panda C++ Version 0.13.3
|
||||||
- fix: If project's compiler set is not the same with the default compiler set, auto openned project's file will use wrong compiler set to do syntax check.
|
- fix: If project's compiler set is not the same with the default compiler set, auto openned project's file will use wrong compiler set to do syntax check.
|
||||||
- change: symbols that exactly match are sorted to the front in the code suggestion popup list
|
- change: symbols that exactly match are sorted to the front in the code suggestion popup list
|
||||||
- fix: symbols defind locally should be sorted to the front in the code suggestion popup list
|
- fix: symbols defind locally should be sorted to the front in the code suggestion popup list
|
||||||
|
- fix: when show function tips, can't correctly calcuate the current position in the function param list
|
||||||
|
|
||||||
Red Panda C++ Version 0.13.2
|
Red Panda C++ Version 0.13.2
|
||||||
- fix: "delete and exit" button in the environtment / folder option page doesn't work correctly
|
- fix: "delete and exit" button in the environtment / folder option page doesn't work correctly
|
||||||
|
|
|
@ -3182,152 +3182,128 @@ void Editor::updateFunctionTip()
|
||||||
pMainWindow->functionTip()->hide();
|
pMainWindow->functionTip()->hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferCoord caretPos = caretXY();
|
if (!highlighter())
|
||||||
ContentsCoord curPos = fromBufferCoord(caretPos);
|
return;
|
||||||
ContentsCoord cursorPos = curPos;
|
|
||||||
int nBraces = 0;
|
bool isFunction = false;
|
||||||
int nCommas = 0;
|
auto action = finally([&isFunction]{
|
||||||
int FMaxScanLength = 500;
|
if (!isFunction)
|
||||||
// Find out where the function ends...
|
|
||||||
for (int i=0;i<FMaxScanLength;i++) {
|
|
||||||
// Stopping characters...
|
|
||||||
QChar ch = *curPos;
|
|
||||||
if (ch == '\0' || ch == ';') {
|
|
||||||
pMainWindow->functionTip()->hide();
|
pMainWindow->functionTip()->hide();
|
||||||
return;
|
});
|
||||||
// Opening brace, increase count
|
const int maxLines=20;
|
||||||
}
|
BufferCoord caretPos = caretXY();
|
||||||
QChar nextCh = *(curPos+1);
|
int currentLine = caretPos.Line-1;
|
||||||
if (ch == '(') {
|
int currentChar = caretPos.Char-1;
|
||||||
nBraces++;
|
BufferCoord functionNamePos{-1,-1};
|
||||||
// Ending brace, decrease count or success (found ending)!
|
bool foundFunctionStart = false;
|
||||||
} else if (ch == ')') {
|
int parenthesisLevel = 0;
|
||||||
nBraces--;
|
int braceLevel = 0;
|
||||||
if (nBraces == -1)
|
int bracketLevel = 0;
|
||||||
|
int paramsCount = 1;
|
||||||
|
int currentParamPos = 1;
|
||||||
|
if (currentLine>=lines()->count())
|
||||||
|
return;
|
||||||
|
while (currentLine>=0) {
|
||||||
|
QString line = lines()->getString(currentLine);
|
||||||
|
if (currentLine!=caretPos.Line-1)
|
||||||
|
currentChar = line.length();
|
||||||
|
QStringList tokens;
|
||||||
|
QList<int> positions;
|
||||||
|
if (currentLine==0)
|
||||||
|
highlighter()->resetState();
|
||||||
|
else
|
||||||
|
highlighter()->setState(
|
||||||
|
lines()->ranges(currentLine-1));
|
||||||
|
highlighter()->setLine(line,currentLine);
|
||||||
|
while(!highlighter()->eol()) {
|
||||||
|
int start = highlighter()->getTokenPos();
|
||||||
|
QString token = highlighter()->getToken();
|
||||||
|
PSynHighlighterAttribute attr = highlighter()->getTokenAttribute();
|
||||||
|
if (start>=currentChar)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Single line comments
|
if (attr != highlighter()->commentAttribute()
|
||||||
} else if ((ch == '/') && (nextCh == '/')) {
|
&& attr!=highlighter()->whitespaceAttribute()) {
|
||||||
// Walk up to an enter sequence
|
if (foundFunctionStart) {
|
||||||
while (ch!='\0' && ch!='\n') {
|
if (attr!=highlighter()->identifierAttribute())
|
||||||
curPos+=1;
|
return; // not a function
|
||||||
ch = *curPos;
|
functionNamePos.Line = currentLine+1;
|
||||||
}
|
functionNamePos.Char = start+1;
|
||||||
|
|
||||||
|
|
||||||
// Skip linebreak;
|
|
||||||
if (ch == '\n') {
|
|
||||||
curPos += 1;
|
|
||||||
}
|
|
||||||
} else if ((ch == '/') && (nextCh == '*')) {
|
|
||||||
|
|
||||||
// Walk up to "*/"
|
|
||||||
while (ch!='\0' && !(ch=='*' && nextCh=='/')) {
|
|
||||||
curPos += 1;
|
|
||||||
ch = *curPos;
|
|
||||||
nextCh = *(curPos+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step over
|
|
||||||
if (ch!='\0') {
|
|
||||||
curPos+=1;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
curPos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//qDebug()<<"first pass:"<<nBraces<<" "<<curPos.line()<<":"<<curPos.ch()<<" - '"<<*curPos<<"'";
|
|
||||||
// If we couldn't find the closing brace or reached the FMaxScanLength...
|
|
||||||
if (nBraces!=-1) {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ContentsCoord FFunctionEnd = curPos;
|
|
||||||
|
|
||||||
int paramPos = 0;
|
|
||||||
bool paramPosFounded = false;
|
|
||||||
// We've stopped at the ending ), start walking backwards )*here* with nBraces = -1
|
|
||||||
for (int i=0;i<FMaxScanLength;i++) {
|
|
||||||
QChar ch = *curPos;
|
|
||||||
QChar prevCh = *(curPos-1);
|
|
||||||
if (prevCh == '*' && ch == '/' ) {
|
|
||||||
while (true) {
|
|
||||||
curPos -= 1;
|
|
||||||
ch = *(curPos);
|
|
||||||
prevCh = *(curPos-1);
|
|
||||||
if (prevCh == '\0') {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (prevCh == '/' && ch == '*' ) {
|
|
||||||
curPos -= 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
tokens.append(token);
|
||||||
|
positions.append(start);
|
||||||
|
} else if (attr == highlighter()->commentAttribute()
|
||||||
|
&& currentLine == caretPos.Line-1 && start<caretPos.Char
|
||||||
|
&& start+token.length()>=caretPos.Char) {
|
||||||
|
return; // in comment, do nothing
|
||||||
}
|
}
|
||||||
} else if (ch == ')') {
|
highlighter()->next();
|
||||||
nBraces++ ;
|
}
|
||||||
} else if (ch == '(') {
|
if (!foundFunctionStart) {
|
||||||
nBraces--;
|
for (int i=tokens.length()-1;i>=0;i--) {
|
||||||
if (nBraces == -1) // found it!
|
if (braceLevel>0) {
|
||||||
break;;
|
if (tokens[i]=="{") {
|
||||||
} else if (ch == ',') {
|
braceLevel--;
|
||||||
if (nBraces == 0) {
|
} else if (tokens[i]=="}") {
|
||||||
if (curPos <= cursorPos && !paramPosFounded) {
|
braceLevel++;
|
||||||
paramPos = nCommas;
|
}
|
||||||
paramPosFounded = true;
|
} else if (bracketLevel>0) {
|
||||||
|
if (tokens[i]=="[") {
|
||||||
|
braceLevel--;
|
||||||
|
} else if (tokens[i]=="]") {
|
||||||
|
braceLevel++;
|
||||||
|
}
|
||||||
|
}else if (parenthesisLevel>0){
|
||||||
|
if (tokens[i]==")") {
|
||||||
|
parenthesisLevel++;
|
||||||
|
} else if (tokens[i]=="(") {
|
||||||
|
parenthesisLevel--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug()<<i<<tokens[i];
|
||||||
|
if (tokens[i]=="(") {
|
||||||
|
// found start of function
|
||||||
|
foundFunctionStart = true;
|
||||||
|
if (i>0) {
|
||||||
|
functionNamePos.Line = currentLine+1;
|
||||||
|
functionNamePos.Char = positions[i-1]+1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else if (tokens[i]=="[") {
|
||||||
|
//we are not in a function call
|
||||||
|
return;
|
||||||
|
} else if (tokens[i]=="{") {
|
||||||
|
//we are not in a function call
|
||||||
|
return;
|
||||||
|
} else if (tokens[i]==";") {
|
||||||
|
//we are not in a function call
|
||||||
|
return;
|
||||||
|
} else if (tokens[i]==")") {
|
||||||
|
parenthesisLevel++;
|
||||||
|
} else if (tokens[i]=="}") {
|
||||||
|
braceLevel++;
|
||||||
|
} else if (tokens[i]=="}") {
|
||||||
|
bracketLevel++;
|
||||||
|
} else if (tokens[i]==",") {
|
||||||
|
paramsCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nCommas++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curPos -= 1;
|
if (functionNamePos.Char>=0)
|
||||||
if (curPos.atStart())
|
break;
|
||||||
|
currentLine--;
|
||||||
|
if (caretPos.Line-currentLine>maxLines)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (paramPosFounded)
|
isFunction = functionNamePos.Char>=0;
|
||||||
paramPos = nCommas - paramPos;
|
currentParamPos = paramsCount-1;
|
||||||
|
if (!isFunction)
|
||||||
//qDebug()<<"second pass:"<<nBraces<<","<<nCommas<<","<<paramPos<<" "<<curPos.line()<<":"<<curPos.ch()<<" - '"<<*curPos<<"'";
|
|
||||||
// If we couldn't find the closing brace or reached the FMaxScanLength...
|
|
||||||
if (nBraces!=-1) {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
//ContentsCoord FFunctionStart = curPos;
|
|
||||||
|
|
||||||
// Skip blanks
|
|
||||||
while (!curPos.atStart()) {
|
|
||||||
QChar prevCh = *(curPos-1);
|
|
||||||
if (prevCh == '\t' || prevCh == ' '
|
|
||||||
|| prevCh == '\n') {
|
|
||||||
curPos-=1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ContentsCoord prevPos = curPos-1;
|
|
||||||
if (prevPos.atStart()) {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Get the name of the function we're about to show
|
|
||||||
BufferCoord FuncStartXY = prevPos.toBufferCoord();
|
|
||||||
QString token;
|
|
||||||
PSynHighlighterAttribute HLAttr;
|
|
||||||
if (!getHighlighterAttriAtRowCol(FuncStartXY,token,HLAttr)) {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (HLAttr != highlighter()->identifierAttribute()) {
|
|
||||||
pMainWindow->functionTip()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferCoord pWordBegin, pWordEnd;
|
BufferCoord pWordBegin, pWordEnd;
|
||||||
|
|
||||||
QString s = getWordAtPosition(this, FuncStartXY, pWordBegin,pWordEnd, WordPurpose::wpInformation);
|
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
|
||||||
|
|
||||||
// qDebug()<<QString("find word at %1:%2 - '%3'")
|
// qDebug()<<QString("find word at %1:%2 - '%3'")
|
||||||
// .arg(FuncStartXY.Line)
|
// .arg(FuncStartXY.Line)
|
||||||
|
@ -3342,7 +3318,7 @@ void Editor::updateFunctionTip()
|
||||||
pMainWindow->functionTip()->clearTips();
|
pMainWindow->functionTip()->clearTips();
|
||||||
QList<PStatement> statements=mParser->getListOfFunctions(mFilename,
|
QList<PStatement> statements=mParser->getListOfFunctions(mFilename,
|
||||||
s,
|
s,
|
||||||
FuncStartXY.Line);
|
functionNamePos.Line);
|
||||||
|
|
||||||
foreach (const PStatement statement, statements) {
|
foreach (const PStatement statement, statements) {
|
||||||
pMainWindow->functionTip()->addTip(
|
pMainWindow->functionTip()->addTip(
|
||||||
|
@ -3365,9 +3341,9 @@ void Editor::updateFunctionTip()
|
||||||
pMainWindow->functionTip()->move(mapToGlobal(p));
|
pMainWindow->functionTip()->move(mapToGlobal(p));
|
||||||
|
|
||||||
pMainWindow->functionTip()->setFunctioFullName(s);
|
pMainWindow->functionTip()->setFunctioFullName(s);
|
||||||
pMainWindow->functionTip()->guessFunction(nCommas);
|
pMainWindow->functionTip()->guessFunction(paramsCount-1);
|
||||||
pMainWindow->functionTip()->setParamIndex(
|
pMainWindow->functionTip()->setParamIndex(
|
||||||
paramPos
|
currentParamPos
|
||||||
);
|
);
|
||||||
cancelHint();
|
cancelHint();
|
||||||
pMainWindow->functionTip()->show();
|
pMainWindow->functionTip()->show();
|
||||||
|
|
Loading…
Reference in New Issue