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

无法正常生成compile_commands,以及“Error:there is no registered task type 'cppbuild'” #256

Open
luyiyun opened this issue Feb 20, 2024 · 1 comment
Labels

Comments

@luyiyun
Copy link

luyiyun commented Feb 20, 2024

Xmake 版本

v2.8.6+master.8545a9301

操作系统版本和架构

Windows 10 22H2

描述问题

使用xmake: createProject创建project(c++,console)后,compile_commands.json内容不完整:
image
我尝试了以下几种操作:

  • 运行xmake:UpdateIntellisense
  • 修改xmake.lua后保存来触发compile_commands.json文件的自动生成
  • 将compile_commands.json删除后,尝试上述两种方式

compile_commands.json会重新生成,但内容依然是不完整的(和上图一样)。
有很小的几率,我将[补全为[],然后重新生成会正常。

还有就是,我发现,如果我先build一遍,然后再去尝试生成compile_commands.json就可以了。

我使用的c++ LSP是clangd而非cpptools,下面是我的xmake插件的相关配置:

	"xmake.debugConfigType": "codelldb", // 使用 codelldb 插件而非 cpptools 进行调试
	"xmake.runMode": "buildRun", // 运行前自动 build
	"xmake.buildLevel": "verbose", // 设置编译时输出信息级别,默认是warnings级别,仅输出编译警告信息以及正常信息,verbose级别输出完整的编译命令行参数,debug级别对应 xmake -vD 的诊断信息,会打印出错的栈信息
	"xmake.customDebugConfig": {
		"console": "integratedTerminal" // XMake调试时使用集成终端而非 debug console,也可以使用 externalTerminal
	},

下面是clangd的相关配置:

	// clangd
	"clangd.path": "c:\\Users\\admin\\AppData\\Roaming\\Code\\User\\globalStorage\\llvm-vs-code-extensions.vscode-clangd\\install\\17.0.3\\clangd_17.0.3\\bin\\clangd.exe",
	// Clangd 运行参数(终端输入 clangd --help-list-hidden 可查看更多)
	"clangd.arguments": [
		"--all-scopes-completion", // 全局补全(补全建议会给出在当前作用域不可见的索引,插入后自动补充作用域标识符),例如在main()中直接写cout,即使没有`#include <iostream>`,也会给出`std::cout`的建议,配合"--header-insertion=iwyu",还可自动插入缺失的头文件
		"--background-index", // 后台分析并保存索引文件
		"--clang-tidy", // 启用 Clang-Tidy 以提供「静态检查」
		"--clang-tidy-checks=performance-*, bugprone-*, misc-*, google-*, modernize-*, readability-*, portability-*",
		"--compile-commands-dir=.vscode", // 编译数据库(compile_commands.json 文件)的目录位置
		"--completion-parse=auto", // 当 clangd 准备就绪时,用它来分析建议
		"--completion-style=detailed", // 建议风格:打包(重载函数只会给出一个建议);还可以设置为 detailed
		// "--query-driver=/usr/bin/clang++", // MAC 上需要设定 clang 编译器的路径,也可以是 /usr/local/opt/llvm/bin/clang++
		// 启用配置文件(YAML格式)项目配置文件是在项目文件夹里的“.clangd”,用户配置文件是“clangd/config.yaml”,该文件来自:Windows: %USERPROFILE%\AppData\Local || MacOS: ~/Library/Preferences/ || Others: $XDG_CONFIG_HOME, usually ~/.config
		"--enable-config",
		"--fallback-style=Webkit", // 默认格式化风格: 在没找到 .clang-format 文件时采用,可用的有 LLVM, Google, Chromium, Mozilla, Webkit, Microsoft, GNU
		"--function-arg-placeholders=true", // 补全函数时,将会给参数提供占位符,键入后按 Tab 可以切换到下一占位符,乃至函数末
		"--header-insertion-decorators", // 输入建议中,已包含头文件的项与还未包含头文件的项会以圆点加以区分
		"--header-insertion=iwyu", // 插入建议时自动引入头文件 iwyu
		"--include-cleaner-stdlib", // 为标准库头文件启用清理功能(不成熟!!!)
		"--log=verbose", // 让 Clangd 生成更详细的日志
		"--pch-storage=memory", // pch 优化的位置(Memory 或 Disk,前者会增加内存开销,但会提升性能)
		"--pretty", // 输出的 JSON 文件更美观
		"--ranking-model=decision_forest", // 建议的排序方案:hueristics (启发式), decision_forest (决策树)
		"-j=12" // 同时开启的任务数量
	],
	// 找不到编译数据库(compile_flags.json 文件)时使用的编译器选项,这样的缺陷是不能直接索引同一项目的不同文件,只能分析系统头文件、当前文件和被include的文件
	"clangd.fallbackFlags": [
		"-pedantic",
		"-Wall",
		"-Wextra",
		"-Wcast-align",
		"-Wdouble-promotion",
		"-Wformat=2",
		"-Wimplicit-fallthrough",
		"-Wmisleading-indentation",
		"-Wnon-virtual-dtor",
		"-Wnull-dereference",
		"-Wold-style-cast",
		"-Woverloaded-virtual",
		"-Wpedantic",
		"-Wshadow",
		"-Wunused",
		"-pthread",
		"-fuse-ld=lld",
		"-fsanitize=address",
		"-fsanitize=undefined",
		"-stdlib=libc++"
	],
	"clangd.checkUpdates": true, // 自动检测 clangd 更新
	"clangd.onConfigChanged": "restart", // 重启 clangd 时重载配置,具体方法: F1 + Fn 打开命令面板,然后搜索“clangd: restart"
	"clangd.serverCompletionRanking": true, // 借助网上的信息排序建议
	"clangd.detectExtensionConflicts": true, // 当其它拓展与 clangd 冲突时警告并建议禁用
	"editor.suggest.snippetsPreventQuickSuggestions": false, // clangd的snippets有很多的跳转点,不用这个就必须手动触发Intellisense了
	// LLDB
	"lldb.commandCompletions": true, // LLDB 指令自动补全
	"lldb.dereferencePointers": true, // LLDB 指针显示解引用内容
	"lldb.evaluateForHovers": true, // LLDB 鼠标悬停在变量上时预览变量值
	"lldb.launch.expressions": "native", // LLDB 监视表达式的默认类型
	"lldb.showDisassembly": "never", // LLDB 不显示汇编代码
	"lldb.verboseLogging": true,

此外,我在运行xmake:createProject和xmake:run是,vscode会报错:

Error: there is no registered task type 'cppbuild'. Did you miss installing an extension that provides a corresponding task provider?

期待的结果

能够正常生成compile_commands.json,从而触发正常的clangd的功能,并且vscode不报错。

工程配置

add_rules("mode.debug", "mode.release")
set_languages("c++20")

target("77-chapter14_3-quiz")
    set_kind("binary")
    add_files("src/*.cpp")

附加信息和错误日志

none

@luyiyun luyiyun added the bug label Feb 20, 2024
@waruqi
Copy link
Member

waruqi commented Feb 21, 2024

先手动执行下 xmake project -k compile_commands 看下生成的是否完整, 插件也是调用这个命令生成

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants