Skip to content

Commit d83b7ee

Browse files
authored
fix: VSCode extension fails to resolve imports from npm packages in pnpm workspaces (#1779)
1 parent f7ccc89 commit d83b7ee

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 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 from 'node:path';
3434
import { URI, Utils } from 'vscode-uri';
3535
import { findNodeModulesFile } from './pkg-utils';
3636

@@ -184,9 +184,16 @@ export function resolveImportUri(imp: ModelImport): URI | undefined {
184184

185185
if (
186186
!imp.path.startsWith('.') && // Respect relative paths
187-
!isAbsolute(imp.path) // Respect Absolute paths
187+
!path.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)