Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows filepaths #626

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jayvee",
"version": "0.6.2",
"version": "0.6.3",
"scripts": {
"nx": "nx",
"format": "nx format:write",
Expand Down
Loading