[PATCH] D154621: [ClangRepl] support code completion at the repl

Fred Fu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 09:10:42 PDT 2023


capfredf created this revision.
Herald added a project: All.
capfredf requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch enabled code completion for ClangREPL. The feature was built upon two
existing Clang components: a list completer for `LineEditor` and `SemaCodeCompletion`.

The former serves the main entry point to trigger the latter. Because a
completion point for a compiler instance needs to be unchanged once it is set,
an incremental compiler instance for code completion is created. In addition to
completion points, it differs from a regular incremental compiler in the following ways:

1. It does not execute input.

2. To obtain declarations or bindings from previous input in the same REPL

session, it carries over AST context source from the main compiler, i.e. the one
used for the interpreter.

3. It contains a `ReplCompletionConsumer`, a subclass of

`CodeCompletionConsumer`. The consumer communicates completion results from
`SemaCodeCompletion` back to the list completer for the REPL.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154621

Files:
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/ExternalSource.cpp
  clang/lib/Interpreter/ExternalSource.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/CodeCompletionTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154621.537760.patch
Type: text/x-patch
Size: 29253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/e5a6b8cc/attachment-0001.bin>


More information about the cfe-commits mailing list