[clangd] Full support for #import insertions
authorDavid Goldman <davg@google.com>
Tue, 6 Dec 2022 21:33:12 +0000 (16:33 -0500)
committerDavid Goldman <davg@google.com>
Mon, 9 Jan 2023 14:48:30 +0000 (09:48 -0500)
commit042dd99484d6f393cc8a365def250e9d74c24d37
tree5469de1f513bdcf45e841fc35092c5ac1657f415
parent814c0bb31660b2441c9a9a6eeaafc2e33c416842
[clangd] Full support for #import insertions

These are still disabled by default, but will work in ObjC code if you
enable the `-import-insertions` flag.

Completion requires ASTSignals to be available; before ASTSignals are
available, we will always use #include. Once they are available, the
behavior varies as follows:

- For source files, use #import if the ObjC language flag is enabled
- For header files:
  - If the ObjC language flag is disabled, use #include
  - If the header file contains any #imports, use #import
  - If the header file references any ObjC decls, use #import
  - Otherwise, use #include

IncludeFixer support is similar, but it does not rely upon ASTSignals,
instead it does the above checks excluding the scan for ObjC symbols.

Differential Revision: https://reviews.llvm.org/D139458
16 files changed:
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/AST.h
clang-tools-extra/clangd/ASTSignals.cpp
clang-tools-extra/clangd/ASTSignals.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Compiler.h
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/IncludeFixer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
clang-tools-extra/clangd/unittests/ASTTests.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp