- fix: Caret on '('/',' in string shouldn't invoke function info tips.

This commit is contained in:
Roy Qu 2024-03-24 10:41:03 +08:00
parent 2cad9262c9
commit 3be7a72fb9
2 changed files with 24 additions and 12 deletions

View File

@ -79,6 +79,8 @@ Red Panda C++ Version 2.27
- enhancement: Improve lambda expression support.
- enhancement: Show type completion hint after "constexpr"/"extern"/"static"/"consteval"/"constinit"/"const"/"volatile"/"inline" etc.
- enhancement: Restore line position after file is modified outside and reloaded.
- fix: Caret on '('/',' in string/comment shouldn't invoke function info tips.
- fix: Function name not correctly found if it and the '(' is not in one line;
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -4225,22 +4225,20 @@ void Editor::updateFunctionTip(bool showTip)
QSynedit::PTokenAttribute attr = syntaxer()->getTokenAttribute();
if (start>=currentChar)
break;
if (
(attr->tokenType() == QSynedit::TokenType::Comment
|| attr->tokenType() == QSynedit::TokenType::String
)
&& currentLine == caretPos.line-1 && start<caretPos.ch-1
&& start+token.length()>=caretPos.ch-1) {
return; // in comment/string, do nothing
}
if (attr->tokenType() != QSynedit::TokenType::Comment
&& attr->tokenType() != QSynedit::TokenType::Space) {
if (foundFunctionStart) {
if (attr!=syntaxer()->identifierAttribute())
return; // not a function
functionNamePos.line = currentLine+1;
functionNamePos.ch = start+1;
break;
}
if (attr->tokenType() == QSynedit::TokenType::String)
token="\"\"";
tokens.append(token);
positions.append(start);
} else if (attr->tokenType() == QSynedit::TokenType::Comment
&& currentLine == caretPos.line-1 && start<caretPos.ch
&& start+token.length()>=caretPos.ch) {
return; // in comment, do nothing
}
syntaxer()->next();
}
@ -4293,6 +4291,18 @@ void Editor::updateFunctionTip(bool showTip)
}
}
}
} else {
int i = tokens.length()-1;
if (i>=0){
if (!tokens[i].isEmpty() &&
isIdentStartChar(tokens[i].front())) {
functionNamePos.line = currentLine+1;
functionNamePos.ch = positions[i]+1;
break;
}
// not a valid function
return;
}
}
if (functionNamePos.ch>=0)
break;