|
| 1 | +# Clangd Hermetic CDB and build.mcpp Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Remove false clangd diagnostics from hermetic mcpp projects, keep module checks on project sources, and prevent clangd from treating `build.mcpp` as an ordinary C++ translation unit. |
| 6 | + |
| 7 | +**Architecture:** Keep clangd's query-driver discovery for ordinary or cross-toolchain CDBs, but skip it when the selected mcpp command already declares a no-default-config sysroot and standard library. Give `build.mcpp` its own language id backed by the C++ TextMate grammar so syntax highlighting remains while the official clangd extension no longer claims the document. Rank real project sources above `.mcpp` dependency-cache and `target` commands for the extension's direct module check. |
| 8 | + |
| 9 | +**Tech Stack:** TypeScript 5.9, VS Code extension manifests and TextMate grammars, Node.js built-in test runner, clangd 22.1.8, VSCE. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Preserve hermetic compilation commands |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Modify: `src/analysis.ts` |
| 17 | +- Modify: `src/extension.ts` |
| 18 | +- Test: `test/analysis.test.ts` |
| 19 | + |
| 20 | +- [x] **Step 1: Write the failing hermetic CDB argument tests** |
| 21 | + |
| 22 | +Add tests that pass the selected CDB arguments through `buildClangdArguments`. A command containing `--no-default-config`, `-nostdinc++`, an explicit `-isystem.../include/c++/v1`, and `--sysroot=...` must remove a previously managed `--query-driver`; an ordinary command must still receive the selected compiler as its query driver. |
| 23 | + |
| 24 | +- [x] **Step 2: Run the analysis test and verify RED** |
| 25 | + |
| 26 | +Run: `npm run compile && node --test dist/test/analysis.test.js` |
| 27 | + |
| 28 | +Expected: the hermetic test fails because the current implementation always appends `--query-driver`. |
| 29 | + |
| 30 | +- [x] **Step 3: Implement the minimum query-driver policy** |
| 31 | + |
| 32 | +Add `compilationArguments?: readonly string[]` to `ClangdArgumentOptions`. Treat a command as self-contained only when all four hermetic markers are present, remove managed query-driver arguments, and append the selected compiler only for non-self-contained commands. Pass `context.analysis.arguments` from both the workspace configuration path and direct `clangd --check` path in `src/extension.ts`. |
| 33 | + |
| 34 | +- [x] **Step 4: Run the focused tests and verify GREEN** |
| 35 | + |
| 36 | +Run: `npm run compile && node --test dist/test/analysis.test.js` |
| 37 | + |
| 38 | +Expected: all analysis tests pass. |
| 39 | + |
| 40 | +### Task 2: Select a project-owned module check source |
| 41 | + |
| 42 | +**Files:** |
| 43 | +- Modify: `src/analysis.ts` |
| 44 | +- Test: `test/analysis.test.ts` |
| 45 | + |
| 46 | +- [x] **Step 1: Write the failing dependency-cache ranking test** |
| 47 | + |
| 48 | +Create a CDB fixture whose first LLVM command points to `/work/app/.mcpp/.../transaction.cpp` with PCM flags and whose later command points to `/work/app/src/main.cpp` with the same flags. Assert that `analyzeCompilationDatabase` selects `/work/app/src/main.cpp`. |
| 49 | + |
| 50 | +- [x] **Step 2: Run the focused test and verify RED** |
| 51 | + |
| 52 | +Run: `npm run compile && node --test dist/test/analysis.test.js` |
| 53 | + |
| 54 | +Expected: the new test selects the `.mcpp` command and fails. |
| 55 | + |
| 56 | +- [x] **Step 3: Implement project-source ranking** |
| 57 | + |
| 58 | +Keep the existing in-project and module-interface scoring, but add a higher score for paths below the command directory whose first component is neither `.mcpp` nor `target`. Preserve the existing fallback when a CDB contains only dependency or generated commands. |
| 59 | + |
| 60 | +- [x] **Step 4: Run the focused tests and verify GREEN** |
| 61 | + |
| 62 | +Run: `npm run compile && node --test dist/test/analysis.test.js` |
| 63 | + |
| 64 | +Expected: all analysis tests pass and the selected UChat check source is a member source file. |
| 65 | + |
| 66 | +### Task 3: Make build.mcpp syntax-only |
| 67 | + |
| 68 | +**Files:** |
| 69 | +- Modify: `package.json` |
| 70 | +- Create: `syntaxes/mcpp-build.tmLanguage.json` |
| 71 | +- Create: `syntaxes/mcpp-build-language-configuration.json` |
| 72 | +- Modify: `test/artifacts.test.ts` |
| 73 | +- Modify: `README.md` |
| 74 | + |
| 75 | +- [x] **Step 1: Write the failing manifest and grammar tests** |
| 76 | + |
| 77 | +Assert that the manifest declares exact filename language `mcpp-build`, that `files.associations` no longer maps `build.mcpp` to `cpp`, and that the new grammar maps `mcpp-build` to `source.mcpp-build` and includes the external `source.cpp` grammar. Keep the assertion that no broad `*.mcpp` association exists. |
| 78 | + |
| 79 | +- [x] **Step 2: Run the artifact tests and verify RED** |
| 80 | + |
| 81 | +Run: `npm run compile && node --test dist/test/artifacts.test.js` |
| 82 | + |
| 83 | +Expected: the manifest still maps `build.mcpp` to `cpp`, so the new assertions fail. |
| 84 | + |
| 85 | +- [x] **Step 3: Implement the custom language** |
| 86 | + |
| 87 | +Register `mcpp-build` with `filenames: ["build.mcpp"]`, a C++-style language configuration, and a TextMate grammar whose root scope is `source.mcpp-build` and whose patterns include `source.cpp`. Remove only the exact `build.mcpp -> cpp` default; keep `.cppm`, `.ixx`, `.mpp`, and `.ccm` associated with `cpp`. Add `onLanguage:mcpp-build` activation. |
| 88 | + |
| 89 | +- [x] **Step 4: Document the semantic boundary** |
| 90 | + |
| 91 | +Update README wording so `build.mcpp` is described as C++-style syntax highlighting without clangd diagnostics, while real C++ module files continue to use clangd. Explain that semantic support for `import mcpp;` requires a future mcpp-generated host-helper CDB and PCM mapping. |
| 92 | + |
| 93 | +- [x] **Step 5: Run the artifact tests and verify GREEN** |
| 94 | + |
| 95 | +Run: `npm run compile && node --test dist/test/artifacts.test.js` |
| 96 | + |
| 97 | +Expected: all artifact tests pass. |
| 98 | + |
| 99 | +### Task 4: Version, full verification, package, install, and tag |
| 100 | + |
| 101 | +**Files:** |
| 102 | +- Modify: `package.json` |
| 103 | +- Modify: `package-lock.json` |
| 104 | +- Modify: `CHANGELOG.md` |
| 105 | + |
| 106 | +- [x] **Step 1: Bump the extension version** |
| 107 | + |
| 108 | +Run: `npm version 0.2.4 --no-git-tag-version` |
| 109 | + |
| 110 | +Add a `0.2.4` changelog entry covering hermetic query-driver handling, project-source checks, and syntax-only `build.mcpp` handling. |
| 111 | + |
| 112 | +- [x] **Step 2: Run the full regression suite** |
| 113 | + |
| 114 | +Run: `npm test` |
| 115 | + |
| 116 | +Expected: all tests pass with zero failures. |
| 117 | + |
| 118 | +- [x] **Step 3: Reproduce the original UChat clangd symptom** |
| 119 | + |
| 120 | +Run matching clangd 22.1.8 against each UChat `RedisMgr.cpp` using its member CDB and the arguments produced by the fixed policy. Confirm there are no `template_instantiate_undefined`, `ovl_no_viable_function_in_call`, SDK type, or module ODR diagnostics. |
| 121 | + |
| 122 | +- [x] **Step 4: Package and inspect the VSIX** |
| 123 | + |
| 124 | +Run: `npm run package` |
| 125 | + |
| 126 | +Expected: `mcpp-vscode-0.2.4.vsix` is created. Inspect its manifest and archive contents to confirm the new language grammar and configuration are included. |
| 127 | + |
| 128 | +- [x] **Step 5: Commit only the repair files** |
| 129 | + |
| 130 | +Stage the plan, source, focused tests, manifest, lockfile, grammar, README, and changelog files. Do not stage pre-existing modified or untracked design documents. Commit as `fix: preserve hermetic clangd configuration`. |
| 131 | + |
| 132 | +- [x] **Step 6: Create the local release tag** |
| 133 | + |
| 134 | +Create annotated tag `v0.2.4` on the verified repair commit. Do not push it or create a GitHub Release. |
| 135 | + |
| 136 | +- [x] **Step 7: Install and verify the packaged extension** |
| 137 | + |
| 138 | +Run: `code --install-extension /Users/cltx/projects/mcpp/mcpp-vscode/mcpp-vscode-0.2.4.vsix --force` |
| 139 | + |
| 140 | +Then run `code --list-extensions --show-versions` and verify `mcpp-community.mcpp-vscode@0.2.4`. A VS Code window reload is required before the new language registration and clangd arguments take effect. |
0 commit comments