fix #326 - enhancement: Suggest macro names after "#ifdef"/"#ifndef".

This commit is contained in:
Roy Qu 2024-03-26 13:18:00 +08:00
parent 5c7e7fb793
commit 40777386a9
4 changed files with 23 additions and 1 deletions

View File

@ -90,6 +90,7 @@ Red Panda C++ Version 2.27
- enhancement: Shortcut key for buttons in find/replace and "find in files" dialogs.
- enhancement: Auto define macro "_DEBUG" for "Debug" compiler set(like visual studio).
- enhancement: Suggest macro names after "#ifdef"/"#ifndef".
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -926,6 +926,11 @@ void Editor::keyPressEvent(QKeyEvent *event)
//last word is a type keyword, this is a var or param define, and dont show suggestion
return;
} else if (lastWord == "#ifdef" || lastWord == "#ifndef") {
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::Macros);
handled=true;
return;
}
PStatement statement = mParser->findStatementOf(
mFilename,
@ -4991,7 +4996,8 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
while ((wordBegin >= 0) && (isIdentChar(s[wordBegin]) || s[wordBegin]==':') ) {
wordBegin--;
}
wordBegin++;
if (wordBegin<0 || s[wordBegin]!='#')
wordBegin++;
if (s[wordBegin]>='0' && s[wordBegin]<='9') // not valid word
return "";

View File

@ -113,6 +113,10 @@ void CodeCompletionPopup::prepareSearch(
mIncludedFiles.clear();
getKeywordCompletionFor(customKeywords);
break;
case CodeCompletionType::Macros:
mIncludedFiles = mParser->getIncludedFiles(filename);
getMacroCompletionList(filename, line);
break;
default:
mIncludedFiles = mParser->getIncludedFiles(filename);
getCompletionFor(ownerExpression,memberOperator,memberExpression, filename,line, customKeywords);
@ -583,6 +587,15 @@ void CodeCompletionPopup::getKeywordCompletionFor(const QSet<QString> &customKey
}
}
void CodeCompletionPopup::getMacroCompletionList(const QString &fileName, int line)
{
const StatementMap& statementMap = mParser->statementList().childrenStatements(nullptr);
foreach(const PStatement& statement, statementMap.values()) {
if (statement->kind==StatementKind::skPreprocessor)
addStatement(statement,fileName,line);
}
}
void CodeCompletionPopup::getCompletionFor(
QStringList ownerExpression,
const QString& memberOperator,

View File

@ -43,6 +43,7 @@ enum class CodeCompletionType {
FunctionWithoutDefinition,
Namespaces,
Types,
Macros,
KeywordsOnly
};
@ -136,6 +137,7 @@ private:
void addStatement(const PStatement& statement, const QString& fileName, int line);
void filterList(const QString& member);
void getKeywordCompletionFor(const QSet<QString>& customKeywords);
void getMacroCompletionList(const QString &fileName, int line);
void getCompletionFor(
QStringList ownerExpression,
const QString& memberOperator,