summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-03-11 10:57:46 +0100
committerChristian Kamm <christian.d.kamm@nokia.com>2010-03-11 11:09:04 +0100
commit5a7858f5ec36f01036bf36f5d60425a6c0ceef33 (patch)
tree48935c8cd8f543f0018c5cae49a4fb5c0d637253 /src/plugins/cpptools/cppcodecompletion.cpp
parent2b40ed698ab9bda6a13fed6ad3ae531c365b3241 (diff)
downloadqt-creator-5a7858f5ec36f01036bf36f5d60425a6c0ceef33.tar.gz
Make sure the BackwardScanner has tokenized before asking for a string.
The problem was that for Foo::Foo (|) when the user triggers completion at |, startOfLine() returns a token that's not on the current line and not yet tokenized by that instance of the BackwardScanner. As a fix I explicitly ask the instance to tokenize up to the given index. Task-number: QTCREATORBUG-673 Reviewed-by: Roberto Raggi
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index ac0d9813e7..bbc63d9ee0 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -1076,7 +1076,11 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
QTextCursor tc(edit->document());
tc.setPosition(endOfExpression);
BackwardsScanner bs(tc);
- QString possibleDecl = bs.mid(bs.startOfLine(bs.startToken())).trimmed().append("();");
+ const int startToken = bs.startToken();
+ const int lineStartToken = bs.startOfLine(startToken);
+ // make sure the required tokens are actually available
+ bs.LA(startToken - lineStartToken);
+ QString possibleDecl = bs.mid(lineStartToken).trimmed().append("();");
Document::Ptr doc = Document::create(QLatin1String("<completion>"));
doc->setSource(possibleDecl.toLatin1());