From 69edf1e26d248fabf05bb0a43d32e34a0fcee121 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 26 Feb 2015 09:15:34 +0200 Subject: [PATCH] CppEditor: Use correct language features in Follow Symbol Change-Id: If4adc4153341ac63bd5566a66ccf177ae4e536e1 Reviewed-by: Nikolai Kosjar --- src/libs/cplusplus/SimpleLexer.cpp | 11 ++--------- src/libs/cplusplus/SimpleLexer.h | 2 +- src/plugins/cppeditor/cppfollowsymbolundercursor.cpp | 12 +++++------- src/plugins/glsleditor/glslautocompleter.cpp | 6 ++++-- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/libs/cplusplus/SimpleLexer.cpp b/src/libs/cplusplus/SimpleLexer.cpp index ff2a5f6468c..373441198c6 100644 --- a/src/libs/cplusplus/SimpleLexer.cpp +++ b/src/libs/cplusplus/SimpleLexer.cpp @@ -129,17 +129,10 @@ int SimpleLexer::tokenAt(const Tokens &tokens, unsigned utf16charsOffset) Token SimpleLexer::tokenAt(const QString &text, unsigned utf16charsOffset, int state, - bool qtMocRunEnabled) + const LanguageFeatures &languageFeatures) { - // FIXME: Check default values. - LanguageFeatures features; - features.qtMocRunEnabled = qtMocRunEnabled; - features.qtEnabled = qtMocRunEnabled; - features.qtKeywordsEnabled = qtMocRunEnabled; - features.objCEnabled = qtMocRunEnabled; - features.cxx11Enabled = qtMocRunEnabled; SimpleLexer tokenize; - tokenize.setLanguageFeatures(features); + tokenize.setLanguageFeatures(languageFeatures); const QVector tokens = tokenize(text, state); const int tokenIdx = tokenAt(tokens, utf16charsOffset); return (tokenIdx == -1) ? Token() : tokens.at(tokenIdx); diff --git a/src/libs/cplusplus/SimpleLexer.h b/src/libs/cplusplus/SimpleLexer.h index ef7fcbf0bdb..bf153eb211b 100644 --- a/src/libs/cplusplus/SimpleLexer.h +++ b/src/libs/cplusplus/SimpleLexer.h @@ -68,7 +68,7 @@ public: static Token tokenAt(const QString &text, unsigned utf16charsOffset, int state, - bool qtMocRunEnabled = false); + const LanguageFeatures &languageFeatures); static int tokenBefore(const Tokens &tokens, unsigned utf16charsOffset); diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index 785ef0379a7..1f493242463 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -466,12 +466,9 @@ TextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &curs int beginOfToken = 0; int endOfToken = 0; - LanguageFeatures features; - features.qtEnabled = true; - features.qtKeywordsEnabled = true; - features.qtMocRunEnabled = true; - features.objCEnabled = true; - features.cxx11Enabled = true; + const LanguageFeatures features = documentFromSemanticInfo + ? documentFromSemanticInfo->languageFeatures() + : LanguageFeatures::defaultFeatures(); SimpleLexer tokenize; tokenize.setLanguageFeatures(features); @@ -564,7 +561,8 @@ TextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &curs if (pos > 0 && !isValidIdentifierChar(ch)) --pos; // positionInBlock points to a delimiter character. const Token tk = SimpleLexer::tokenAt(block.text(), pos, - BackwardsScanner::previousBlockState(block), true); + BackwardsScanner::previousBlockState(block), + features); beginOfToken = block.position() + tk.utf16charsBegin(); endOfToken = block.position() + tk.utf16charsEnd(); diff --git a/src/plugins/glsleditor/glslautocompleter.cpp b/src/plugins/glsleditor/glslautocompleter.cpp index 14b600ce0ff..ff79ed558ba 100644 --- a/src/plugins/glsleditor/glslautocompleter.cpp +++ b/src/plugins/glsleditor/glslautocompleter.cpp @@ -70,7 +70,8 @@ bool GlslCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const { const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), - BackwardsScanner::previousBlockState(cursor.block())); + BackwardsScanner::previousBlockState(cursor.block()), + LanguageFeatures::defaultFeatures()); // XXX Duplicated from CppEditor::isInComment to avoid tokenizing twice if (tk.isComment()) { @@ -99,7 +100,8 @@ bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) c bool GlslCompleter::isInComment(const QTextCursor &cursor) const { const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), - BackwardsScanner::previousBlockState(cursor.block())); + BackwardsScanner::previousBlockState(cursor.block()), + LanguageFeatures::defaultFeatures()); if (tk.isComment()) { const unsigned pos = cursor.selectionEnd() - cursor.block().position();