xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.06k stars 785 forks source link

compile_commands.json 中的 ifc 文件相对路径无法被 VS Code IntelliSense 识别 #5368

Open weichzh opened 3 months ago

weichzh commented 3 months ago

Xmake 版本

2.9.3

操作系统版本和架构

Windows 11 23H2

描述问题

不修改直接生成 compile_commands.json IntelliSense 会报错,找不到 module。 image

// compile_commands.json
[
//...
  {
    "directory": "e:\\Code\\cpplearn",
    "arguments": [
      "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX64\\x64\\cl.exe",
      "/c",
      "/nologo",
      "/O2",
      "/std:c++latest",
      "/EHsc",
      "/IC:\\Users\\nick\\AppData\\Local\\.xmake\\packages\\n\\nlohmann_json\\v3.11.3\\826582eb66794908a16a49dbdd33bec4\\include",
      "/DNDEBUG",
      "/reference",
//下面两行是相对路径
      "exercise=build\\.gens\\cpplearn\\windows\\x64\\release\\rules\\bmi\\cache\\modules\\0edca419\\exercise.ifc",
      "/reference",
      "resource=build\\.gens\\cpplearn\\windows\\x64\\release\\rules\\bmi\\cache\\modules\\0edca419\\resource.ifc",
      "/Fobuild\\.objs\\cpplearn\\windows\\x64\\release\\src\\main.cpp.obj",
      "src\\main.cpp",
      "-imsvc",
      "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt",
      "-imsvc",
      "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared",
      "-imsvc",
      "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt",
      "-imsvc",
      "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um",
      "-imsvc",
      "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt",
      "-imsvc",
      "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\include"
    ],
    "file": "src\\main.cpp"
  }
]

给改为绝对路径后智能提示能正常显示。

期待的结果

生成 compile_commands.json 时给设置为绝对路径。

工程配置

-- xmake.lua
add_rules("mode.debug", "mode.release")
add_requires("nlohmann_json v3.11.3")
set_languages("c++23")

target("cpplearn")
    set_kind("binary")
    add_files("src/*.cpp", "src/lib/*.ixx")
    add_packages("nlohmann_json")

附加信息和错误日志

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: compile_commands.json cannot be recognized by VS Code IntelliSense

waruqi commented 3 months ago

这不应该是 VS Code IntelliSense 的问题么,你得到他们那边去反馈。。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Shouldn't this be a problem with VS Code IntelliSense? You need to get feedback from them. .

weichzh commented 3 months ago

这不应该是 VS Code IntelliSense 的问题么,你得到他们那边去反馈。。

我那边也发了。感觉module现在各方面支持都还是很差。。。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Shouldn't this be a problem with VS Code IntelliSense? You need to get feedback from them. .

I also sent it over there. I feel that module support in all aspects is still very poor. . .

waruqi commented 3 months ago

不是感觉,原本现在 lsp 和 编译器都还没完整支持。你现在用 就是躺坑。。想要稳定用,建议再等 5 年。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


It's not my feeling, originally lsp and compiler are not fully supported yet. What you use now is just lying in a trap. . If you want stable use, it is recommended to wait another 5 years.

Arthapz commented 3 months ago

u can try https://github.com/ChuanqiXu9/clangd-for-modules and https://github.com/Arthapz/xmake/tree/clangd-module-map

i can confirm that it work (i'm using it under neovim, but vscode clangd lsp ext should handle it too)

image

(i added these parameters to clangd to make it work "--offset-encoding=utf-16", "--header-insertion=never", "--experimental-modules-support", "--compile-commands-dir=.vscode", "--modules-map-path=build/clangd_mapper.txt")