forked from qt-creator/qt-creator
Clang: Fix applying override declarations
Since https://reviews.llvm.org/D50898 (clang-8) libclang provides override declarations when completing code in derived class scopes. Applying such a completion item appended "()" and resulted in invalid code, which is fixed with this change - the semicolon is inserted instead now. Change-Id: If2a04c5c719f62b98874f083a97445cd4e1db07d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -151,6 +151,19 @@ static bool skipParenForFunctionLikeSnippet(const std::vector<int> &placeholderP
|
||||
&& position + 1 == text.size();
|
||||
}
|
||||
|
||||
static bool isFuncDeclAsSingleTypedText(const CodeCompletion &completion)
|
||||
{
|
||||
// There is no libclang API to tell function call items from declaration items apart.
|
||||
// However, the chunks differ for these items (c-index-test -code-completion-at=...):
|
||||
// An (override) declaration (available in derived class scope):
|
||||
// CXXMethod:{TypedText void hello() override} (40)
|
||||
// A function call:
|
||||
// CXXMethod:{ResultType void}{TypedText hello}{LeftParen (}{RightParen )} (36)
|
||||
return completion.completionKind == CodeCompletion::FunctionDefinitionCompletionKind
|
||||
&& completion.chunks.size() == 1
|
||||
&& completion.chunks[0].kind == CodeCompletionChunk::TypedText;
|
||||
}
|
||||
|
||||
void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulator,
|
||||
int basePosition) const
|
||||
{
|
||||
@@ -232,8 +245,12 @@ void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulato
|
||||
cursor.setPosition(basePosition);
|
||||
abandonParen = QString("(;,{}").contains(prevChar);
|
||||
}
|
||||
if (!abandonParen)
|
||||
abandonParen = isAtUsingDeclaration(manipulator, basePosition);
|
||||
if (!abandonParen) {
|
||||
const bool isFullDecl = isFuncDeclAsSingleTypedText(ccr);
|
||||
if (isFullDecl)
|
||||
extraCharacters += QLatin1Char(';');
|
||||
abandonParen = isAtUsingDeclaration(manipulator, basePosition) || isFullDecl;
|
||||
}
|
||||
|
||||
if (!abandonParen && ccr.completionKind == CodeCompletion::FunctionDefinitionCompletionKind) {
|
||||
const CodeCompletionChunk resultType = ccr.chunks.first();
|
||||
|
Reference in New Issue
Block a user