Skip to content

Commit

Permalink
Replicate logic to get file path like in Langium to fix Windows file …
Browse files Browse the repository at this point in the history
…path issues
  • Loading branch information
georg-schwarz committed Oct 24, 2024
1 parent 7a02683 commit 7ac6a81
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions libs/interpreter-lib/src/parsing-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type JayveeServices,
initializeWorkspace,
} from '@jvalue/jayvee-language-server';
import { type AstNode, type LangiumDocument } from 'langium';
import { type AstNode, type LangiumDocument, UriUtils } from 'langium';
import { type LangiumServices } from 'langium/lsp';
import { DiagnosticSeverity } from 'vscode-languageserver-protocol';
import { URI } from 'vscode-uri';
Expand Down Expand Up @@ -44,9 +44,9 @@ export async function extractDocumentFromFile(
return Promise.reject(ExitCode.FAILURE);
}

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

/**
* Creates the URI for a file path in a way similar to Langium.
* This is necessary to make sure that the document lookup works on Windows.
* Fixed https://github.com/jvalue/jayvee/issues/623.
* Workaround needs to be removed once the issue is fixed in Langium:
* https://github.com/eclipse-langium/langium/issues/1725
*/
function getFileUriLikeLangiumImpl(filePath: string): URI {
const folderPath = path.dirname(filePath);
const folderUri = URI.parse(path.resolve(folderPath));
const fileName = path.basename(filePath);
return UriUtils.joinPath(folderUri, fileName);
}

/**
* Extracts a document from a string that contains a model.
* Does not load an additional working directory.
Expand Down

0 comments on commit 7ac6a81

Please sign in to comment.