Skip to content

Add CppModulesProject test scenario for C++20 modules groundwork - #14837

Open
soroshsabz wants to merge 9 commits into
microsoft:mainfrom
soroshsabz:feature/cpp-modules-test-scenario
Open

soroshsabz wants to merge 9 commits into
microsoft:mainfrom
soroshsabz:feature/cpp-modules-test-scenario

Conversation

@soroshsabz

@soroshsabz soroshsabz commented Oct 16, 2026 •

Copy link
Copy Markdown

Motivation

IntelliSense support for C++20 modules importing (#6302) is still in development on the language server side. Meanwhile, module-based projects already exercise extension-side behavior that currently has no test coverage:

  • module interface files (.cppm/.ixx) being recognized as C++ sources,
  • compile_commands.json entries containing compiler module flags not preventing IntelliSense,
  • module-related compiler arguments (GCC, Clang and MSVC spellings) surviving the custom configuration provider path unmodified.

This PR adds a CppModulesProject test scenario that locks that behavior in. It makes no statement about the semantic understanding of module imports by the language server — when server-side support lands, these tests are the natural place to add the end-to-end module IntelliSense assertions.

What the tests cover

  1. File classification — .cppm/.ixx files open with the cpp language id (guards the file associations that module files depend on for any IntelliSense at all).

  2. compile_commands.json with module flags, per compiler — a runtime-generated database (with fake gcc/clang++ checked into the scenario assets, following the SimpleCppProject pattern) carries compiler-accurate module flags:

    • GCC importer (main.cpp): -std=c++20 -fmodules-ts (the module flag g++ accepts; GCC does not accept Clang's -fprebuilt-module-path/-fmodule-file spellings)
    • Clang importer (main4.cpp): -std=c++20 -fmodules -fprebuilt-module-path=... -fmodule-file=math=...pcm

    Each importer's entry also carries a sentinel define in the same arguments array as the module flags, and the tests hover over a symbol that is only declared under the corresponding #ifdef: the hover resolves if and only if the database entry (module flags included) was actually applied to the translation unit, rather than IntelliSense falling back to a default configuration.

  3. Custom configuration provider — a v6 provider returns configurations carrying GCC-style (gcc compilerPath + -std=c++20 -fmodules-ts) and MSVC-style (cl compilerPath + /ifcSearchDir, /reference, /headerUnit, /stdIfcDir) module arguments. The sentinel defines travel inside compilerArgs — the same array as the module flags — and the defines field is deliberately empty, so the hover assertions verify that the compilerArgs array itself (module flags included) reaches the language server and takes effect. Dropping or rewriting those arguments can no longer pass the tests.

Notes

  • No product behavior change — tests and CI wiring only.
  • CI: one new Windows step (yarn test --scenario=CppModulesProject) mirroring the existing SimpleCppProject step. Happy to drop it or extend it to other platforms per maintainer preference.
  • Context: the engine-side prerequisite for gcc-dialect modules is progressing in the now-open EDG front end (C++20 modules: support gnu emulation modes and extended floating-point types edgcpp/compiler#315 fixes IFC generation in gnu emulation modes); this scenario is the extension-side acceptance harness for when that support reaches the shipped binaries.

Related: #6302

@soroshsabz
soroshsabz requested a review from a team as a code owner October 16, 2026 16:47
@github-project-automation github-project-automation Bot moved this to Pull Request in cpptools Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not establish compilation-database use or preservation of delivered module arguments.

2 open findings
What changed in this PR

Adds C++20 modules test groundwork for extension-side behavior while semantic module-import support remains under development.

Changes:

  • Adds file-classification, compilation-database, and custom-provider tests.
  • Adds module fixtures and fake compiler assets.
  • Runs the scenario in Windows CI.
File Description
Extension/​test/​scenarios/​CppModulesProject/​tests/​modules.integration.test.ts Adds module scenario tests.
Extension/​test/​scenarios/​CppModulesProject/​assets/​math.ixx Adds geometry module interface.
Extension/​test/​scenarios/​CppModulesProject/​assets/​math.cppm Adds math module interface.
Extension/​test/​scenarios/​CppModulesProject/​assets/​main3.cpp Adds MSVC-provider importer.
Extension/​test/​scenarios/​CppModulesProject/​assets/​main2.cpp Adds GCC-provider importer.
Extension/​test/​scenarios/​CppModulesProject/​assets/​main.cpp Adds compilation-database importer.
Extension/​test/​scenarios/​CppModulesProject/​assets/​bin/​gcc.exe Adds Windows fake compiler.
Extension/​test/​scenarios/​CppModulesProject/​assets/​bin/​gcc Adds non-Windows fake compiler.
Extension/​test/​scenarios/​CppModulesProject/​assets/​.gitignore Ignores generated configuration files.
.github/​workflows/​job-compile-and-test.yml Adds Windows scenario execution.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

const document: vscode.TextDocument = await openAndAwaitIntelliSenseReady(cpptools, disposables, "main2.cpp");
const expected: api.SourceFileConfigurationItem[] = [ { uri: document.uri.toString(), configuration: gccModuleConfig } ];
assert.strictEqual(configurationProvidedBeforeCanProvide, false);
assert.deepStrictEqual(lastResult, expected);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e6d54fe. Two changes:

  1. Delivery is now observed through IntelliSense rather than the provider's own return value: each configuration carries a sentinel define through the provider API's documented defines channel (PROVIDER_GCC_SENTINEL / PROVIDER_MSVC_SENTINEL), and the tests hover over a symbol that is only declared when that define is applied to the translation unit. A dropped or rewritten configuration can no longer pass these tests.
  2. The lastResult comparisons remain, but demoted to an API-handshake check (items were delivered for the requested URIs); the module flags stay in compilerArgs as the payload carried through that path.

One limitation to note: the public test hook (IntelliSenseStatus) only exposes {status, filename} -- there is no channel to inspect the effective translation-unit options -- which is why effect-based sentinels were used instead of asserting the outgoing configuration directly.

Side finding from applying this: defines passed inside compilerArgs (as opposed to the defines field) are not applied for custom provider configurations -- the sentinel placed there failed immediately, while the defines channel works. That is exactly the class of silent argument loss this comment was about.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully addressed in 6e9be58: the lastResult deepEqual comparisons -- which re-used the same configuration objects as the expectations -- are now removed entirely, since as you noted they could not observe what the extension delivers.

What the provider tests assert now:

  1. canProvideConfiguration was invoked before provideConfigurations (the extension initiated the handshake correctly).
  2. Configurations were delivered for the correct file URIs (lastResult.map(item => item.uri)) -- an externally observable handshake check that does not reference the configuration objects.
  3. The delivered configuration took effect on the translation unit: each configuration carries a sentinel define through the provider API's defines channel, and the test hovers over a symbol that is only declared under the corresponding #ifdef. If the extension dropped or rewrote the delivered arguments, or the server did not apply them, the hover does not resolve and the test fails. (Verified by watching this exact failure when the sentinel was placed in compilerArgs -- which the server does not apply for custom provider configurations -- during the previous iteration.)

All 5 scenario tests pass against the shipped 1.35.4 binaries.

@sean-mcmanus Sean McManus (sean-mcmanus) Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨Copilot (devbox3-wsl/agent170): The sentinel checks the separate defines field, not the module flags in compilerArgs. Dropping or rewriting those flags while retaining defines would still satisfy the URI and hover assertions, so this does not yet verify that the GCC/MSVC arguments reach the language server. Could the test independently check the outgoing arguments for each URI, or narrow the stated coverage?

Update for 64ed47fd: the sentinel now checks that a -D//D argument from compilerArgs takes effect, but dropping just -fmodules-ts or /reference while keeping the sentinel would still pass. The provider suite also covers GCC and MSVC, not Clang; its Clang case uses the compilation database. Could the module switches be checked independently and the stated provider coverage corrected, or the claims narrowed to what these tests actually verify?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a63ba3f. The sentinel now travels in compilerArgs -- the same array as the module flags -- and each configuration sets a compilerPath, which turns out to be the key: with a compilerPath present, the server applies defines from compilerArgs (verified experimentally: the identical sentinel placed in compilerArgs without a compilerPath was not applied, while it is applied with one).

So each provider test now verifies:

  1. The handshake (asked before provided; items delivered for the correct URI).
  2. That the compilerArgs array itself -- carrying both the module flags and the sentinel define -- reached the language server and took effect for the translation unit (hover resolves only if the define in that array was applied).

The defines field is now intentionally empty. Dropping or rewriting compilerArgs can no longer pass these tests: there is no other channel through which the sentinel could arrive.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review identified no unresolved blocking issues in the test-only scenario, fixtures, or CI wiring.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The test-only changes follow existing scenario patterns, with no unresolved blocking findings.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@soroshsabz

Copy link
Copy Markdown
Author

Sean McManus (@sean-mcmanus) Is there anything else I can do?

@soroshsabz

soroshsabz commented Oct 29, 2026 •

Copy link
Copy Markdown
Author

As you can see edgcpp/compiler#315 has been merged

So please review this PR, I want to submit another PR for implement required features

@soroshsabz

Copy link
Copy Markdown
Author

@soroshsabz

Copy link
Copy Markdown
Author

Sean McManus (@sean-mcmanus) Could you run CI for this PR?

thanks

@sean-mcmanus

Copy link
Copy Markdown
Contributor

soroshsabz My apologies -- I am and have been super busy recently.

@soroshsabz

soroshsabz commented Nov 12, 2026 •

Copy link
Copy Markdown
Author

Sean McManus (@sean-mcmanus) Ok, I am waiting for you

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The integration tests are vulnerable to request batching and restored-editor timing, and the MSVC fixture uses an invalid header-unit option.

3 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The provider tests may miss lost module flags and race configuration updates, leaving their coverage and reliability in need of human assessment.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@soroshsabz

Copy link
Copy Markdown
Author

Sean McManus (@sean-mcmanus) could you review this PR again? and run CI?

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

3 participants