forked from qt-creator/qt-creator
TextEditor: Allow special highlighting for static members
Task-number: QTCREATORBUG-9659 Change-Id: Idae529fd876ba5f555c76e4d282efc9263263d6c Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2463,6 +2463,8 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
||||
}
|
||||
if (token.modifiers.contains("declaration"))
|
||||
styles.mixinStyles.push_back(C_DECLARATION);
|
||||
if (token.modifiers.contains("static"))
|
||||
styles.mixinStyles.push_back(C_STATIC_MEMBER);
|
||||
if (isOutputParameter(token))
|
||||
styles.mixinStyles.push_back(C_OUTPUT_ARGUMENT);
|
||||
qCDebug(clangdLogHighlight) << "adding highlighting result"
|
||||
|
@@ -1099,9 +1099,9 @@ void ClangdTestHighlighting::test_data()
|
||||
QTest::newRow("local variable captured by lambda") << 442 << 24 << 442 << 27
|
||||
<< QList<int>{C_LOCAL} << 0;
|
||||
QTest::newRow("static protected member") << 693 << 16 << 693 << 30
|
||||
<< QList<int>{C_FIELD, C_DECLARATION} << 0;
|
||||
<< QList<int>{C_FIELD, C_DECLARATION, C_STATIC_MEMBER} << 0;
|
||||
QTest::newRow("static private member") << 696 << 16 << 696 << 28
|
||||
<< QList<int>{C_FIELD, C_DECLARATION} << 0;
|
||||
<< QList<int>{C_FIELD, C_DECLARATION, C_STATIC_MEMBER} << 0;
|
||||
QTest::newRow("alias template declaration (opening angle bracket)") << 700 << 10 << 700 << 11
|
||||
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen);
|
||||
QTest::newRow("alias template declaration (closing angle bracket)") << 700 << 16 << 700 << 17
|
||||
|
@@ -1305,7 +1305,8 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.utf16chars();
|
||||
|
||||
const Result use(line, column, length, SemanticHighlighter::FieldUse);
|
||||
const Result use(line, column, length, c->isStatic()
|
||||
? SemanticHighlighter::StaticFieldUse : SemanticHighlighter::FieldUse);
|
||||
addUse(use);
|
||||
|
||||
return true;
|
||||
@@ -1359,12 +1360,15 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
|
||||
continue; // TODO: add diagnostic messages and color call-operators calls too?
|
||||
|
||||
const bool isVirtual = funTy->isVirtual();
|
||||
const bool isStaticMember = funTy->isStatic() && funTy->enclosingClass();
|
||||
Kind matchingKind;
|
||||
if (functionKind == FunctionDeclaration) {
|
||||
matchingKind = isVirtual ? SemanticHighlighter::VirtualFunctionDeclarationUse
|
||||
: isStaticMember ? SemanticHighlighter::StaticMethodDeclarationUse
|
||||
: SemanticHighlighter::FunctionDeclarationUse;
|
||||
} else {
|
||||
matchingKind = isVirtual ? SemanticHighlighter::VirtualMethodUse
|
||||
: isStaticMember ? SemanticHighlighter::StaticMethodUse
|
||||
: SemanticHighlighter::FunctionUse;
|
||||
}
|
||||
if (argumentCount < funTy->minimumArgumentCount()) {
|
||||
|
@@ -328,6 +328,12 @@ void SemanticHighlighter::updateFormatMapFromFontSettings()
|
||||
m_formatMap[VirtualFunctionDeclarationUse] =
|
||||
fs.toTextCharFormat(TextStyles::mixinStyle(C_VIRTUAL_METHOD, C_DECLARATION));
|
||||
m_formatMap[PseudoKeywordUse] = fs.toTextCharFormat(C_KEYWORD);
|
||||
m_formatMap[StaticFieldUse]
|
||||
= fs.toTextCharFormat(TextStyles::mixinStyle(C_FIELD, C_STATIC_MEMBER));
|
||||
m_formatMap[StaticMethodUse]
|
||||
= fs.toTextCharFormat(TextStyles::mixinStyle(C_FUNCTION, C_STATIC_MEMBER));
|
||||
m_formatMap[StaticMethodDeclarationUse] = fs.toTextCharFormat(
|
||||
TextStyles::mixinStyle(C_FUNCTION, {C_DECLARATION, C_STATIC_MEMBER}));
|
||||
}
|
||||
|
||||
} // namespace CppEditor
|
||||
|
@@ -58,6 +58,9 @@ public:
|
||||
PseudoKeywordUse,
|
||||
FunctionDeclarationUse,
|
||||
VirtualFunctionDeclarationUse,
|
||||
StaticFieldUse,
|
||||
StaticMethodUse,
|
||||
StaticMethodDeclarationUse,
|
||||
AngleBracketOpen,
|
||||
AngleBracketClose,
|
||||
DoubleAngleBracketClose,
|
||||
|
@@ -114,6 +114,7 @@ const char *nameForStyle(TextStyle style)
|
||||
case C_DECLARATION: return "Declaration";
|
||||
case C_FUNCTION_DEFINITION: return "FunctionDefinition";
|
||||
case C_OUTPUT_ARGUMENT: return "OutputArgument";
|
||||
case C_STATIC_MEMBER: return "StaticMember";
|
||||
|
||||
case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel";
|
||||
}
|
||||
|
@@ -114,6 +114,7 @@ enum TextStyle : quint8 {
|
||||
C_DECLARATION,
|
||||
C_FUNCTION_DEFINITION,
|
||||
C_OUTPUT_ARGUMENT,
|
||||
C_STATIC_MEMBER,
|
||||
|
||||
C_LAST_STYLE_SENTINEL
|
||||
};
|
||||
|
@@ -361,6 +361,10 @@ FormatDescriptions TextEditorSettingsPrivate::initialFormats()
|
||||
tr("Writable arguments of a function call."),
|
||||
outputArgumentFormat,
|
||||
FormatDescription::ShowAllControls);
|
||||
formatDescr.emplace_back(C_STATIC_MEMBER,
|
||||
tr("Static Member"),
|
||||
tr("Names of static fields or member functions."),
|
||||
FormatDescription::ShowAllControls);
|
||||
|
||||
return formatDescr;
|
||||
}
|
||||
|
@@ -36,14 +36,20 @@ struct TextStyles {
|
||||
TextStyle mainStyle;
|
||||
MixinTextStyles mixinStyles;
|
||||
|
||||
static TextStyles mixinStyle(TextStyle main, TextStyle mixin)
|
||||
static TextStyles mixinStyle(TextStyle main, const QList<TextStyle> &mixins)
|
||||
{
|
||||
TextStyles res;
|
||||
res.mainStyle = main;
|
||||
res.mixinStyles.initializeElements();
|
||||
for (TextStyle mixin : mixins)
|
||||
res.mixinStyles.push_back(mixin);
|
||||
return res;
|
||||
}
|
||||
|
||||
static TextStyles mixinStyle(TextStyle main, TextStyle mixin)
|
||||
{
|
||||
return mixinStyle(main, QList<TextStyle>{mixin});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
@@ -72,6 +72,9 @@ static QString useKindToString(UseKind useKind)
|
||||
CASE_STR(FunctionUse);
|
||||
CASE_STR(FunctionDeclarationUse);
|
||||
CASE_STR(PseudoKeywordUse);
|
||||
CASE_STR(StaticFieldUse);
|
||||
CASE_STR(StaticMethodUse);
|
||||
CASE_STR(StaticMethodDeclarationUse);
|
||||
default:
|
||||
QTest::qFail("Unknown UseKind", __FILE__, __LINE__);
|
||||
return QLatin1String("Unknown UseKind");
|
||||
@@ -361,21 +364,21 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 5, Highlighting::TypeUse)
|
||||
<< Use(3, 16, 3, Highlighting::FieldUse)
|
||||
<< Use(3, 16, 3, Highlighting::StaticFieldUse)
|
||||
<< Use(4, 12, 5, Highlighting::TypeUse)
|
||||
<< Use(6, 9, 5, Highlighting::TypeUse)
|
||||
<< Use(6, 16, 5, Highlighting::FieldUse)
|
||||
<< Use(7, 14, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(11, 5, 5, Highlighting::TypeUse)
|
||||
<< Use(11, 12, 3, Highlighting::FieldUse)
|
||||
<< Use(11, 12, 3, Highlighting::FieldUse) // FIXME: Should be StaticField
|
||||
<< Use(13, 6, 5, Highlighting::TypeUse)
|
||||
<< Use(13, 13, 5, Highlighting::TypeUse)
|
||||
<< Use(13, 20, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(15, 5, 3, Highlighting::FieldUse)
|
||||
<< Use(15, 5, 3, Highlighting::StaticFieldUse)
|
||||
<< Use(16, 5, 5, Highlighting::TypeUse)
|
||||
<< Use(16, 12, 3, Highlighting::FieldUse)
|
||||
<< Use(16, 12, 3, Highlighting::FieldUse) // FIXME: Should be StaticField
|
||||
<< Use(17, 5, 5, Highlighting::FieldUse)
|
||||
<< Use(17, 12, 3, Highlighting::FieldUse));
|
||||
<< Use(17, 12, 3, Highlighting::StaticFieldUse));
|
||||
|
||||
QTest::newRow("VariableHasTheSameNameAsEnumUse")
|
||||
<< _("struct Foo\n"
|
||||
@@ -443,11 +446,11 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 3, Highlighting::TypeUse)
|
||||
<< Use(3, 16, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(3, 16, 3, Highlighting::StaticMethodDeclarationUse)
|
||||
<< Use(6, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(8, 9, 3, Highlighting::LocalUse)
|
||||
<< Use(8, 15, 3, Highlighting::TypeUse)
|
||||
<< Use(8, 20, 3, Highlighting::FunctionUse));
|
||||
<< Use(8, 20, 3, Highlighting::StaticMethodUse));
|
||||
|
||||
QTest::newRow("8902_staticFunctionHighlightingAsMember_functionArgument")
|
||||
<< _("struct Foo\n"
|
||||
@@ -461,11 +464,11 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 3, Highlighting::TypeUse)
|
||||
<< Use(3, 16, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(3, 16, 3, Highlighting::StaticMethodDeclarationUse)
|
||||
<< Use(6, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(6, 14, 3, Highlighting::LocalUse)
|
||||
<< Use(8, 5, 3, Highlighting::TypeUse)
|
||||
<< Use(8, 10, 3, Highlighting::FunctionUse));
|
||||
<< Use(8, 10, 3, Highlighting::StaticMethodUse));
|
||||
|
||||
QTest::newRow("8902_staticFunctionHighlightingAsMember_templateParameter")
|
||||
<< _("struct Foo\n"
|
||||
@@ -480,11 +483,11 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 3, Highlighting::TypeUse)
|
||||
<< Use(3, 16, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(3, 16, 3, Highlighting::StaticMethodDeclarationUse)
|
||||
<< Use(6, 17, 3, Highlighting::TypeUse)
|
||||
<< Use(7, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(9, 5, 3, Highlighting::TypeUse)
|
||||
<< Use(9, 10, 3, Highlighting::FunctionUse));
|
||||
<< Use(9, 10, 3, Highlighting::StaticMethodUse));
|
||||
|
||||
QTest::newRow("staticFunctionHighlightingAsMember_struct")
|
||||
<< _("struct Foo\n"
|
||||
@@ -499,11 +502,11 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 3, Highlighting::TypeUse)
|
||||
<< Use(3, 16, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(3, 16, 3, Highlighting::StaticMethodDeclarationUse)
|
||||
<< Use(6, 8, 3, Highlighting::TypeUse)
|
||||
<< Use(7, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(9, 5, 3, Highlighting::TypeUse)
|
||||
<< Use(9, 10, 3, Highlighting::FunctionUse));
|
||||
<< Use(9, 10, 3, Highlighting::StaticMethodUse));
|
||||
|
||||
QTest::newRow("QTCREATORBUG8890_danglingPointer")
|
||||
<< _("template<class T> class QList {\n"
|
||||
@@ -569,13 +572,13 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
<< Use(1, 17, 1, Highlighting::TypeUse)
|
||||
<< Use(2, 7, 9, Highlighting::TypeUse)
|
||||
<< Use(5, 12, 1, Highlighting::TypeUse)
|
||||
<< Use(5, 15, 8, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(5, 15, 8, Highlighting::StaticMethodDeclarationUse)
|
||||
<< Use(8, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(10, 6, 3, Highlighting::FunctionDeclarationUse);
|
||||
for (int i = 0; i < 250; ++i) {
|
||||
excessiveUses
|
||||
<< Use(12 + i, 5, 9, Highlighting::TypeUse)
|
||||
<< Use(12 + i, 28, 8, Highlighting::FunctionUse);
|
||||
<< Use(12 + i, 28, 8, Highlighting::StaticMethodUse);
|
||||
}
|
||||
QTest::newRow("QTCREATORBUG8974_danglingPointer")
|
||||
<< excessive
|
||||
|
Reference in New Issue
Block a user