From: Kadir Cetinkaya Date: Mon, 13 Aug 2018 08:13:35 +0000 (+0000) Subject: [clang] Store code completion token range in preprocessor. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0a5e830f198cf42d29f72f1ec06fbf4c5210e2c;p=clang [clang] Store code completion token range in preprocessor. Summary: This change is to support a new fature in clangd, tests will be send toclang-tools-extra with that change. Unittests are included in: https://reviews.llvm.org/D50449 Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50443 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339540 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index e718f5b6bb..0feeca56f7 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -310,6 +310,9 @@ class Preprocessor { /// on the stem that is to be code completed. IdentifierInfo *CodeCompletionII = nullptr; + /// Range for the code completion token. + SourceRange CodeCompletionTokenRange; + /// The directory that the main file should be considered to occupy, /// if it does not correspond to a real file (as happens when building a /// module). @@ -1131,6 +1134,16 @@ public: CodeCompletionII = Filter; } + /// Set the code completion token range for detecting replacement range later + /// on. + void setCodeCompletionTokenRange(const SourceLocation Start, + const SourceLocation End) { + CodeCompletionTokenRange = {Start, End}; + } + SourceRange getCodeCompletionTokenRange() const { + return CodeCompletionTokenRange; + } + /// Get the code completion token for filtering purposes. StringRef getCodeCompletionFilter() { if (CodeCompletionII) diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index def47b2f10..bfeaa03d85 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -868,6 +868,7 @@ void Preprocessor::Lex(Token &Result) { if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) { // Remember the identifier before code completion token. setCodeCompletionIdentifierInfo(Result.getIdentifierInfo()); + setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc()); // Set IdenfitierInfo to null to avoid confusing code that handles both // identifiers and completion tokens. Result.setIdentifierInfo(nullptr);