【问题标题】:Visual Studio Code clangd extension configurationVisual Studio Code clangd 扩展配置
【发布时间】:2018-07-18 13:03:02
【问题描述】:

我正在尝试使用 vscode-clangd 扩展将 clangd 与 VS Code 集成,但我在配置包含路径时遇到问题...

我在 VS Code 设置中创建了额外的配置:

"clangd.path": "path_to_clangd/bin/clangd",
"clangd.arguments": [
    "-compile-commands-dir=path_to_commands/compile_commands.json"
]

但是扩展报告了很多缺失的包含错误。

我也试过了:

    "-compile-commands-dir=path_to_commands"

但这也没有用。

有谁知道如何配置这个扩展?我目前无法找到任何文档。

问候

【问题讨论】:

    标签: visual-studio-code clang


    【解决方案1】:

    你的路径应该是compile_commands.json的目录,而不是文件,你需要通过vscode-clangd扩展重启clangd

    settings.json

    {
        "cmake.buildDirectory": "${workspaceFolder}/debug",
        "clangd.arguments": [
            "-background-index",
            "-compile-commands-dir=debug"
        ],
    }
    

    重启

    1. 在你的项目根目录下改一点 .clang-tidy 文件,如果没有,用一些东西创建一个
    2. vscode-clangd 会提示你重启 clangd
    3. 检查clangd进程,应该类似于
    ❯ ps -Af | grep clangd
    awei     285478 282126  0 10:42 ?        00:00:03 /opt/llvm-10.0.0/bin/clangd -background-index -compile-commands-dir=debug
    

    【讨论】:

      【解决方案2】:

      这是我的答案,它有效:

          "clangd.path": "/Users/jiewang/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/11.0.0/clangd_11.0.0/bin/clangd",
          "clangd.arguments": [
              "--compile-commands-dir=${workspaceFolder}/build",
              "--completion-style=detailed",
              "--header-insertion=never"
          ],
      

      【讨论】:

        【解决方案3】:

        似乎 compile_commands.json 必须在文件夹根目录中才能让扩展程序找到它。

        我只是添加一个符号链接:

        ln -s /path-to-build-dir/compile_commands.json /path-to-src-root-dir/
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-11-22
          • 1970-01-01
          • 1970-01-01
          • 2014-01-23
          • 1970-01-01
          • 2015-11-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多