gpt4 book ai didi

Have .clangd configure differently based on windows vs linux(根据Windows和Linux配置不同的.clangd)

转载 作者:bug小助手 更新时间:2023-10-24 21:03:39 24 4
gpt4 key购买 nike



I have a cmake C++ project. I access the project directory from WSL2-Ubuntu and MINGW64 git-bash on my Windows machine. I have a separate build folder for each: build-wsl and build-win respectively.

我有一个cmake C++项目。在我的Windows机器上,我从wsl2-ubuntu和MINGW64git-bash访问项目目录。我分别为它们创建了一个单独的构建文件夹:Build-WSL和Build-Win。


I'm trying to configure the project with the clangd LSP for neovim. I know I can create a .clangd config at the project root to tell clangd where to look for the compile_commands.json. I'd like to do something like this:

我正在尝试为nevim配置clangd lsp的项目。我知道我可以在项目根目录创建一个.clangd配置,告诉clangd在哪里可以找到COMPILE_COMMANDS.json。我想做这样的事情:


If: WIN32
CompileFlags:
CompilationDatabase: build-win/
Else:
CompilationFlags:
CompilationDatabase: build-wsl/

Is there a way to achieve that? If so, how? Thanks in advance!

有没有办法实现这一点?如果是这样的话,是如何做到的呢?提前谢谢!


更多回答
优秀答案推荐

I'm not aware of any support for this in the config file syntax itself.

我不知道配置文件语法本身对此有任何支持。


One thing to consider might be having your build system generate the .clangd file with different contents on different platforms (then the platform-checking logic would go into the cmake script). Though, if the location of CompilationDatabase is the only thing that differs between the platforms, a simpler alternative might be to just have your build system symlink (or copy) the compile_commands.json file from the respective location to the project root, where clangd will find it automatically.

需要考虑的一件事可能是让您的构建系统在不同的平台上生成具有不同内容的.clangd文件(然后平台检查逻辑将进入cmake脚本)。但是,如果CompilationDatabase的位置是不同平台之间唯一不同的地方,一个更简单的替代方法可能是让构建系统符号链接(或复制)COMPILE_COMMANDS.json文件从各自的位置到项目根目录,在那里clangd会自动找到它。


更多回答

Thank you for the suggestions. Though one issue is that I'm accessing the same directory from both WSL and git bash. I just tried symlinking build-win/ -> build/ in git bash, but the symlink also appeared my WSL shell. With the cmake logic, copying out compile_commands.json to project root from one shell, would wipe out the file created by the other shell. So I would need to rerun cmake every time I switched shells. Something that came to mind just now, is I could use $XDG_CONFIG_HOME/clang/config.yaml on each machine.

谢谢你的建议。尽管有一个问题是我同时从wsl和git bash访问相同的目录。我刚刚在git bash中尝试了symlink Build-win/->Build/,但symlink也显示了我的WSL外壳。使用cmake逻辑,从一个外壳中将Compile_Commands.json复制到项目根目录,将会清除另一个外壳创建的文件。因此,每次切换外壳时,我都需要重新运行cmake。刚才想到的是,我可以在每台机器上使用$XDG_CONFIG_HOME/clang/config.yaml。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com