Skip to content

Commit 7ac6a81

Browse files
committed
Replicate logic to get file path like in Langium to fix Windows file path issues
1 parent 7a02683 commit 7ac6a81

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

libs/interpreter-lib/src/parsing-util.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type JayveeServices,
1111
initializeWorkspace,
1212
} from '@jvalue/jayvee-language-server';
13-
import { type AstNode, type LangiumDocument } from 'langium';
13+
import { type AstNode, type LangiumDocument, UriUtils } from 'langium';
1414
import { type LangiumServices } from 'langium/lsp';
1515
import { DiagnosticSeverity } from 'vscode-languageserver-protocol';
1616
import { URI } from 'vscode-uri';
@@ -44,9 +44,9 @@ export async function extractDocumentFromFile(
4444
return Promise.reject(ExitCode.FAILURE);
4545
}
4646

47-
const document = services.shared.workspace.LangiumDocuments.getDocument(
48-
URI.file(path.resolve(filePath)),
49-
);
47+
const fileUri = getFileUriLikeLangiumImpl(filePath);
48+
const document =
49+
services.shared.workspace.LangiumDocuments.getDocument(fileUri);
5050
if (document === undefined) {
5151
logger.logErr(`Did not load file ${filePath} correctly.`);
5252
return Promise.reject(ExitCode.FAILURE);
@@ -55,6 +55,20 @@ export async function extractDocumentFromFile(
5555
return await validateDocument(document, services, logger);
5656
}
5757

58+
/**
59+
* Creates the URI for a file path in a way similar to Langium.
60+
* This is necessary to make sure that the document lookup works on Windows.
61+
* Fixed https://github.com/jvalue/jayvee/issues/623.
62+
* Workaround needs to be removed once the issue is fixed in Langium:
63+
* https://github.com/eclipse-langium/langium/issues/1725
64+
*/
65+
function getFileUriLikeLangiumImpl(filePath: string): URI {
66+
const folderPath = path.dirname(filePath);
67+
const folderUri = URI.parse(path.resolve(folderPath));
68+
const fileName = path.basename(filePath);
69+
return UriUtils.joinPath(folderUri, fileName);
70+
}
71+
5872
/**
5973
* Extracts a document from a string that contains a model.
6074
* Does not load an additional working directory.

0 commit comments

Comments
 (0)