Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clangd[lsp]): Args aren't being passed correctly. #193

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

Jint-lzxy
Copy link
Collaborator

@Jint-lzxy Jint-lzxy commented Aug 18, 2022

There've been updates to clangd (llvm, 13 - 14) that modified the method to pass args to the lsp.

TL;DR: We need to use the cmd table to pass clangd's arguments and set command-line arguments of the compiler (e.g., clang++) via clangd's configuration file in the source tree or an OS-specific directory. For most cases, --query-driver MUST be set so that clangd can correctly parse system's includes (e.g., for using #include<type_traits>), especially when the user doesn't provide compile_commands.json or compile_flags.txt.


Detailed Discussion about Configuration File (Maybe we need to add this to the wiki?)

Configuration is stored in YAML files. These are either:

  • project configuration: a file named .clangd in the source tree. (clangd searches in all parent directories of the active file).
    • Generally this should be used for shared and checked-in settings.
    • (Existing directories named .clangd can be deleted. These were used for temporary storage by clangd before version 11.)
  • user configuration: a config.yaml file in an OS-specific directory:
    • Windows: %LocalAppData%\clangd\config.yaml, typically C:\Users\Bob\AppData\Local\clangd\config.yaml.
    • macOS: ~/Library/Preferences/clangd/config.yaml.
    • Linux and others: $XDG_CONFIG_HOME/clangd/config.yaml, typically ~/.config/clangd/config.yaml.
Example (My) Configuration

CompileFlags:
  Add: [-Wall, -Wextra, -pedantic, -std=c++17]
  Remove: # Nothing.
  Compiler: clang++
Diagnostics:
  ClangTidy:
    Add: ["*"]
    Remove:
      [
        altera-*,
        bugprone-easily-swappable-parameters,
        cppcoreguidelines-avoid-c-arrays,
        cppcoreguidelines-avoid-non-const-global-variables,
        cppcoreguidelines-owning-memory,
        cppcoreguidelines-pro-bounds-constant-array-index,
        cppcoreguidelines-pro-bounds-pointer-arithmetic,
        cppcoreguidelines-pro-bounds-array-to-pointer-decay,
        cppcoreguidelines-pro-type-reinterpret-cast,
        cppcoreguidelines-pro-type-vararg,
        fuchsia-default-arguments-calls,
        fuchsia-default-arguments-declarations,
        fuchsia-overloaded-operator,
        fuchsia-statically-constructed-objects,
        google-build-using-namespace,
        google-objc-function-naming,
        google-readability-braces-around-statements,
        google-readability-casting,
        hicpp-avoid-c-arrays,
        hicpp-braces-around-statements,
        hicpp-no-array-decay,
        hicpp-signed-bitwise,
        hicpp-vararg,
        llvm-else-after-return,
        llvmlibc-callee-namespace,
        llvmlibc-implementation-in-namespace,
        llvmlibc-restrict-system-libc-headers,
        misc-no-recursion,
        modernize-avoid-c-arrays,
        modernize-use-nodiscard,
        modernize-use-trailing-return-type,
        readability-braces-around-statements,
        readability-else-after-return,
        readability-magic-numbers,
        readability-redundant-access-specifiers,
      ]
    CheckOptions:
      readability-identifier-naming.VariableCase: [CamelCase]
InlayHints:
  Enabled: No
  ParameterNames: Yes
  DeducedTypes: Yes
Hover:
  ShowAKA: Yes
Index:
  Background: Build

For more details visit: nvim-lspconfig's server setup document and LLVM clangd's website.

@ayamir ayamir closed this Aug 19, 2022
@ayamir ayamir reopened this Aug 19, 2022
@ayamir ayamir merged commit 8fccdc1 into ayamir:main Aug 19, 2022
vkingw pushed a commit to vkingw/nvimdots that referenced this pull request Feb 7, 2023
fix(clangd[lsp]): Args aren't being passed correctly.
YanTree pushed a commit to YanTree/nvim that referenced this pull request Apr 9, 2023
fix(clangd[lsp]): Args aren't being passed correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants