forked from qt-creator/qt-creator
TextEditor: Add highlighting category for namespaces
... and make use of it in the built-in code model and with clangd. Task-number: QTCREATORBUG-16580 Change-Id: I8c331f56aa1bbf91c9f768be82a779a72f40c4c7 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<style name="String" foreground="#636363"/>
|
||||
<style name="Text" foreground="#000000" background="#ffffff"/>
|
||||
<style name="Type"/>
|
||||
<style name="Namespace"/>
|
||||
<style name="VirtualMethod" italic="true"/>
|
||||
<style name="Occurrences.Unused" underlineColor="#8F8F8F" underlineStyle="SingleUnderline"/>
|
||||
<style name="Warning" underlineColor="#505050" underlineStyle="SingleUnderline"/>
|
||||
|
@@ -2452,7 +2452,7 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
||||
} else if (token.type == "comment") { // "comment" means code disabled via the preprocessor
|
||||
styles.mainStyle = C_DISABLED_CODE;
|
||||
} else if (token.type == "namespace") {
|
||||
styles.mainStyle = C_TYPE;
|
||||
styles.mainStyle = C_NAMESPACE;
|
||||
} else if (token.type == "property") {
|
||||
styles.mainStyle = C_FIELD;
|
||||
} else if (token.type == "enum") {
|
||||
|
@@ -764,12 +764,12 @@ void ClangdTestHighlighting::test_data()
|
||||
QTest::newRow("struct declaration") << 50 << 8 << 50 << 11
|
||||
<< QList<int>{C_TYPE, C_DECLARATION} << 0;
|
||||
QTest::newRow("namespace declaration") << 160 << 11 << 160 << 20
|
||||
<< QList<int>{C_TYPE, C_DECLARATION} << 0;
|
||||
<< QList<int>{C_NAMESPACE, C_DECLARATION} << 0;
|
||||
QTest::newRow("namespace alias declaration") << 164 << 11 << 164 << 25
|
||||
<< QList<int>{C_TYPE, C_DECLARATION} << 0;
|
||||
<< QList<int>{C_NAMESPACE, C_DECLARATION} << 0;
|
||||
QTest::newRow("struct in namespaced using declaration") << 165 << 18 << 165 << 35
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("namespace reference") << 166 << 1 << 166 << 10 << QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("namespace reference") << 166 << 1 << 166 << 10 << QList<int>{C_NAMESPACE} << 0;
|
||||
QTest::newRow("namespaced struct in global variable declaration") << 166 << 12 << 166 << 29
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("virtual function declaration") << 170 << 18 << 170 << 33
|
||||
@@ -992,7 +992,8 @@ void ClangdTestHighlighting::test_data()
|
||||
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen);
|
||||
QTest::newRow("class template instantiation (closing angle bracket)") << 384 << 22 << 384 << 23
|
||||
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketClose);
|
||||
QTest::newRow("namespace in declaration") << 413 << 4 << 413 << 26 << QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("namespace in declaration") << 413 << 4 << 413 << 26
|
||||
<< QList<int>{C_NAMESPACE} << 0;
|
||||
QTest::newRow("namespaced class in declaration") << 413 << 28 << 413 << 41
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("class as template argument in declaration") << 413 << 42 << 413 << 52
|
||||
@@ -1163,14 +1164,14 @@ void ClangdTestHighlighting::test_data()
|
||||
QTest::newRow("reference to global variable") << 764 << 5 << 764 << 14
|
||||
<< QList<int>{C_GLOBAL} << 0;
|
||||
QTest::newRow("nested template instantiation (namespace 1)") << 773 << 8 << 773 << 11
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
<< QList<int>{C_NAMESPACE} << 0;
|
||||
QTest::newRow("nested template instantiation (type 1)") << 773 << 13 << 773 << 19
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("nested template instantiation (opening angle bracket 1)")
|
||||
<< 773 << 19 << 773 << 20
|
||||
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketOpen);
|
||||
QTest::newRow("nested template instantiation (namespace 2)") << 773 << 20 << 773 << 23
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
<< QList<int>{C_NAMESPACE} << 0;
|
||||
QTest::newRow("nested template instantiation (type 2)") << 773 << 25 << 773 << 29
|
||||
<< QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("nested template instantiation (opening angle bracket 2)")
|
||||
|
@@ -477,7 +477,7 @@ bool CheckSymbols::visit(NamespaceAST *ast)
|
||||
if (!tok.generated()) {
|
||||
int line, column;
|
||||
getTokenStartPosition(ast->identifier_token, &line, &column);
|
||||
Result use(line, column, tok.utf16chars(), SemanticHighlighter::TypeUse);
|
||||
Result use(line, column, tok.utf16chars(), SemanticHighlighter::NamespaceUse);
|
||||
addUse(use);
|
||||
}
|
||||
}
|
||||
@@ -1221,7 +1221,15 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast)
|
||||
int line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
const unsigned length = tok.utf16chars();
|
||||
const Result use(line, column, length, SemanticHighlighter::TypeUse);
|
||||
Kind kind = SemanticHighlighter::TypeUse;
|
||||
const QList<Symbol *> &symbols = b->symbols();
|
||||
for (const Symbol * const s : symbols) {
|
||||
if (s->isNamespace()) {
|
||||
kind = SemanticHighlighter::NamespaceUse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const Result use(line, column, length, kind);
|
||||
addUse(use);
|
||||
}
|
||||
|
||||
@@ -1266,6 +1274,8 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam
|
||||
Kind kind = SemanticHighlighter::TypeUse;
|
||||
if (c->enclosingEnum() != nullptr)
|
||||
kind = SemanticHighlighter::EnumerationUse;
|
||||
else if (c->isNamespace())
|
||||
kind = SemanticHighlighter::NamespaceUse;
|
||||
else if (c->isStatic())
|
||||
// treat static variable as a field(highlighting)
|
||||
kind = SemanticHighlighter::FieldUse;
|
||||
|
@@ -316,6 +316,7 @@ void SemanticHighlighter::updateFormatMapFromFontSettings()
|
||||
const FontSettings &fs = m_baseTextDocument->fontSettings();
|
||||
|
||||
m_formatMap[TypeUse] = fs.toTextCharFormat(C_TYPE);
|
||||
m_formatMap[NamespaceUse] = fs.toTextCharFormat(C_NAMESPACE);
|
||||
m_formatMap[LocalUse] = fs.toTextCharFormat(C_LOCAL);
|
||||
m_formatMap[FieldUse] = fs.toTextCharFormat(C_FIELD);
|
||||
m_formatMap[EnumerationUse] = fs.toTextCharFormat(C_ENUMERATION);
|
||||
|
@@ -48,6 +48,7 @@ public:
|
||||
enum Kind {
|
||||
Unknown = 0,
|
||||
TypeUse,
|
||||
NamespaceUse,
|
||||
LocalUse,
|
||||
FieldUse,
|
||||
EnumerationUse,
|
||||
|
@@ -417,6 +417,10 @@ bool FontSettings::loadColorScheme(const QString &fileName,
|
||||
foreach (const FormatDescription &desc, descriptions) {
|
||||
const TextStyle id = desc.id();
|
||||
if (!m_scheme.contains(id)) {
|
||||
if (id == C_NAMESPACE && m_scheme.contains(C_TYPE)) {
|
||||
m_scheme.setFormatFor(C_NAMESPACE, m_scheme.formatFor(C_TYPE));
|
||||
continue;
|
||||
}
|
||||
Format format;
|
||||
const Format &descFormat = desc.format();
|
||||
// Default fallback for background and foreground is C_TEXT, which is set through
|
||||
|
@@ -54,6 +54,7 @@ const char *nameForStyle(TextStyle style)
|
||||
case C_NUMBER: return "Number";
|
||||
case C_STRING: return "String";
|
||||
case C_TYPE: return "Type";
|
||||
case C_NAMESPACE: return "Namespace";
|
||||
case C_LOCAL: return "Local";
|
||||
case C_PARAMETER: return "Parameter";
|
||||
case C_GLOBAL: return "Global";
|
||||
|
@@ -54,6 +54,7 @@ enum TextStyle : quint8 {
|
||||
C_NUMBER,
|
||||
C_STRING,
|
||||
C_TYPE,
|
||||
C_NAMESPACE,
|
||||
C_LOCAL,
|
||||
C_PARAMETER,
|
||||
C_GLOBAL,
|
||||
|
@@ -160,6 +160,8 @@ FormatDescriptions TextEditorSettingsPrivate::initialFormats()
|
||||
tr("Name of a primitive data type."), Qt::darkYellow);
|
||||
formatDescr.emplace_back(C_TYPE, tr("Type"), tr("Name of a type."),
|
||||
Qt::darkMagenta);
|
||||
formatDescr.emplace_back(C_NAMESPACE, tr("Namespace"), tr("Name of a namespace."),
|
||||
Qt::darkGreen);
|
||||
formatDescr.emplace_back(C_LOCAL, tr("Local"),
|
||||
tr("Local variables."), QColor(9, 46, 100));
|
||||
formatDescr.emplace_back(C_PARAMETER, tr("Parameter"),
|
||||
|
@@ -62,6 +62,7 @@ static QString useKindToString(UseKind useKind)
|
||||
switch (useKind) {
|
||||
CASE_STR(Unknown);
|
||||
CASE_STR(TypeUse);
|
||||
CASE_STR(NamespaceUse);
|
||||
CASE_STR(LocalUse);
|
||||
CASE_STR(FieldUse);
|
||||
CASE_STR(EnumerationUse);
|
||||
@@ -249,8 +250,8 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
<< _("namespace N {}\n"
|
||||
"using namespace N;\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 1, Highlighting::TypeUse)
|
||||
<< Use(2, 17, 1, Highlighting::TypeUse));
|
||||
<< Use(1, 11, 1, Highlighting::NamespaceUse)
|
||||
<< Use(2, 17, 1, Highlighting::NamespaceUse));
|
||||
|
||||
QTest::newRow("LocalUse")
|
||||
<< _("int f()\n"
|
||||
@@ -713,11 +714,11 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
<< Use(1, 14, 4, Highlighting::FieldUse)
|
||||
<< Use(2, 6, 4, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(4, 8, 4, Highlighting::FieldUse)
|
||||
<< Use(6, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(7, 16, 4, Highlighting::FieldUse)
|
||||
<< Use(8, 8, 4, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(10, 10, 4, Highlighting::FieldUse)
|
||||
<< Use(13, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(13, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(15, 27, 4, Highlighting::FieldUse)
|
||||
<< Use(16, 10, 4, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(16, 19, 4, Highlighting::FieldUse)
|
||||
@@ -795,9 +796,9 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
" Foo foo;\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 7, 2, Highlighting::TypeUse)
|
||||
<< Use(4, 7, 2, Highlighting::NamespaceUse)
|
||||
<< Use(4, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(5, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(7, 5, 3, Highlighting::TypeUse)
|
||||
@@ -815,10 +816,10 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(5, 7, 2, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(5, 7, 2, Highlighting::NamespaceUse)
|
||||
<< Use(5, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(8, 5, 3, Highlighting::TypeUse)
|
||||
@@ -834,10 +835,10 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
" Foo foo;\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(6, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(6, 15, 3, Highlighting::TypeUse)
|
||||
<< Use(7, 5, 3, Highlighting::TypeUse)
|
||||
<< Use(7, 9, 3, Highlighting::LocalUse));
|
||||
@@ -852,7 +853,7 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
" Foo foo;\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(5, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(7, 9, 3, Highlighting::LocalUse));
|
||||
@@ -869,9 +870,9 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(6, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(8, 9, 3, Highlighting::LocalUse));
|
||||
|
||||
@@ -885,7 +886,7 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
" Foo foo;\n"
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(2, 7, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(7, 9, 3, Highlighting::LocalUse));
|
||||
@@ -947,14 +948,14 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n")
|
||||
<< (UseList()
|
||||
<< Use(1, 8, 1, Highlighting::TypeUse)
|
||||
<< Use(2, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(2, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(4, 24, 1, Highlighting::TypeUse)
|
||||
<< Use(4, 34, 10, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(8, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(8, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(8, 16, 10, Highlighting::TypeUse)
|
||||
<< Use(10, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(12, 5, 2, Highlighting::TypeUse)
|
||||
<< Use(12, 5, 2, Highlighting::NamespaceUse)
|
||||
<< Use(12, 9, 10, Highlighting::TypeUse)
|
||||
<< Use(12, 20, 1, Highlighting::TypeUse)
|
||||
<< Use(12, 23, 1, Highlighting::LocalUse));
|
||||
@@ -970,9 +971,9 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
" Foo foo;\n"
|
||||
"}\n")
|
||||
<< (QList<Use>()
|
||||
<< Use(3, 15, 2, Highlighting::TypeUse)
|
||||
<< Use(3, 15, 2, Highlighting::NamespaceUse)
|
||||
<< Use(3, 27, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(4, 15, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 6, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(8, 5, 3, Highlighting::TypeUse)
|
||||
@@ -994,12 +995,12 @@ void tst_CheckSymbols::test_checksymbols_data()
|
||||
"}\n"
|
||||
)
|
||||
<< (QList<Use>()
|
||||
<< Use(1, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(3, 15, 2, Highlighting::TypeUse)
|
||||
<< Use(1, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(3, 15, 2, Highlighting::NamespaceUse)
|
||||
<< Use(3, 27, 3, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 2, Highlighting::TypeUse)
|
||||
<< Use(4, 11, 2, Highlighting::NamespaceUse)
|
||||
<< Use(4, 15, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 3, Highlighting::TypeUse)
|
||||
<< Use(6, 11, 3, Highlighting::NamespaceUse)
|
||||
<< Use(8, 10, 3, Highlighting::FunctionDeclarationUse)
|
||||
<< Use(10, 13, 3, Highlighting::LocalUse)
|
||||
);
|
||||
|
Reference in New Issue
Block a user