diff --git a/README.md b/README.md index 309e90f..9f5d15e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Tells the extension to use a local release of the Lexical language server instead of the automatically installed one. Useful to work on Lexical, or use an older version. This path can point to a directory that holds the lexical start script (assumed to be `start_lexical.sh`) or any executable launcher script. +Relative paths will be interpreted to be relative to the current VSCode workspace. The path should look something like `/home/username/Projects/lexical/_build/dev/package/lexical/bin/start_lexical.sh`. diff --git a/package-lock.json b/package-lock.json index 35e4cb5..d49a7e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lexical", - "version": "0.0.22", + "version": "0.0.23", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lexical", - "version": "0.0.22", + "version": "0.0.23", "license": "Apache-2.0", "dependencies": { "axios": "1.7.9", diff --git a/src/configuration.ts b/src/configuration.ts index 33b9fdb..26ca5ae 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -8,8 +8,27 @@ namespace Configuration { export function getReleasePathOverride( getConfig: GetConfig, + workspace: typeof vsWorkspace, ): string | undefined { - return getConfig("releasePathOverride") as string | undefined; + const releasePath = getConfig("releasePathOverride") as string | undefined; + + if (!releasePath) { + Logger.info("Release override path is undefined."); + return undefined; + } else if (path.isAbsolute(releasePath)) { + Logger.info( + `Release override path is set to absolute path "${releasePath}".`, + ); + return releasePath; + } else { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const workspacePath = workspace.workspaceFolders![0].uri.path; + const absolutePath = path.join(workspacePath, releasePath); + Logger.info( + `Release override path is set to relative path "${releasePath}". Expanded absolute path is "${absolutePath}".`, + ); + return absolutePath; + } } export function getProjectDirUri( diff --git a/src/extension.ts b/src/extension.ts index fd30e51..83eb184 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -43,17 +43,18 @@ export function deactivate(): void { async function maybeAutoInstall( context: ExtensionContext, ): Promise { - const releasePathOverride = Configuration.getReleasePathOverride(getConfig); + const releasePathOverride = Configuration.getReleasePathOverride( + getConfig, + workspace, + ); if (releasePathOverride !== undefined && releasePathOverride !== "") { - Logger.info( - `Release override path set to "${releasePathOverride}". Skipping auto-install.`, - ); + Logger.info(`Release override path is set. Skipping auto-install.`); return releasePathOverride as string; } - Logger.info("Release override path is undefined, starting auto-install."); + Logger.info("Release override path is undefined. Starting auto-install."); return await LanguageServer.install( context.globalStorageUri, @@ -115,9 +116,11 @@ async function start( clientOptions, ); - Logger.info( - `Starting lexical release in "${startScriptOrReleaseFolderPath}"`, - ); + if (fs.existsSync(startScriptPath)) { + Logger.info(`Starting lexical at "${startScriptPath}"`); + } else { + Logger.error(`Lexical start script not found: ${startScriptPath}`); + } try { await client.start(); diff --git a/src/test/configuration.test.ts b/src/test/configuration.test.ts index e218d97..2c8620d 100644 --- a/src/test/configuration.test.ts +++ b/src/test/configuration.test.ts @@ -25,4 +25,45 @@ describe("Configuration", () => { expect(projectDirUri).toEqual(URI.file("/stub/subdirectory")); }); + + test("getReleasePathOverride returns undefined when no releasePathOverride is configured", () => { + const getConfigMock = jest.fn().mockReturnValue(undefined); + const workspace = WorkspaceFixture.withUri(URI.file("/stub")); + const releasePathOverride = Configuration.getReleasePathOverride( + getConfigMock, + workspace, + ); + + expect(releasePathOverride).toBeUndefined(); + }); + + test("getReleasePathOverride returns the path as configured when it is asolute", () => { + const absolutePath = "/an/absolute/path"; + const getConfigMock = jest.fn().mockReturnValue(absolutePath); + const workspace = WorkspaceFixture.withUri(URI.file("/stub")); + const releasePathOverride = Configuration.getReleasePathOverride( + getConfigMock, + workspace, + ); + + expect(releasePathOverride).toBe(absolutePath); + }); + + test.each([ + ["./a/relative/path", "/my/workspace", "/my/workspace/a/relative/path"], + ["../a/relative/path", "/my/workspace", "/my/a/relative/path"], + ["a/relative/path", "/my/workspace", "/my/workspace/a/relative/path"], + ])( + "getReleasePathOverride returns the workspace path joined with the release path when it is relative (%s)", + (releasePath, workspacePath, expectedPath) => { + const getConfigMock = jest.fn().mockReturnValue(releasePath); + const workspace = WorkspaceFixture.withUri(URI.file(workspacePath)); + const releasePathOverride = Configuration.getReleasePathOverride( + getConfigMock, + workspace, + ); + + expect(releasePathOverride).toBe(expectedPath); + }, + ); });