xmake-vscode icon indicating copy to clipboard operation
xmake-vscode copied to clipboard

Add command to setup whole vscode settings

Open xq114 opened this issue 4 years ago • 5 comments

你在什么场景下需要该功能?

目前clone一个xmake project之后想在vscode里面设置需要几步:

  1. 安装cpp、xmake插件
  2. 运行xmake config
  3. 运行xmake: update intellisense
  4. 打开c_cpp: set up configuration (UI)
  5. 点开Advanced Options
  6. 在compile commands区域输入${workspaceFolder}/.vscode/compile_commands.json
  7. 保存退出

每个xmake project,同一个project在每一台机器上都要重复一遍,非常麻烦

描述可能的解决方案

提供一个command XMake: Set up,完成上面的2-7步所有过程(但不安装新的包,如需要安装则提示用户),或者3-7步所有过程(也就是生成compile_commands.json后还生成一个c_cpp_properties.json),config留给用户决定

其他信息

需要根据当前compile_commands的生成路径传给c_cpp_properties.json;

之后如果分离了launch.json也可以加入这个feature

xq114 avatar Oct 15 '21 03:10 xq114

最近没啥时间搞,你可以提个 pr 过来 ,插件加载阶段 调用下 update_intellisense

https://github.com/xmake-io/xmake-vscode/blob/master/assets/update_intellisense.lua 里面改下,增加对 .vscode/c_cpp_properties.json 的编辑或者生成,追加对 compile_commands 的绑定

waruqi avatar Oct 15 '21 04:10 waruqi

要生成c_cpp_properties.json还得探测arch、compiler、cStandard和cppStandard,这些xmake中怎么实现呢

xq114 avatar Oct 15 '21 05:10 xq114

要生成c_cpp_properties.json还得探测arch、compiler、cStandard和cppStandard,这些xmake中怎么实现呢

os.arch is_arch 或者根据当前外面的 arch 配置来取也行

全局编译器

import("core.tool.compiler")
    local compinst = compiler.load("cxx")
    compinst:name()

cStandard,cppStandard 如果 xmake.lua 有设置 set_languages ,那么应该走 compile_commands 去覆盖它们,如果没有走默认全局的话,你可以根据当前编译平台和编译器 写死个默认值

waruqi avatar Oct 15 '21 06:10 waruqi

cStandard,cppStandard 如果 xmake.lua 有设置 set_languages ,那么应该走 compile_commands 去覆盖它们,如果没有走默认全局的话,你可以根据当前编译平台和编译器 写死个默认值

vscode只会采用全局cppStandard(没设置就默认c11和c++17),不会读取compile_commands里面的std flag,这里还要手动取出xmake中最新的language standard

xq114 avatar Oct 15 '21 07:10 xq114

core.project.project 里面通过 project.get("target.languages") 可以取全局的 set_languages 设置。。

如果没有全局的,走 project.targets() 遍历每个 target 取特定 target的设置。。target:get("languages")

waruqi avatar Oct 15 '21 07:10 waruqi