Repository navigation
Add C_Cpp.intelliSenseModuleSearchPath for module import IntelliSense - #14894
soroshsabz wants to merge 3 commits into
Conversation
|
Sean McManus (@sean-mcmanus) can you please review this PR? thanks :) |
There was a problem hiding this comment.
🟡 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
Bound compiler timeouts when descendants keep pipes open · New Honor and isolate each workspace folder's settings · New Expand workspace variables in the compiler path · New Regenerate modules when interfaces change · New Map GNU C++23 and C++26 standards correctly · New Invalidate cached exports when dependencies change · New Pass effective preprocessing settings to the compiler · New Compile dependencies before importing modules · New Resolve the module output path consistently · New Do not skip unverified missing-module diagnostics · New
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
.eifcfiles 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
| const timer: NodeJS.Timeout = setTimeout(() => { | ||
| output += "\n(timeout)"; | ||
| child.kill(); | ||
| }, compileTimeoutMs); |
There was a problem hiding this comment.
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.
| const settings: CppSettings = new CppSettings(this.RootUri); | ||
| let moduleSearchPathEnv: NodeJS.ProcessEnv | undefined; | ||
| if (settings.intelliSenseModuleCompilerPath) { | ||
| const targetDir: string | undefined = getModuleFilesTargetDir(settings.intelliSenseModuleSearchPath, this.RootPath); |
There was a problem hiding this comment.
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.)
| const out: Logger = getOutputChannelLogger(); | ||
| try { | ||
| const interfaceFiles: string[] = await findModuleInterfaceFiles(); | ||
| await generateModuleFiles(settings.intelliSenseModuleCompilerPath, interfaceFiles, targetDir, |
There was a problem hiding this comment.
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.
| const interfaceFiles: string[] = await findModuleInterfaceFiles(); | ||
| await generateModuleFiles(settings.intelliSenseModuleCompilerPath, interfaceFiles, targetDir, | ||
| settings.defaultCppStandard, (message: string) => out.appendLine(message)); |
| 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) { |
| 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


Motivation
Follow-up to #14837 (the
CppModulesProjecttest 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:
importdirectives 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.eifcmodule interface files in every mode, and it searches the directory named by theEDG_MODULES_PATHenvironment variable (inherited from the extension host by the language server process)..eifcfiles, 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 resolvingimportdirectives. It is passed to the language server throughEDG_MODULES_PATHat 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.eifcmodule interface files, soimportresolution 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:.eifcfile is missing or older than the source (sequentially, per-file timeout, output logged to the C/C++ output channel),C_Cpp.intelliSenseModuleSearchPathwhen set, otherwise a per-workspace cache directory under the extension's default cache root),EDG_MODULES_PATHat 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:
CppModulesProject(running first, before the language server starts): with a module interface compiler configured (a test fake that produces the checked-in.eifcfiles) and the search path set, the test asserts that the generated files appear in the target directory and thatimport 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.eifcfixtures 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
CppModulesProjectscenario 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.Notes
import std;, variable templates, static data members) are tracked in the EDG IFC tracking issues ([GNATS 28269] [EDG IFC] Macros edgcpp/compiler#59, Clang/LLDB support #60, IntelliSense does not work on Win10 #61, Completion options at wrong places #70, libc includes not found in vs code #73, if define MACRO, c++ Syntax colorization and highlighting is error #74, Allow breakpoints in other native languages source files #75, How can i attach to a remote C++ application? #78, Enhance symbol indexing #355); this PR's mechanisms are independent of them and already usable for named-module projects.Related: #6302, #14837, edgcpp/compiler#315, edgcpp/compiler#631