[all-commits] [llvm/llvm-project] 814c0b: [clangd] Add flag to control #import include inser...

David Goldman via All-commits all-commits at lists.llvm.org
Mon Jan 9 07:04:13 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 814c0bb31660b2441c9a9a6eeaafc2e33c416842
      https://github.com/llvm/llvm-project/commit/814c0bb31660b2441c9a9a6eeaafc2e33c416842
  Author: David Goldman <davg at google.com>
  Date:   2023-01-09 (Mon, 09 Jan 2023)

  Changed paths:
    M clang-tools-extra/clangd/CodeComplete.h
    M clang-tools-extra/clangd/tool/ClangdMain.cpp

  Log Message:
  -----------
  [clangd] Add flag to control #import include insertions

This will be disabled by default, hopefully we can enable for the next
major release.

Differential Revision: https://reviews.llvm.org/D139446


  Commit: 042dd99484d6f393cc8a365def250e9d74c24d37
      https://github.com/llvm/llvm-project/commit/042dd99484d6f393cc8a365def250e9d74c24d37
  Author: David Goldman <davg at google.com>
  Date:   2023-01-09 (Mon, 09 Jan 2023)

  Changed paths:
    M clang-tools-extra/clangd/AST.cpp
    M clang-tools-extra/clangd/AST.h
    M clang-tools-extra/clangd/ASTSignals.cpp
    M clang-tools-extra/clangd/ASTSignals.h
    M clang-tools-extra/clangd/ClangdServer.cpp
    M clang-tools-extra/clangd/ClangdServer.h
    M clang-tools-extra/clangd/CodeComplete.cpp
    M clang-tools-extra/clangd/Compiler.h
    M clang-tools-extra/clangd/IncludeFixer.cpp
    M clang-tools-extra/clangd/IncludeFixer.h
    M clang-tools-extra/clangd/ParsedAST.cpp
    M clang-tools-extra/clangd/ParsedAST.h
    M clang-tools-extra/clangd/tool/ClangdMain.cpp
    M clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
    M clang-tools-extra/clangd/unittests/ASTTests.cpp
    M clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

  Log Message:
  -----------
  [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


Compare: https://github.com/llvm/llvm-project/compare/59f91ddf90d4...042dd99484d6


More information about the All-commits mailing list