@@ -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' ;
1414import { type LangiumServices } from 'langium/lsp' ;
1515import { DiagnosticSeverity } from 'vscode-languageserver-protocol' ;
1616import { 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