Commit 809611f3 authored by Francois Ferrand's avatar Francois Ferrand Committed by Leandro Melo

CppHighlighter: highlight all functions/methods.

- Highlight all function/methods (not just virtual methods).
- Highlight as a function even if number of arguments does not match. In
  that case, add a diagnostic message to indicate there are too many/too
  few arguments.
- Fix highlighting of parameters in function declarations.
  These used to be handled indiferently, and they could be mistaken for
  type or field references.
- Properly highlight template method calls.

Change-Id: I6e61c9ee47763db95c62314f9cc1c4d398df38b3
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent 16bca8b0
......@@ -14,6 +14,7 @@
<style name="Doxygen.Comment" foreground="#55ffff"/>
<style name="Doxygen.Tag" foreground="#00a0a0"/>
<style name="Field"/>
<style name="Function"/>
<style name="Keyword" foreground="#ffff55"/>
<style name="Label" foreground="#ffff55"/>
<style name="LineNumber" foreground="#888888" background="#232323"/>
......
......@@ -8,6 +8,7 @@
<style name="Doxygen.Comment" foreground="#808080"/>
<style name="Doxygen.Tag" foreground="#808080" italic="true"/>
<style name="Field"/>
<style name="Function"/>
<style name="Keyword" bold="true"/>
<style name="Label"/>
<style name="LineNumber" foreground="#c7c4c1" background="#efebe7"/>
......
......@@ -19,6 +19,7 @@
<style name="Doxygen.Comment" foreground="#737dd5"/>
<style name="Doxygen.Tag" foreground="#4e5ab3"/>
<style name="Field" bold="true"/>
<style name="Function"/>
<style name="Keyword" foreground="#808bed"/>
<style name="Label" foreground="#e76000"/>
<style name="LineNumber" foreground="#8b8bcd" background="#2e2e2e"/>
......
......@@ -8,6 +8,7 @@
<style name="Doxygen.Comment" foreground="#808080" italic="true"/>
<style name="Doxygen.Tag" foreground="#808080" bold="true" italic="true"/>
<style name="Field" foreground="#660e7a" bold="true"/>
<style name="Function" foreground="#000000"/>
<style name="Keyword" foreground="#000080" bold="true"/>
<style name="Label" foreground="#800000" bold="true"/>
<style name="Local" foreground="#000000"/>
......
......@@ -192,6 +192,9 @@ public:
void addDiagnosticMessage(const DiagnosticMessage &d)
{ _diagnosticMessages.append(d); }
void clearDiagnosticMessages()
{ _diagnosticMessages.clear(); }
QList<DiagnosticMessage> diagnosticMessages() const
{ return _diagnosticMessages; }
......
......@@ -1047,6 +1047,11 @@ void CPPEditorWidget::finishHighlightSymbolUsages()
TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
highlighter, m_highlighter);
if (m_modelManager)
m_modelManager->setExtraDiagnostics(m_lastSemanticInfo.doc->fileName(),
CPlusPlus::CppModelManagerInterface::CppSemanticsDiagnostic,
m_lastSemanticInfo.doc->diagnosticMessages());
}
......@@ -1744,6 +1749,8 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
fs.toTextCharFormat(TextEditor::C_LABEL);
m_semanticHighlightFormatMap[SemanticInfo::MacroUse] =
fs.toTextCharFormat(TextEditor::C_PREPROCESSOR);
m_semanticHighlightFormatMap[SemanticInfo::FunctionUse] =
fs.toTextCharFormat(TextEditor::C_FUNCTION);
m_keywordFormat = fs.toTextCharFormat(TextEditor::C_KEYWORD);
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
......
......@@ -179,7 +179,8 @@ public:
enum ExtraDiagnosticKind
{
AllExtraDiagnostics = -1,
ExportedQmlTypesDiagnostic
ExportedQmlTypesDiagnostic,
CppSemanticsDiagnostic
};
public:
......
This diff is collapsed.
......@@ -107,7 +107,7 @@ protected:
bool maybeType(const Name *name) const;
bool maybeMember(const Name *name) const;
bool maybeStatic(const Name *name) const;
bool maybeVirtualMethod(const Name *name) const;
bool maybeFunction(const Name *name) const;
void checkName(NameAST *ast, Scope *scope = 0);
void checkNamespace(NameAST *name);
......@@ -121,7 +121,7 @@ protected:
void addTypeOrStatic(const QList<LookupItem> &candidates, NameAST *ast);
void addStatic(const QList<LookupItem> &candidates, NameAST *ast);
void addClassMember(const QList<LookupItem> &candidates, NameAST *ast);
void addVirtualMethod(const QList<LookupItem> &candidates, NameAST *ast, unsigned argumentCount);
void addFunction(const QList<LookupItem> &candidates, NameAST *ast, unsigned argumentCount);
bool isTemplateClass(Symbol *s) const;
......@@ -142,6 +142,7 @@ protected:
virtual bool visit(SimpleNameAST *ast);
virtual bool visit(DestructorNameAST *ast);
virtual bool visit(ParameterDeclarationAST *ast);
virtual bool visit(QualifiedNameAST *ast);
virtual bool visit(TemplateIdAST *ast);
......@@ -166,10 +167,9 @@ private:
LookupContext _context;
TypeOfExpression typeOfExpression;
QString _fileName;
QList<Document::DiagnosticMessage> _diagnosticMessages;
QSet<QByteArray> _potentialTypes;
QSet<QByteArray> _potentialMembers;
QSet<QByteArray> _potentialVirtualMethods;
QSet<QByteArray> _potentialFunctions;
QSet<QByteArray> _potentialStatics;
QList<AST *> _astStack;
QVector<Use> _usages;
......
......@@ -1154,13 +1154,19 @@ void CppModelManager::updateEditor(Document::Ptr doc)
QTextCursor c(ed->document()->findBlockByNumber(m.line() - 1));
const QString text = c.block().text();
for (int i = 0; i < text.size(); ++i) {
if (! text.at(i).isSpace()) {
c.setPosition(c.position() + i);
break;
if (m.length() > 0 && m.column() + m.length() < (unsigned)text.size()) {
int column = m.column() > 0 ? m.column() - 1 : 0;
c.setPosition(c.position() + column);
c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length());
} else {
for (int i = 0; i < text.size(); ++i) {
if (! text.at(i).isSpace()) {
c.setPosition(c.position() + i);
break;
}
}
c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
sel.cursor = c;
sel.format.setToolTip(m.text());
e.selections.append(sel);
......
......@@ -53,7 +53,8 @@ public:
StaticUse,
VirtualMethodUse,
LabelUse,
MacroUse
MacroUse,
FunctionUse
};
typedef TextEditor::SemanticHighlighter::Result Use;
......
......@@ -61,6 +61,7 @@ const char *nameForStyle(TextStyle style)
case C_FIELD: return "Field";
case C_STATIC: return "Static";
case C_VIRTUAL_METHOD: return "VirtualMethod";
case C_FUNCTION: return "Function";
case C_KEYWORD: return "Keyword";
case C_OPERATOR: return "Operator";
case C_PREPROCESSOR: return "Preprocessor";
......
......@@ -60,6 +60,7 @@ enum TextStyle {
C_FIELD,
C_STATIC,
C_VIRTUAL_METHOD,
C_FUNCTION,
C_KEYWORD,
C_OPERATOR,
C_PREPROCESSOR,
......
......@@ -145,6 +145,7 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
formatDescriptions.append(FormatDescription(C_FIELD, tr("Field"), Qt::darkRed));
formatDescriptions.append(FormatDescription(C_STATIC, tr("Static"), Qt::darkMagenta));
formatDescriptions.append(FormatDescription(C_FUNCTION, tr("Function")));
FormatDescription virtualMethodFormatDescriptor(C_VIRTUAL_METHOD, tr("Virtual Method"));
virtualMethodFormatDescriptor.format().setItalic(true);
formatDescriptions.append(virtualMethodFormatDescriptor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment