From 8f02ff42863ba12381de66e0975a61b1bd159673 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Tue, 31 Jan 2023 12:50:21 +1100 Subject: [PATCH] fix cross platform test --- languageServer/src/LanguageServer.ts | 4 +++- languageServer/src/test/definitions.test.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/languageServer/src/LanguageServer.ts b/languageServer/src/LanguageServer.ts index 6c0cc4dcd5..918b80ef2a 100644 --- a/languageServer/src/LanguageServer.ts +++ b/languageServer/src/LanguageServer.ts @@ -93,7 +93,9 @@ export class LanguageServer { if (locationsAccumulator.length === 0) { for (const possibleFile of symbolUnderCursor.name.split(' ')) { - const possiblePath = join(dirname(document.uri), possibleFile) + const possiblePath = URI.parse( + join(dirname(document.uri), possibleFile) + ).toString() const file = await connection.sendRequest<{ contents: string } | null>('readFileContents', possiblePath) diff --git a/languageServer/src/test/definitions.test.ts b/languageServer/src/test/definitions.test.ts index ac223c0480..01fa45cd1a 100644 --- a/languageServer/src/test/definitions.test.ts +++ b/languageServer/src/test/definitions.test.ts @@ -1,4 +1,5 @@ import { Position, Range } from 'vscode-languageserver/node' +import { URI } from 'vscode-uri' import { params_dvc_yaml, train_dvc_yaml } from './fixtures/examples/valid' import { params } from './fixtures/params' import { train } from './fixtures/python' @@ -58,8 +59,10 @@ describe('textDocument/definitions', () => { }) it('should try to read the file system when a python file is unknown', async () => { + const trainUri = URI.file('train.py').toString() + mockedReadFileContents.mockImplementation(path => { - if (path === 'file:/train.py') { + if (path === trainUri) { return { contents: train } } return null @@ -75,14 +78,14 @@ describe('textDocument/definitions', () => { const response = await requestDefinitions(dvcYaml, 'train.py') - expect(mockedReadFileContents).toHaveBeenCalledWith('file:/train.py', { + expect(mockedReadFileContents).toHaveBeenCalledWith(trainUri, { _isCancelled: false }) expect(response).toBeTruthy() expect(response).toStrictEqual({ range: Range.create(Position.create(0, 0), Position.create(7, 13)), - uri: 'file:/train.py' + uri: trainUri }) }) })