Skip to content

0.24.0: std's command follows the build, not an edit buffer, and an open file a build rule transforms is a shadowed source that formats (#95) - #96

Merged
Sunrisepeak merged 4 commits into
mainfrom
fix/issue-95-std-and-shadowed-sources
Nov 22, 2026
Merged

Sunrisepeak merged 4 commits into
mainfrom
fix/issue-95-std-and-shadowed-sources

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Owner

Fixes #95. Design: .agents/docs/2026-11-22-issue-95-std-command-stability-and-shadowed-sources-design.md (§8 the plan and its dependencies, §10 what implementing it found).

What was wrong

  1. The restart loop. std is built with the arguments of one representative unit. It was the first unit that imported std and was not an interface, and the edit buffer counted. In a package whose build programs share the targets' toolchain and import std, typing import std; into main.cpp made main.cpp the representative. Saving without it moved std to a build program's unit, whose command differs, and clangd restarted each time.
  2. degraded + Format Document doing nothing. HuxerUI's hcg generates the compiled unit from src/app.cppm, and [build] sources = []. The open original was planned as a second provider of app, so it became ambiguous-module, was left out, and no formatter was asked.

What changes (server only; no engine or mcpp change)

  • S1: std's representative is chosen by set first: target sets before build-program sets, then a set that imports std as the build database states it (never the buffer). Within that set it is the first non-interface unit. S3: the plan records the choice (plan.stdFollows), and the plan diff logs std follows … now (was …).
  • G0: the server reads ide.generated (S1 §7.2), writes it back (the model cache keeps it), and reads the authored source of a generated unit from it: a stated origin (emit build-database: a generated source does not say which authored file it is a transformed copy of (S1 ide.generated names it only among inputs) mcpp-community/mcpp#1004), else the single C++ input of the generating step.
  • G1: an open file no set describes, providing a module the build provides, is a shadowed source. It is a notice plus an information diagnostic (generated-from with the step, or outside-build), not an issue, and the state stays ready.
  • G2b: a file the plan leaves out is formatted by clangd under a scratch name beside it (<name>.mcppls-format<ext>, didOpen → format → didClose). Everything clangd says about that URI is dropped. G2a: files clangd set aside keep the empty answer, and a not-formatted notice and log line say why.
  • Version: series 0.24.0. CHANGELOG, troubleshooting (en and zh-CN), S3 notice codes and the spec changelog are updated.
  • Left for later: S2 (std without the project's -I) waits for experiments E2/E3 (design §7.5).

Evidence

  • mcpp-std-representative (new conformance fixture, real mcpp emit build-database, the reported shape): removing and restoring import std; in main.cpp. 0.23.0 restarts clangd twice ("units are compiled with other arguments (std.compat.cppm)"), this branch never. Run locally on linux-x64 with mcpp 2026.11.20.1.
  • shadowed-source (new, mock mcpp, the hcg shape): state ready, no ambiguous-module, the shadowed-source diagnostic, and Format Document equal to the golden file with the fixture's .clang-format, through the scratch document.
  • Unit cases: the S1 set/unit choice, including the reporter's order, which fails on 0.23.0's ranking; G1 for generated-from, outside-build and the real two-provider ambiguity; G0 parse, round-trip and origin/inputs.
  • E1 (design §10.4): clangd 23.1.0-mcppls.12 answers formatting for a just-opened scratch module unit in 1 ms, with the parent .clang-format.
  • Locally: mcpp test 630/630; devtools check all; validate.py; fixtures mcpp-build-programs, generated-module, format-explicit, mcpp-split unchanged.

…pen file a build rule transforms is a shadowed source that formats (#95)

clangd restarted, and every module was prepared again, each time `import std` came into
main.cpp or left it. std is built with the arguments of one representative unit: the first
that imported std and was no interface, read from the edit buffer too. In a package whose
build programs share the targets' toolchain and import std, typing the import made main.cpp
the representative and saving without it moved std to a build program's unit, whose command
differs (-I, -g, warnings). The representative is now chosen by set, then by unit, from what
the build describes: the targets' sets before the build programs', a set that imports std as
the build database states it before one that does not; in the set, its first unit that is no
interface. The plan names it (plan.stdFollows) and the plan diff says when it moves. The
mcpp-std-representative fixture drives the reported shape with mcpp's own build database:
0.23.0 restarts clangd at each save, this never.

With `[build] sources = []` and a rule that generates the compiled unit from the file being
edited (HuxerUI's hcg), the open original declared the module the generated copy provides: it
was an ambiguous-module, the workspace degraded, and formatting answered nothing. The server
now reads ide.generated (S1 7.2), and an open file no set describes that provides a module
the build provides is a shadowed source: a notice and an information diagnostic naming the
unit standing for it (generated-from, with the step, or outside-build), not an issue. A file
the plan leaves out is formatted by clangd under a scratch name beside it, opened for the
one request; what clangd says about that name is dropped. Files clangd set aside keep an
empty answer, and the log and a not-formatted notice say why.

Design: .agents/docs/2026-11-22-issue-95-std-command-stability-and-shadowed-sources-design.md
@Sunrisepeak
Sunrisepeak force-pushed the fix/issue-95-std-and-shadowed-sources branch from a8bedb5 to 8304ca1 Compare November 22, 2026 15:37
@Sunrisepeak
Sunrisepeak merged commit 6eb2438 into main Nov 22, 2026
168 of 170 checks passed
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.

Engine restart loop on std.compat.ixx argument differences leaves workspace degraded; Format Document no-op for hcg-generated source

1 participant