vscode-cmake-tools
Copilot instructions1.7k starsChanged 7 months agoMITView on GitHub
You are an expert contributor to microsoft/vscode-cmake-tools, a TypeScript VS Code extension targeting Windows, macOS, and Linux. You are deeply familiar with CMake, CMake Presets, CTest, CPack, generator types (Ninja, Ninja Multi-Config, Visual Studio, Unix Makefiles), kit/toolchain selection, the VS Code extension API, and this repo's architecture. Match existing patterns precisely and always prefer tracing the canonical data flow over guessing or grepping.
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about microsoft/vscode-cmake-tools
- clangd/vscode-clangd“support commands in settings”GitHub · Jun 27, 2020 · 17 reactions
- fredericbonnet/cmake-test-explorer“trigger BuildBeforeRun also by running a test in the testexplorer”GitHub · Mar 12, 2021 · 8 reactions
- twxs/vs.language.cmake“CMake Tools Extension & twxs.cmake extension”GitHub · Jan 29, 2024 · 5 reactions
- disroop/vs-code-conan“configuration provider for cpptools / IntelliSense”GitHub · Jan 14, 2021 · 3 reactions
- microsoft/vscode-cmake-tools-api“Update APIs”GitHub · Aug 1, 2025 · 2 reactions
The biggest 5 of 14 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 14
Talked about on GitHub (14 times).
On GitHub · 14
- Jun 27, 2020support commands in settings — clangd/vscode-clangd17 reactions · 8 comments
- Mar 12, 2021trigger BuildBeforeRun also by running a test in the testexplorer — fredericbonnet/cmake-test-explorer8 reactions
- Jan 29, 2024CMake Tools Extension & twxs.cmake extension — twxs/vs.language.cmake5 reactions · 1 comment
- Jan 14, 2021configuration provider for cpptools / IntelliSense — disroop/vs-code-conan3 reactions · 5 comments
- Aug 1, 2025Update APIs — microsoft/vscode-cmake-tools-api2 reactions · 4 comments
9 more on GitHub
- Nov 15, 2024Add C++26 support (setting values only) — microsoft/vscode-cpptools2 reactions · 3 comments
- Oct 25, 2024cmake-kits.json incorrect CXX compiler — raspberrypi/pico-vscode2 reactions · 3 comments
- Oct 24, 2024Add support for `${command:<name-of-command>}` in c_cpp_properties.json — microsoft/vscode-cpptools2 reactions · 7 comments
- Feb 28, 2022Add support for resolving commands — microsoft/vscode-cpptools2 reactions · 4 comments
- Jun 19, 2025Cleanup standard version handling. — microsoft/vscode-makefile-tools1 reaction
- Mar 5, 2025Pixi builds / VSCode / CMake issues and differences — FreeCAD/FreeCAD1 reaction · 15 comments
- Jan 31, 2025Feature request: Improved variable and command substitution for build directories setting — JacquesLucke/gcov-viewer1 reaction
- Sep 26, 2024Replace CMake grammar — github-linguist/linguist1 reaction
- Sep 16, 2024Newest macos-latest environment update not working for VS Code tests — actions/runner-images1 reaction · 2 comments
In this repository7 other files it gives its agents.
- add-commandSkill
- add-diagnostic-parserSkill
- add-settingSkill
- backend-testsSkill
- presets-vs-kitsSkill
- pr-readinessSkill
- validation-projectSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
18 rules. About 0 are common, 1 is distinctive, and 17 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
17
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Error reporting: Use rollbar wrappers for top-level error boundaries around event handlers, never bare try/catch that silently swallows.
- Very specific: line 26
Telemetry: Use helpers in src/telemetry.ts (logEvent).
- Very specific: line 66
Use ConfigurationReader.onChange() for typed, per-setting change notifications:
- Very specific: line 75
Do not use vscode.workspace.onDidChangeConfiguration directly — the onChange() API is type-safe, fires only for the specific setting, and …
- Very specific: line 97
Call util.isMultiConfGeneratorFast(generator) before any build-type logic.
- Very specific: line 101
Every file with user-visible text needs the vscode-nls boilerplate:
- Very specific: line 117
Update package.nls.json for English strings — never modify files under i18n/ (translations are updated separately).
- Very specific: line 118
When a setting uses markdownDescription in package.json, the NLS key suffix must be .markdownDescription, not .description.
- Very specific: line 129
Prefer async/await over .then() chains and never use empty catch blocks.
- Very specific: line 133
Never concatenate path strings with / or \\.
- Very specific: line 141
Every setting in contributes.configuration must have an explicit scope:
- Very specific: line 153
Create src/diagnostics/<name>.ts — extend RawDiagnosticParser, implement handleLine()
- Very specific: line 154
Add an instance to the Compilers class in src/diagnostics/build.ts
- Very specific: line 155
Add the parser name to cmake.enabledOutputParsers enum array and default array in package.json
- Very specific: line 156
Add English strings to package.nls.json if descriptions change
- Distinctive: line 166
If git status shows these as modified, run git checkout -- .npmrc yarn.lock before committing
- Very specific: line 187
If the module has no transitive vscode dependency (e.g., encodingUtils, cmakeValue) → import directly via @cmt/*
- Very specific: line 188
If the module transitively imports vscode and the mock is insufficient → mirror the pure function logic inline in the test file.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CMake Tools — Contributor Instructions
Domain knowledge
- Two operating modes: presets mode (
CMakePresets.json/CMakeUserPresets.json) vs. kits/variants mode. Many bugs affect only one. Always checkCMakeProject.useCMakePresetsand handle both unless explicitly justified. - Kits: Define compiler, optional toolchain file, optional Visual Studio installation, and environment. On Windows, MSVC kits require VS Developer Environment (
vcvarsall.bat) merged viagetEffectiveSubprocessEnvironment()incmakeDriver.ts. - Generators: Single-config (Ninja, Unix Makefiles) use
CMAKE_BUILD_TYPEat configure time. Multi-config (Ninja Multi-Config, Visual Studio) use--configat build time. Never assume single-config. - Presets:
CMakePresets.jsonis project-owned (committed).CMakeUserPresets.jsonis user-owned (gitignored). Both supportincludechaining. The merged tree lives inPresetsController— never re-parse preset files directly. Types live insrc/presets/preset.ts. - CTest / CPack / Workflow: Separate drivers —
CTestDriver(src/ctest.ts),CPackDriver(src/cpack.ts), andWorkflowDriver(src/workflow.ts) — each with their own preset type. - Code model: The CMake file-API produces
CodeModelContent(defined insrc/drivers/codeModel.ts) after configure — the authoritative source for targets, file groups, and toolchains. Never infer targets fromCMakeLists.txt. - Variable expansion:
src/expand.tshandles${variable}expansion for both kit-context and preset-context vars. Changes here need unit tests. - Cross-platform: Runs on Windows, macOS, Linux. Path separators, env var casing, compiler locations, and generator availability all differ.
Project conventions
- Path alias:
@cmt/*maps tosrc/*(seetsconfig.json). Always useimport foo from '@cmt/foo'— never relative paths from outsidesrc/.@test/*maps totest/*(defined in bothtsconfig.jsonandtest.tsconfig.json). Useimport ... from '@test/...'in test files. - Error reporting: Use
rollbarwrappers for top-level error boundaries around event handlers, never baretry/catchthat silently swallows.rollbar.invoke(what, fn)— wraps synchronous code; catches, logs, and re-throws.rollbar.invokeAsync(what, fn)— wraps async function execution; catches promise rejections.rollbar.takePromise(what, additional, thenable)— attaches an error handler to an already-created Thenable (e.g., a return value from a VS Code API call). Use this when you have a promise but didn't create it viainvokeAsync.
- Telemetry: Use helpers in
src/telemetry.ts(logEvent). Never call the VS Code telemetry API directly.
Architecture
| Layer | Primary files | Responsibility |
| CMake driver | src/drivers/cmakeDriver.ts (base), cmakeFileApiDriver.ts, cmakeLegacyDriver.ts, cmakeServerDriver.ts | Spawning CMake, file-API replies, code model, cache, targets. cmakeFileApiDriver is the modern default. |
| CMake project | src/cmakeProject.ts | Per-folder state: kit/preset, configure/build/test lifecycle |
| Build runner | src/cmakeBuildRunner.ts | Build-process orchestration and output streaming |
| Task provider | src/cmakeTaskProvider.ts | VS Code task integration (tasks.json "cmake" type) |
| Project controller | src/projectController.ts | Multi-folder workspace, active-project routing |
| Presets | src/presets/presetsController.ts, presetsParser.ts, preset.ts | Loading, merging, expanding, watching preset files; type definitions |
| Kits | src/kits/kitsController.ts, src/kits/kit.ts, src/kits/variant.ts | Compiler scanning, toolchain environment, VS kit detection, variant handling |
| Extension entry | src/extension.ts | Activation, command registration, wiring all layers |
| UI / tree views | src/ui/ (projectStatus.ts, projectOutline/, cacheView.ts, pinnedCommands.ts) | Sidebar views, status bar, context menus |
| Diagnostics | src/diagnostics/ (cmake.ts, build.ts, gcc.ts, msvc.ts, gnu-ld.ts, etc.) | Output parsing, log-level routing, problem matchers — one file per compiler family |
| CMake debugger | src/debug/cmakeDebugger/ | Debug adapter for CMake script/configure debugging |
| Language services | src/languageServices/ | CMake-language hover, completion, validation |
| Config | src/config.ts | ConfigurationReader — canonical access to all extension settings |
| Tests | test/unit-tests/, test/integration-tests/, test/end-to-end-tests/, test/smoke/ | Mocha suites at four levels of granularity |
Mandatory rules — apply to every task
Before touching any code, orient first
Identify the affected layer(s) from the architecture table above. Read the relevant files before writing anything. Never guess at call sites, data flow, or configuration keys.
Use canonical data paths — never ad-hoc reads or grep
| Need | Use — not grep or direct file reads |
| Targets / target types | CMakeProject.targets, .executableTargets, or codeModelContent |
| Active preset | CMakeProject.configurePreset / .buildPreset / .testPreset / .packagePreset / .workflowPreset |
| Active kit | CMakeProject.activeKit |
| Merged preset list | PresetsController |
| Cache entries | CMakeDriver.cmakeCacheEntries |
| Extension settings | ConfigurationReader (src/config.ts) — never vscode.workspace.getConfiguration() directly |
Reactive configuration subscriptions
Use ConfigurationReader.onChange() for typed, per-setting change notifications:
const disposable = config.onChange('settingName', (newValue) => {
// Respond to change
});
// Store disposable in a field or push to a disposables array for cleanupDo not use vscode.workspace.onDidChangeConfiguration directly — the onChange() API is type-safe, fires only for the specific setting, and integrates with the extension's promise tracking.
Always handle both operating modes
When a code path touches shared logic (configure, build, test, targets, environment), check CMakeProject.useCMakePresets and ensure it works correctly in both presets mode and kits/variants mode. Omitting the check for one mode in shared code is a bug waiting to happen. Features that are inherently mode-specific (e.g., kit scanning, preset expansion) are fine to scope to one mode.
SpecialKits sentinel values
Kit names may be sentinel values, not real compiler paths. Always check before treating kit.name as a file path:
SpecialKits.Unspecified('__unspec__') — no kit selectedSpecialKits.ScanForKits('__scanforkits__') — triggers kit scanningSpecialKits.ScanSpecificDir('__scan_specific_dir__') — scan a specific directory
Kit trust model
Kits have an isTrusted: boolean property. Auto-scanned kits from untrusted paths are filtered out before selection and use. This prevents untrusted kits from executing environmentSetupScript. Do not bypass this trust filtering when adding kit-related code.
Always handle both generator types
Single-config uses CMAKE_BUILD_TYPE; multi-config uses --config at build time. Check the active generator before any build-type logic.
Call util.isMultiConfGeneratorFast(generator) before any build-type logic. Multi-config generators include Visual Studio, Xcode, and Ninja Multi-Config. Note: the cmake.setBuildTypeOnMultiConfig setting can override multi-config behavior — check it before assuming.
Localize all user-visible strings
Every file with user-visible text needs the vscode-nls boilerplate:
import * as nls from 'vscode-nls';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
// ✅ localize('my.message.key', 'Human-readable message')
// ❌ bare strings in user-visible outputNLS key naming and package.nls.json
Settings: cmake-tools.configuration.cmake.<settingName>.description (or .markdownDescription)
Commands: cmake-tools.command.cmake.<commandName>.title
- Update
package.nls.jsonfor English strings — never modify files underi18n/(translations are updated separately). - When a setting uses
markdownDescriptioninpackage.json, the NLS key suffix must be.markdownDescription, not.description.
Use the module-scoped logger — never console.log
import * as logging from '@cmt/logging';
const log = logging.createLogger('my-module');async/await — never swallow errors
Prefer async/await over .then() chains and never use empty catch blocks. Wrap top-level event handlers in rollbar.invokeAsync(). Exception: fire-and-forget UI calls (e.g., vscode.window.showInformationMessage(...).then(...)) where .then() is idiomatic.
Paths — always path.join() / path.normalize()
Never concatenate path strings with / or \\. No exceptions.
New or changed settings: update all three locations
package.json (contributes.configuration), src/config.ts (ConfigurationReader), and docs/cmake-settings.md.
Setting scope in package.json
Every setting in contributes.configuration must have an explicit scope:
"resource"— per-folder; use for anything CMake project-specific (paths, build args, generator, environment)."window"— global; use for extension-wide UI/behavior settings.
Examples: cmake.buildDirectory → "resource" (project-specific path), cmake.autoSelectActiveFolder → "window" (global UI behavior).
Every PR needs a CHANGELOG entry
One entry under the current version in CHANGELOG.md, in the appropriate section (Features:, Improvements:, or Bug Fixes:), describing user-visible behavior in the repo's existing tense and category style.
Adding a new diagnostic parser
- Create
src/diagnostics/<name>.ts— extendRawDiagnosticParser, implementhandleLine() - Add an instance to the
Compilersclass insrc/diagnostics/build.ts - Add the parser name to
cmake.enabledOutputParsersenum array and default array inpackage.json - Add English strings to
package.nls.jsonif descriptions change
Currently registered: gcc, gnuld, ghs, diab, msvc, iar, iwyu. Default-enabled: cmake, gcc, gnuld, msvc, ghs, diab.
Copilot CI environment (agent-only)
This section applies to the Copilot coding agent, not human contributors.
In the Copilot agent CI environment, .npmrc is renamed to .npmrc.bak and yarn.lock registry URLs are patched to use the public npm registry. These are environment artifacts:
- Never commit
.npmrc.bakor the patchedyarn.lock - If
git statusshows these as modified, rungit checkout -- .npmrc yarn.lockbefore committing
Testing checklist
yarn unitTestspasses- If
src/diagnostics/,src/presets/, orsrc/expand.tschanged — affected unit tests updated - If
src/kits/changed — updatetest/unit-tests/kitmanager.test.ts - Behavior verified in presets mode and kits/variants mode
- Behavior verified with single-config and multi-config generators
- Windows/macOS/Linux differences considered (paths, env vars, MSVC toolchain, generator availability)
Backend tests (yarn backendTests)
The fastest feedback loop — runs via Mocha with no VS Code instance or display required.
- Files go in
test/unit-tests/backend/<name>.test.ts - Framework: Mocha TDD (
suite/test), Chaiexpectassertions - Run:
yarn backendTests - Mock setup:
test/unit-tests/backend/setup-vscode-mock.tsprovides minimalvscodestubs
Import strategy:
- If the module has no transitive
vscodedependency (e.g.,encodingUtils,cmakeValue) → import directly via@cmt/* - If the module transitively imports
vscodeand the mock is insufficient → mirror the pure function logic inline in the test file. This is the established pattern inexpand.test.ts,targetMap.test.ts,shell-propagation.test.ts. - Heuristic: Try
@cmt/*import first. If it fails due to vscode dependency at runtime, fall back to mirroring.
Where to start
- Configure/build/test behavior →
src/cmakeProject.ts+src/drivers/ - Build output / streaming →
src/cmakeBuildRunner.ts - Task provider (
tasks.json) →src/cmakeTaskProvider.ts - Preset loading or resolution →
src/presets/presetsController.ts+presetsParser.ts - Preset types / interfaces →
src/presets/preset.ts - Kit detection or environment →
src/kits/kitsController.ts+kit.ts - Variant handling →
src/kits/variant.ts - Variable expansion →
src/expand.ts - Command does nothing or crashes →
src/extension.tshandler registration - Sidebar item or context menu →
src/ui/nodecontextValue+package.jsonwhenclauses - Output panel text or log level →
src/diagnostics/cmake.ts(CMakeOutputConsumer) - Compiler-specific diagnostics →
src/diagnostics/gcc.ts,msvc.ts,gnu-ld.ts, etc. - Setting ignored or wrong source →
src/config.ts+package.jsoncontributes.configuration - Preset file change not detected →
src/presets/presetsController.tsfile watcher - CMake debugger →
src/debug/cmakeDebugger/
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

