From 39491d7b6098f96eb1f88d68068eb654c1e2bd81 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 22 Jan 2018 17:18:28 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323133 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Preprocessor.cpp | 7 ++++++- test/CodeCompletion/inside-macros.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/CodeCompletion/inside-macros.cpp diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 7d789e7801..08469bc025 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -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); } diff --git a/test/CodeCompletion/inside-macros.cpp b/test/CodeCompletion/inside-macros.cpp new file mode 100644 index 0000000000..dc40c6ad31 --- /dev/null +++ b/test/CodeCompletion/inside-macros.cpp @@ -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 +} -- 2.50.1