Skip to content

Add C_Cpp.intelliSenseModuleSearchPath for module import IntelliSense - #14894

Open
soroshsabz wants to merge 3 commits into
microsoft:mainfrom
soroshsabz:feature/modules-e2e
Open

soroshsabz wants to merge 3 commits into
microsoft:mainfrom
soroshsabz:feature/modules-e2e

Conversation

@soroshsabz

@soroshsabz soroshsabz commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Follow-up to #14837 (the CppModulesProject test scenario) and the extension-side part of #6302 (IntelliSense for C++20 modules importing in gcc/clang projects).

Module IntelliSense for gcc/clang-mode projects has been blocked by two things:

  1. Module interface file resolution. The IntelliSense engine (EDG-based, now open source at edgcpp/compiler) understands import directives in every mode, but GCC/Clang toolchains produce their own binary module formats (.gcm, .pcm) which the engine cannot read, and the MSVC-style search-dir compiler arguments are not processed in gcc/clang modes. The engine can, however, read its own .eifc module interface files in every mode, and it searches the directory named by the EDG_MODULES_PATH environment variable (inherited from the extension host by the language server process).
  2. Module interface file production. No compiler or build system emits .eifc files, so even with a search path there was nothing for the engine to find.

This PR adds the extension-side workflow that resolves both, in every IntelliSense mode.

What this PR adds

1. New setting C_Cpp.intelliSenseModuleSearchPath (string, ${workspaceFolder} supported): the directory searched for module interface files when resolving import directives. It is passed to the language server through EDG_MODULES_PATH at server startup (composited with the existing sanitizer-env mechanism; inherited unchanged when unset).

2. New setting C_Cpp.intelliSenseModuleCompilerPath: a C/C++ front end command that compiles the workspace's module interface units (.cppm/.ixx/.ccm) into .eifc module interface files, so import resolution works without any manual per-module setup. Build the command from the open-source EDG front end (edgcpp/compiler; gnu emulation mode interfaces are supported since edgcpp/compiler#315). The extension:

  • finds the module interface units of the workspace,
  • (re)compiles the ones whose .eifc file is missing or older than the source (sequentially, per-file timeout, output logged to the C/C++ output channel),
  • writes the generated files into the module search path directory (C_Cpp.intelliSenseModuleSearchPath when set, otherwise a per-workspace cache directory under the extension's default cache root),
  • points the engine's EDG_MODULES_PATH at that directory.

This replaces the closed-source-only workflow with an open one: the module interface files that IntelliSense consumes are produced by the same open-source front end that anyone can build and audit.

3. Tests:

  • Unit tests for the settings→environment resolution and the target directory selection (7 tests), and for the module interface compilation orchestration — interface file detection, module name parsing (including partitions), standard mapping, and regeneration staleness (19 tests).
  • An end-to-end scenario test in CppModulesProject (running first, before the language server starts): with a module interface compiler configured (a test fake that produces the checked-in .eifc files) and the search path set, the test asserts that the generated files appear in the target directory and that import math; / import geometry; resolve in gcc mode — hovering over an imported function and over a variable exported from inside a namespace works, and the "could not find module file" diagnostics are gone. The .eifc fixtures were produced with the open-source EDG front end. The test dynamically skips its semantic assertions (with a console warning) if a future language server build can no longer read the checked-in fixtures, so module file format churn cannot turn CI red.

Validation

  • 7/7 CppModulesProject scenario tests pass against the shipped 1.36.0 binaries, including the new end-to-end test with semantic assertions on both function and variable imports.
  • 182/182 unit tests pass; TypeScript and ESLint clean.
  • The exported-variable import used by the test's namespace assertion required an engine fix: exported variables were silently dropped from module interface files (edgcpp/compiler#58). That fix is proposed in C++20 modules: write exported variables to IFC files [GH #58] edgcpp/compiler#631; the checked-in fixtures are generated with that fix.

Notes

Related: #6302, #14837, edgcpp/compiler#315, edgcpp/compiler#631

@soroshsabz

Copy link
Copy Markdown
Contributor Author

Sean McManus (@sean-mcmanus) can you please review this PR?

thanks :)

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 compiler timeout kills only the direct child, so a descendant retaining stdout/stderr can leave generation unresolved and block IntelliSense startup indefinitely. Separately, generation can fail when dependencies have not yet been compiled, while missing change-triggered regeneration and dependency-aware cache invalidation can leave module outputs missing or stale.

10 open issues
What changed in this PR

Adds extension-side support for C++ module imports by generating EDG module interface files and configuring the language server’s search directory.

Changes:

  • Adds module compiler and search-path settings.
  • Generates missing or outdated .eifc files before server startup.
  • Adds unit tests and a fixture-backed module-import scenario.
File Description
Extension/​package.json Registers both settings.
Extension/​package.nls.json Documents settings and reload requirements.
Extension/​src/​LanguageServer/​settings.ts Exposes setting getters.
Extension/​src/​LanguageServer/​moduleSearchPath.ts Resolves search paths and cache directories.
Extension/​src/​LanguageServer/​moduleInterfaceCompiler.ts Implements module-file generation.
Extension/​src/​LanguageServer/​client.ts Connects generation and server environment setup.
Extension/​test/​unit/​moduleSearchPath.test.ts Tests path and environment helpers.
Extension/​test/​unit/​moduleInterfaceCompiler.test.ts Tests parsing, standards, and freshness checks.
Extension/​test/​scenarios/​CppModulesProject/​tests/​modules.integration.test.ts Exercises generation and imported-symbol resolution.
Extension/​test/​scenarios/​CppModulesProject/​assets/​.gitignore Ignores generated module files.

Review effort: Balanced

Comment on lines +185 to +188
const timer: NodeJS.Timeout = setTimeout(() => {
output += "\n(timeout)";
child.kill();
}, compileTimeoutMs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b1e8c2a: Bound compiler timeouts when descendants keep pipes open** (moduleInterfaceCompiler.ts:188)
Addressed: invokeCompiler now kills the whole process tree on timeout (taskkill /pid /T /F on Windows, process-group SIGKILL on other platforms — the compiler is spawned detached for that purpose), destroys the stdout/stderr streams, and settles the invocation on a bounded deadline (2s grace period after the kill) rather than relying solely on close. A hung descendant can no longer block IntelliSense startup.

Comment on lines +1665 to +1668
const settings: CppSettings = new CppSettings(this.RootUri);
let moduleSearchPathEnv: NodeJS.ProcessEnv | undefined;
if (settings.intelliSenseModuleCompilerPath) {
const targetDir: string | undefined = getModuleFilesTargetDir(settings.intelliSenseModuleSearchPath, this.RootPath);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b1e8c2a: Honor and isolate each workspace folder's settings** (client.ts:1668)
Addressed: the settings are now documented as applying to the folder that starts the (shared) language server — the setting descriptions state this explicitly for multi-root workspaces — and module interface discovery is scoped to that folder's root (findModuleInterfaceFiles uses a RelativePattern rooted at the client's root path), so a later folder's sources are never compiled with a foreign compiler. (The language server process is shared across folders by design, so a per-folder environment is not possible for the EDG_MODULES_PATH variable; the settings of the starting folder are the ones that take effect, which is now documented.)

Comment thread Extension/src/LanguageServer/client.ts Outdated
const out: Logger = getOutputChannelLogger();
try {
const interfaceFiles: string[] = await findModuleInterfaceFiles();
await generateModuleFiles(settings.intelliSenseModuleCompilerPath, interfaceFiles, targetDir,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b1e8c2a: Expand workspace variables in the compiler path** (client.ts:1673)
Addressed: expandWorkspaceFolder now expands ${workspaceFolder} in the compiler path (and in each argument of the new C_Cpp.intelliSenseModuleCompilerArgs setting) against the client's root path before spawning.

Comment thread Extension/src/LanguageServer/client.ts Outdated
Comment on lines +1672 to +1674
const interfaceFiles: string[] = await findModuleInterfaceFiles();
await generateModuleFiles(settings.intelliSenseModuleCompilerPath, interfaceFiles, targetDir,
settings.defaultCppStandard, (message: string) => out.appendLine(message));
Comment on lines +67 to +70
case "c++23":
return ["--c++23"];
case "c++26":
return ["--c++26"];
fs.promises.stat(interfaceFilePath),
fs.promises.stat(moduleFile)
]);
return moduleFileStat.mtimeMs < sourceStat.mtimeMs;

const result: ModuleFileGenerationResult = { generated: [], skipped: [], failed: [] };
await fs.promises.mkdir(targetDir, { recursive: true });
const compilerArgs: string[] = [...getEdgStandardArgs(cppStandard), "--modules", "--module_interface"];
await fs.promises.mkdir(targetDir, { recursive: true });
const compilerArgs: string[] = [...getEdgStandardArgs(cppStandard), "--modules", "--module_interface"];

for (const interfaceFilePath of interfaceFilePaths) {
Comment on lines +49 to +50
resolved = resolved.trim();
return resolved ? resolved : undefined;
await testHelpers.delay(5000);
const diagnostics: vscode.Diagnostic[] = vscode.languages.getDiagnostics(document.uri);
const moduleFileErrors: vscode.Diagnostic[] = diagnostics.filter(d => d.message.includes("could not find module file"));
if (moduleFileErrors.length > 0) {
…ency-aware staleness, retry passes, gnu++ standards, relative paths, and test hardening
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.

2 participants