Skip to content

feat: add opt-in code completion for mcpp.toml - #4

Closed
Ximiaw wants to merge 8 commits into
mcpp-community:mainfrom
Ximiaw:feat/mcpp-toml-completion
Closed

feat: add opt-in code completion for mcpp.toml#4
Ximiaw wants to merge 8 commits into
mcpp-community:mainfrom
Ximiaw:feat/mcpp-toml-completion

Conversation

@Ximiaw

@Ximiaw Ximiaw commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

概要

mcpp.toml 增加代码补全(默认关闭,经 mcpp.tomlCompletion 设置开启)。
字段表对齐 mcpp 主仓库文档:docs/zh/05-mcpp-toml.md 为主,并覆盖
02-pack-and-release.md([pack])、03-toolchains.md([toolchain] 平台 pin、
[build].target、linkage 取值)、06-workspace.md([workspace]、
[package].namespace、依赖 spec 的 workspace 继承键)。

补全内容

  • 段头:[package]、[targets.]、[workspace]、[pack] 等 22 个段,
    参数化段插入 snippet 占位符
  • 字段键:按当前段给出,字符串/数组/布尔分别带 "$1" / [$1] / $1 占位
  • 枚举与布尔值:standard、kind、cxx_runtime、cache、c_standard、
    platforms、default_profile/profile、linkage、opt 及布尔键
  • 内联表 spec 键:依赖(version/path/git/features/tools/host-module/
    reexport/workspace 等)与 feature(defines/implies/sources/requires 等)
  • per-glob 旗标键:[build].flags / feature flags 条目内的
    glob/cflags/cxxflags/asmflags/defines
  • 写法模板:[dependencies]、[features] 等开放词汇段的常用写法 snippet
  • 条件段归属:[target.'cfg(...)'.build] 等正确归入对应组;
    未识别的自定义段不提供建议(附录 A:不支持包自定义键)

实现

  • 补全逻辑为不依赖 vscode API 的纯模块(src/mcppTomlCompletion.ts),
    extension.ts 只做 CompletionItem 映射;段头建议覆盖已输入的 [ 前缀
  • 仅绑定 mcpp-toml 语言(精确文件名 mcpp.toml),不影响其他文件
  • 新增 onLanguage:mcpp-toml 激活事件
  • 新增 mcpp.tomlCompletion 设置(resource 作用域,默认 false):
    该功能尚不完善,字段表可能滞后于 mcpp 演进,故默认关闭

测试

  • 新增 26 个 node:test 用例,覆盖段头/键/值/内联表/模板/条件段/
    点式选择器键/未知段等场景
  • 全量 122 个测试通过

Ximiaw added 8 commits August 7, 2026 17:41
Suggest section headers, per-section keys, and enum/boolean values
aligned with docs/zh/05-mcpp-toml.md, plus long-form spec keys inside
dependency and feature inline tables. Registered for the mcpp-toml
language with onLanguage activation; completion logic is a pure module
covered by node:test cases.
Empty positions in [dependencies], [features], [generated_files],
[capabilities], [xlings.workspace], [xlings.envs] and [tools.overrides]
now offer snippet templates of the common forms instead of nothing.
Also use Folder/EnumMember/Snippet completion item kinds so section,
key and value suggestions render with fitting icons.
Add key completions for [build.cxx_runtime] (default/tests),
[resources.version-info] and [runtime."<cap>"] (provider), and the
[build].profile alias of default-profile, all per docs/zh/05-mcpp-toml.md.
Offer glob/cflags/cxxflags/asmflags/defines inside [build].flags and
feature flags inline-table entries (docs/zh/05-mcpp-toml.md section
2.3/2.8). SectionSpec no longer carries key data; section lookup reads
SECTION_GROUPS only.
Bare dotted dependency keys (capi.lua, imgui.backend.glfw_opengl3)
now parse as key=value positions instead of falling back to template
suggestions. Sections are tri-state: document top offers section
headers, unknown custom sections offer nothing (appendix A: custom
toml keys are unsupported), known groups offer their keys.
The mcpp.toml field set spans more than docs/zh/05-mcpp-toml.md:
- [workspace] members/exclude and [workspace.dependencies] with
  namespace subtables (06-workspace.md)
- [package].namespace and the dependency spec workspace = true
  inheritance key (06-workspace.md)
- [toolchain] per-platform pins linux/macos/windows and
  [build].target with the documented target vocabulary
  (03-toolchains.md)
- linkage = "dynamic" alongside static (03-toolchains.md)
[pack] default_mode/include/exclude and [pack.bundle-project]
also_skip/force_bundle per docs/zh/02-pack-and-release.md. All zh docs
(00-10) are now swept for mcpp.toml sections; no others define new
manifest tables.
New mcpp.tomlCompletion boolean setting (resource scope, default
false); the completion provider returns nothing until it is enabled.
@wellwei

wellwei commented Aug 7, 2026

Copy link
Copy Markdown
Member

维护者结论:这个 PR 暂时保留,不关闭,但当前不合并。补全功能有用户价值,默认关闭和 resource 级设置也合理;主要问题是当前实现把快速演进的 mcpp manifest schema 复制成扩展内约 659 行手写表,提交时已经与权威解析器发生漂移。继续逐项补字段之前,应先确定可维护的数据来源和功能范围。

当前确认的问题:

  1. 条件 build 段会建议无效字段。 [target.<predicate>.build] 被归入完整 [build],从而建议 targetcacheprofilecxx_runtimec_standard 等字段;mcpp 条件段只接受 build inputs,其余字段会被警告并忽略。

  2. key/value 补全没有显式替换范围。 provider 目前只为 section 设置 range。接受 default-p"c++2 等部分输入的建议时,VS Code 默认 word range 可能留下重复前缀、错误引号或损坏文本。需要针对实际 CompletionItem 映射做测试,而不只是测试纯函数返回值。

  3. feature 内嵌 flags 补全分支不可达。feature = { flags = [ { ... } ] },代码会先命中 feature 外层 inline spec 分支并返回,后面的 per-glob glob/cflags/cxxflags/asmflags/defines 分支不会执行。

  4. schema 已有缺失和语法覆盖空洞。 当前至少缺少 default-featuresvisibilityforwardallow_host_libsdialect_cxxflags 等字段,也未覆盖解析器接受的 [[build.flags]][[features.<name>.flags]];段头和 target 词表也已有遗漏。

  5. 测试边界不足。 现有测试主要验证纯函数的建议列表,没有覆盖配置开关、VS Code provider 映射、替换范围、引号闭合以及真实 mcpp parser 是否接受补全结果。

建议先补一个需求/设计 Issue,在以下方向中作出选择:

  • 只提供少量稳定段头和 snippets,不承诺完整 schema;或
  • 由 mcpp 提供版本化、机器可读的 manifest schema,再生成/消费补全数据。

不建议把“默认关闭”作为生成无效配置的兼容策略。如果继续当前手写 schema 路线,至少需要逐项对齐当前 mcpp parser,并增加 provider 层和 parser 契约测试。

我在该提交上独立复核了 npm test,结果为 122/122;这些测试目前没有覆盖上述问题。

@Ximiaw

Ximiaw commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #9

@Ximiaw Ximiaw closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants