Skip to content

Commit a071451

Browse files
committed
fix: VSCode extension fails to resolve imports from npm packages in pnpm workspaces
Fixes #1760 #1627
1 parent f7ccc89 commit a071451

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/schema/src/utils/ast-utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
Mutable,
3131
Reference,
3232
} from 'langium';
33-
import { isAbsolute } from 'node:path';
33+
import path, { isAbsolute } from 'node:path';
3434
import { URI, Utils } from 'vscode-uri';
3535
import { findNodeModulesFile } from './pkg-utils';
3636

@@ -186,7 +186,14 @@ export function resolveImportUri(imp: ModelImport): URI | undefined {
186186
!imp.path.startsWith('.') && // Respect relative paths
187187
!isAbsolute(imp.path) // Respect Absolute paths
188188
) {
189-
imp.path = findNodeModulesFile(imp.path) ?? imp.path;
189+
// use the current model's path as the search context
190+
const contextPath = imp.$container.$document
191+
? path.dirname(imp.$container.$document.uri.fsPath)
192+
: process.cwd();
193+
imp.path = findNodeModulesFile(imp.path, contextPath) ?? imp.path;
194+
if (imp.path) {
195+
console.log('Loaded import from:', imp.path);
196+
}
190197
}
191198

192199
const dirUri = Utils.dirname(getDocument(imp).uri);

0 commit comments

Comments
 (0)