Skip to content

feat: add structural completion for mcpp.toml - #9

Open
Ximiaw wants to merge 2 commits into
mcpp-community:mainfrom
Ximiaw:feat/mcpp-toml-structure-completion
Open

feat: add structural completion for mcpp.toml#9
Ximiaw wants to merge 2 commits into
mcpp-community:mainfrom
Ximiaw:feat/mcpp-toml-structure-completion

Conversation

@Ximiaw

@Ximiaw Ximiaw commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

概要

mcpp.toml 增加结构补全,依据设计 issue #8 的拆分结论,本 PR 只含可先
落地的结构层。Supersedes #4

提供的建议

  • 段头 snippet:25 段([package][targets.<name>][indices]
    [pack] 等),参数化段带可跳转占位符;
  • 写法模板:[dependencies] 的五种依赖写法、[features] 表形式、
    capabilities / xlings / tools.overrides / generated_files 等开放段的条目形态。

明确不含#8 范围内留待后续,接口已预留)

实现

  • 容错 TOML context scanner:未闭合输入容错、CRLF、引号/点分键、嵌套内联表
    下钻;输出带 token 位置的光标上下文,每条建议携带显式替换范围,不产生
    无效文本;
  • 条件段归组:[target.'cfg(windows)'.dependencies] 等正确识别;
  • 未知自定义段不提供建议(附录 A:不支持包自定义键);
  • 核心模块零 vscode 依赖、零 npm 依赖;extension.ts 仅 1:1 映射;
  • 设置 mcpp.tomlCompletion(resource 域,默认开启);未受信任工作区仅有
    纯文本补全,不执行任何外部程序(capabilities 描述已同步)。

测试

  • 新增 102 例:scanner 容错/替换范围/部分输入;补全行为矩阵;
  • 契约测试 44 例:全部段头与模板(含实例)经真实 mcpp build 验证,
    含「条件段拒绝非 build-input 键」反向断言;无 mcpp 环境自动 skip;
  • 全量 198 例通过。

已知缺口:vscode 胶水层(设置门 + 1:1 映射)无自动化测试,逻辑刻意压薄;
未知段被 mcpp 静默忽略,段头契约测试对「段被上游删除」不敏感(靠源码出处
注释 + 升级 diff 对照兜底)。

Section-header snippets and writing templates for free-vocabulary
sections, computed from a tolerant TOML parser that yields cursor
contexts with explicit replacement ranges (unterminated input, CRLF,
quoted/dotted keys, nested inline tables). Conditional sections such as
[target.<sel>.dependencies] resolve to their base group.

No static field keys/enums (waiting for a versioned upstream manifest
schema) and no dynamic dependency data (waiting for a batch catalog
interface); the completion query layer is provider-dispatch so both can
be added back without touching the parser. Contract tests run every
registered section header and template key through real mcpp builds
(skipped where mcpp is absent). Gated by mcpp.tomlCompletion
(default on).
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.

1 participant