[PATCH] D42241: [CodeComplete] Fix completion in the middle of idents in macro calls
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 18 07:10:35 PST 2018
ilya-biryukov created this revision.
ilya-biryukov added reviewers: bkramer, arphaman.
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.
Repository:
rC Clang
https://reviews.llvm.org/D42241
Files:
lib/Lex/Preprocessor.cpp
test/CodeCompletion/inside-macros.cpp
Index: test/CodeCompletion/inside-macros.cpp
===================================================================
--- /dev/null
+++ 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
+}
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -773,8 +773,13 @@
}
} 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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42241.130406.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180118/86b74eb7/attachment.bin>
More information about the cfe-commits
mailing list