Skip to content
Snippets Groups Projects
Commit 62dba8e4 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Fix incorrect completion inside 'Item\n{ ... }'.

The newline made the linizer add an automatic semicolon after Item,
causing the completion context finder to not recognize it as an object
definition.

Task-number: QTCREATORBUG-2658
Reviewed-by: Roberto Raggi
parent 87d8adb1
No related branches found
No related tags found
No related merge requests found
...@@ -191,9 +191,41 @@ QString LineInfo::trimmedCodeLine(const QString &t) ...@@ -191,9 +191,41 @@ QString LineInfo::trimmedCodeLine(const QString &t)
needSemicolon = true; needSemicolon = true;
break; break;
case Token::Identifier: case Token::Identifier: {
// need to disambiguate
// "Rectangle\n{" in a QML context from
// "a = Somevar\n{" in a JS context
// What's done here does not cover all cases, but goes as far as possible
// with the limited information that's available.
const QStringRef text = tokenText(last);
if (yyLinizerState.leftBraceFollows && !text.isEmpty() && text.at(0).isUpper()) {
int i = index;
// skip any preceeding 'identifier.'; these could appear in both cases
while (i >= 2) {
const Token &prev = yyLinizerState.tokens.at(i-1);
const Token &prevPrev = yyLinizerState.tokens.at(i-2);
if (prev.kind == Token::Dot && prevPrev.kind == Token::Identifier) {
i -= 2;
} else {
break;
}
}
// it could also be 'a = \n Foo \n {', but that sounds unlikely
if (i == 0)
break;
// these indicate a QML context
const Token &prev = yyLinizerState.tokens.at(i-1);
if (prev.kind == Token::Semicolon || prev.kind == Token::Identifier
|| prev.kind == Token::RightBrace || prev.kind == Token::RightBracket) {
break;
}
}
needSemicolon = true; needSemicolon = true;
break; break;
}
case Token::Keyword: case Token::Keyword:
if (tokenText(last) != QLatin1String("else")) if (tokenText(last) != QLatin1String("else"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment