forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user