ClangCodeModel/TextEditor: Add support for highlighting parameters

This is already built into clang, so we just need to expose it to the
highlighter and the UI.

Fixes: QTCREATORBUG-24880
Change-Id: I6d0595af2589a9b69eb954aafad46457ab2c5752
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Tom Praschan
2021-03-03 19:32:48 +01:00
parent edba0ca838
commit 5fcd52fe83
14 changed files with 22 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
<style name="String" foreground="#d69545"/> <style name="String" foreground="#d69545"/>
<style name="Type" foreground="#ff8080"/> <style name="Type" foreground="#ff8080"/>
<style name="Local" foreground="#d6bb9a"/> <style name="Local" foreground="#d6bb9a"/>
<style name="Parameter" foreground="#d6bb9a"/>
<style name="Global" foreground="#9aa7d6"/> <style name="Global" foreground="#9aa7d6"/>
<style name="Field"/> <style name="Field"/>
<style name="Static" foreground="#66a334" italic="true"/> <style name="Static" foreground="#66a334" italic="true"/>

View File

@@ -13,6 +13,7 @@
<style name="PrimitiveType" foreground="#000080" bold="true"/> <style name="PrimitiveType" foreground="#000080" bold="true"/>
<style name="Label" foreground="#800000" bold="true"/> <style name="Label" foreground="#800000" bold="true"/>
<style name="Local" foreground="#000000"/> <style name="Local" foreground="#000000"/>
<style name="Parameter" foreground="#000000"/>
<style name="Number" foreground="#0000ff"/> <style name="Number" foreground="#0000ff"/>
<style name="Operator" foreground="#000000"/> <style name="Operator" foreground="#000000"/>
<style name="Overloaded Operator" foreground="#000000"/> <style name="Overloaded Operator" foreground="#000000"/>

View File

@@ -26,6 +26,7 @@
<style name="String" foreground="#2aa198"/> <style name="String" foreground="#2aa198"/>
<style name="Type" foreground="#b58900"/> <style name="Type" foreground="#b58900"/>
<style name="Local" foreground="#839496"/> <style name="Local" foreground="#839496"/>
<style name="Parameter" foreground="#839496"/>
<style name="Global"/> <style name="Global"/>
<style name="Field" foreground="#268bd2"/> <style name="Field" foreground="#268bd2"/>
<style name="Static" foreground="#b58900" italic="true"/> <style name="Static" foreground="#b58900" italic="true"/>

View File

@@ -26,6 +26,7 @@
<style name="String" foreground="#2aa198"/> <style name="String" foreground="#2aa198"/>
<style name="Type" foreground="#b58900"/> <style name="Type" foreground="#b58900"/>
<style name="Local" foreground="#657b83"/> <style name="Local" foreground="#657b83"/>
<style name="Parameter" foreground="#657b83"/>
<style name="Global"/> <style name="Global"/>
<style name="Field" foreground="#268bd2"/> <style name="Field" foreground="#268bd2"/>
<style name="Static" foreground="#b58900" italic="true"/> <style name="Static" foreground="#b58900" italic="true"/>

View File

@@ -78,6 +78,7 @@ enum class HighlightingType : quint8
Type, Type,
PrimitiveType, PrimitiveType,
LocalVariable, LocalVariable,
Parameter,
Field, Field,
GlobalVariable, GlobalVariable,
Enumeration, Enumeration,

View File

@@ -138,6 +138,7 @@ public:
return extraInfo.declaration return extraInfo.declaration
&& types.mainHighlightingType != HighlightingType::LocalVariable && types.mainHighlightingType != HighlightingType::LocalVariable
&& types.mainHighlightingType != HighlightingType::Parameter
&& (types.mixinHighlightingTypes.contains(HighlightingType::Operator) && (types.mixinHighlightingTypes.contains(HighlightingType::Operator)
== extraInfo.token.startsWith("operator")); == extraInfo.token.startsWith("operator"));
} }

View File

@@ -50,6 +50,8 @@ TextEditor::TextStyle toTextStyle(ClangBackEnd::HighlightingType type)
return TextEditor::C_PRIMITIVE_TYPE; return TextEditor::C_PRIMITIVE_TYPE;
case HighlightingType::LocalVariable: case HighlightingType::LocalVariable:
return TextEditor::C_LOCAL; return TextEditor::C_LOCAL;
case HighlightingType::Parameter:
return TextEditor::C_PARAMETER;
case HighlightingType::Field: case HighlightingType::Field:
case HighlightingType::QtProperty: case HighlightingType::QtProperty:
return TextEditor::C_FIELD; return TextEditor::C_FIELD;

View File

@@ -80,7 +80,7 @@ static Utils::optional<TextEditor::TextStyle> styleForScopes(const QList<QString
{"variable.other.member", TextEditor::C_FIELD}, {"variable.other.member", TextEditor::C_FIELD},
{"variable.other.field", TextEditor::C_FIELD}, {"variable.other.field", TextEditor::C_FIELD},
{"variable.other.field.static", TextEditor::C_GLOBAL}, {"variable.other.field.static", TextEditor::C_GLOBAL},
{"variable.parameter", TextEditor::C_LOCAL}, {"variable.parameter", TextEditor::C_PARAMETER},
}; };
for (QString scope : scopes) { for (QString scope : scopes) {

View File

@@ -55,6 +55,7 @@ const char *nameForStyle(TextStyle style)
case C_STRING: return "String"; case C_STRING: return "String";
case C_TYPE: return "Type"; case C_TYPE: return "Type";
case C_LOCAL: return "Local"; case C_LOCAL: return "Local";
case C_PARAMETER: return "Parameter";
case C_GLOBAL: return "Global"; case C_GLOBAL: return "Global";
case C_FIELD: return "Field"; case C_FIELD: return "Field";
// TODO: Rename "Static" to "Enumeration" in next major update, // TODO: Rename "Static" to "Enumeration" in next major update,

View File

@@ -55,6 +55,7 @@ enum TextStyle : quint8 {
C_STRING, C_STRING,
C_TYPE, C_TYPE,
C_LOCAL, C_LOCAL,
C_PARAMETER,
C_GLOBAL, C_GLOBAL,
C_FIELD, C_FIELD,
C_ENUMERATION, C_ENUMERATION,

View File

@@ -162,6 +162,8 @@ FormatDescriptions TextEditorSettingsPrivate::initialFormats()
Qt::darkMagenta); Qt::darkMagenta);
formatDescr.emplace_back(C_LOCAL, tr("Local"), formatDescr.emplace_back(C_LOCAL, tr("Local"),
tr("Local variables."), QColor(9, 46, 100)); tr("Local variables."), QColor(9, 46, 100));
formatDescr.emplace_back(C_PARAMETER, tr("Parameter"),
tr("Function or method parameters."), QColor(9, 46, 100));
formatDescr.emplace_back(C_FIELD, tr("Field"), formatDescr.emplace_back(C_FIELD, tr("Field"),
tr("Class' data members."), Qt::darkRed); tr("Class' data members."), Qt::darkRed);
formatDescr.emplace_back(C_GLOBAL, tr("Global"), formatDescr.emplace_back(C_GLOBAL, tr("Global"),

View File

@@ -110,6 +110,11 @@ bool Cursor::isInvalidDeclaration() const
return clang_isInvalidDeclaration(m_cxCursor); return clang_isInvalidDeclaration(m_cxCursor);
} }
bool Cursor::isParameter() const
{
return kind() == CXCursor_ParmDecl;
}
bool Cursor::isLocalVariable() const bool Cursor::isLocalVariable() const
{ {
switch (semanticParent().kind()) { switch (semanticParent().kind()) {

View File

@@ -62,6 +62,7 @@ public:
bool isCompoundType() const; bool isCompoundType() const;
bool isDeclaration() const; bool isDeclaration() const;
bool isInvalidDeclaration() const; bool isInvalidDeclaration() const;
bool isParameter() const;
bool isLocalVariable() const; bool isLocalVariable() const;
bool isReference() const; bool isReference() const;
bool isExpression() const; bool isExpression() const;

View File

@@ -142,7 +142,9 @@ void TokenInfo::overloadedDeclRefKind(const Cursor &cursor)
void TokenInfo::variableKind(const Cursor &cursor) void TokenInfo::variableKind(const Cursor &cursor)
{ {
if (cursor.isLocalVariable()) if (cursor.isParameter())
m_types.mainHighlightingType = HighlightingType::Parameter;
else if (cursor.isLocalVariable())
m_types.mainHighlightingType = HighlightingType::LocalVariable; m_types.mainHighlightingType = HighlightingType::LocalVariable;
else else
m_types.mainHighlightingType = HighlightingType::GlobalVariable; m_types.mainHighlightingType = HighlightingType::GlobalVariable;