Author: ibiryukov Date: Mon Jan 22 09:18:28 2018 New Revision: 323133 URL: http://llvm.org/viewvc/llvm-project?rev=323133&view=rev Log: [CodeComplete] Fix completion in the middle of idents in macro calls
Summary: This patch removes IdentifierInfo from completion token after remembering the identifier in the preprocessor. Prior to this patch, completion token had the IdentifierInfo set to null when completing at the start of identifier and to the II for completion prefix when in the middle of identifier. This patch unifies how code completion token is handled when it is insterted before the identifier and in the middle of the identifier. The actual IdentifierInfo can still be obtained from the Preprocessor. Reviewers: bkramer, arphaman Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42241 Added: cfe/trunk/test/CodeCompletion/inside-macros.cpp Modified: cfe/trunk/lib/Lex/Preprocessor.cpp Modified: cfe/trunk/lib/Lex/Preprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=323133&r1=323132&r2=323133&view=diff ============================================================================== --- cfe/trunk/lib/Lex/Preprocessor.cpp (original) +++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Jan 22 09:18:28 2018 @@ -773,8 +773,13 @@ void Preprocessor::Lex(Token &Result) { } } while (!ReturnedToken); - if (Result.is(tok::code_completion)) + if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) { + // Remember the identifier before code completion token. setCodeCompletionIdentifierInfo(Result.getIdentifierInfo()); + // Set IdenfitierInfo to null to avoid confusing code that handles both + // identifiers and completion tokens. + Result.setIdentifierInfo(nullptr); + } LastTokenWasAt = Result.is(tok::at); } Added: cfe/trunk/test/CodeCompletion/inside-macros.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/inside-macros.cpp?rev=323133&view=auto ============================================================================== --- cfe/trunk/test/CodeCompletion/inside-macros.cpp (added) +++ cfe/trunk/test/CodeCompletion/inside-macros.cpp Mon Jan 22 09:18:28 2018 @@ -0,0 +1,13 @@ +#define ID(X) X + +void test(bool input_var) { + ID(input_var) = true; + // Check that input_var shows up when completing at the start, in the middle + // and at the end of the identifier. + // + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:6 %s -o - | FileCheck %s + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:8 %s -o - | FileCheck %s + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:15 %s -o - | FileCheck %s + + // CHECK: input_var +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits