aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/CodeComplete.cpp
diff options
context:
space:
mode:
authorFred Fu <moonsolo@gmail.com>2023-08-28 19:12:29 +0000
committerVassil Vassilev <v.g.vassilev@gmail.com>2023-08-28 19:59:56 +0000
commit5ab25a42ba70c4b50214b0e78eaaccd30696fa09 (patch)
tree112c1671a82b1c65d9d95b5577980935e0fcba81 /clang-tools-extra/clangd/CodeComplete.cpp
parentf0e2a5e260c24597f11b122d20051f057d96b544 (diff)
downloadllvm-5ab25a42ba70c4b50214b0e78eaaccd30696fa09.zip
llvm-5ab25a42ba70c4b50214b0e78eaaccd30696fa09.tar.gz
llvm-5ab25a42ba70c4b50214b0e78eaaccd30696fa09.tar.bz2
Reland "[clang-repl] support code completion at a REPL."
Original commit message: " This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382 " The new patch also fixes clangd and several memory issues that the bots reported.
Diffstat (limited to 'clang-tools-extra/clangd/CodeComplete.cpp')
-rw-r--r--clang-tools-extra/clangd/CodeComplete.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 68e12b2..1a0023d 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -821,6 +821,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) {
case CodeCompletionContext::CCC_Symbol:
case CodeCompletionContext::CCC_SymbolOrNewName:
case CodeCompletionContext::CCC_ObjCClassForwardDecl:
+ case CodeCompletionContext::CCC_TopLevelOrExpression:
return true;
case CodeCompletionContext::CCC_OtherWithMacros:
case CodeCompletionContext::CCC_DotMemberAccess: