Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.

Commit 6d5dcb3

Browse files
authored
Add support for relative release path overrides (#97)
1 parent c2c955e commit 6d5dcb3

5 files changed

Lines changed: 75 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Tells the extension to use a local release of the Lexical language server
3939
instead of the automatically installed one. Useful to work on Lexical, or use an
4040
older version. This path can point to a directory that holds the lexical start
4141
script (assumed to be `start_lexical.sh`) or any executable launcher script.
42+
Relative paths will be interpreted to be relative to the current VSCode workspace.
4243

4344
The path should look something like
4445
`/home/username/Projects/lexical/_build/dev/package/lexical/bin/start_lexical.sh`.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configuration.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,27 @@ namespace Configuration {
88

99
export function getReleasePathOverride(
1010
getConfig: GetConfig,
11+
workspace: typeof vsWorkspace,
1112
): string | undefined {
12-
return getConfig("releasePathOverride") as string | undefined;
13+
const releasePath = getConfig("releasePathOverride") as string | undefined;
14+
15+
if (!releasePath) {
16+
Logger.info("Release override path is undefined.");
17+
return undefined;
18+
} else if (path.isAbsolute(releasePath)) {
19+
Logger.info(
20+
`Release override path is set to absolute path "${releasePath}".`,
21+
);
22+
return releasePath;
23+
} else {
24+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25+
const workspacePath = workspace.workspaceFolders![0].uri.path;
26+
const absolutePath = path.join(workspacePath, releasePath);
27+
Logger.info(
28+
`Release override path is set to relative path "${releasePath}". Expanded absolute path is "${absolutePath}".`,
29+
);
30+
return absolutePath;
31+
}
1332
}
1433

1534
export function getProjectDirUri(

src/extension.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ export function deactivate(): void {
4343
async function maybeAutoInstall(
4444
context: ExtensionContext,
4545
): Promise<string | undefined> {
46-
const releasePathOverride = Configuration.getReleasePathOverride(getConfig);
46+
const releasePathOverride = Configuration.getReleasePathOverride(
47+
getConfig,
48+
workspace,
49+
);
4750

4851
if (releasePathOverride !== undefined && releasePathOverride !== "") {
49-
Logger.info(
50-
`Release override path set to "${releasePathOverride}". Skipping auto-install.`,
51-
);
52+
Logger.info(`Release override path is set. Skipping auto-install.`);
5253

5354
return releasePathOverride as string;
5455
}
5556

56-
Logger.info("Release override path is undefined, starting auto-install.");
57+
Logger.info("Release override path is undefined. Starting auto-install.");
5758

5859
return await LanguageServer.install(
5960
context.globalStorageUri,
@@ -115,9 +116,11 @@ async function start(
115116
clientOptions,
116117
);
117118

118-
Logger.info(
119-
`Starting lexical release in "${startScriptOrReleaseFolderPath}"`,
120-
);
119+
if (fs.existsSync(startScriptPath)) {
120+
Logger.info(`Starting lexical at "${startScriptPath}"`);
121+
} else {
122+
Logger.error(`Lexical start script not found: ${startScriptPath}`);
123+
}
121124

122125
try {
123126
await client.start();

src/test/configuration.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,45 @@ describe("Configuration", () => {
2525

2626
expect(projectDirUri).toEqual(URI.file("/stub/subdirectory"));
2727
});
28+
29+
test("getReleasePathOverride returns undefined when no releasePathOverride is configured", () => {
30+
const getConfigMock = jest.fn().mockReturnValue(undefined);
31+
const workspace = WorkspaceFixture.withUri(URI.file("/stub"));
32+
const releasePathOverride = Configuration.getReleasePathOverride(
33+
getConfigMock,
34+
workspace,
35+
);
36+
37+
expect(releasePathOverride).toBeUndefined();
38+
});
39+
40+
test("getReleasePathOverride returns the path as configured when it is asolute", () => {
41+
const absolutePath = "/an/absolute/path";
42+
const getConfigMock = jest.fn().mockReturnValue(absolutePath);
43+
const workspace = WorkspaceFixture.withUri(URI.file("/stub"));
44+
const releasePathOverride = Configuration.getReleasePathOverride(
45+
getConfigMock,
46+
workspace,
47+
);
48+
49+
expect(releasePathOverride).toBe(absolutePath);
50+
});
51+
52+
test.each([
53+
["./a/relative/path", "/my/workspace", "/my/workspace/a/relative/path"],
54+
["../a/relative/path", "/my/workspace", "/my/a/relative/path"],
55+
["a/relative/path", "/my/workspace", "/my/workspace/a/relative/path"],
56+
])(
57+
"getReleasePathOverride returns the workspace path joined with the release path when it is relative (%s)",
58+
(releasePath, workspacePath, expectedPath) => {
59+
const getConfigMock = jest.fn().mockReturnValue(releasePath);
60+
const workspace = WorkspaceFixture.withUri(URI.file(workspacePath));
61+
const releasePathOverride = Configuration.getReleasePathOverride(
62+
getConfigMock,
63+
workspace,
64+
);
65+
66+
expect(releasePathOverride).toBe(expectedPath);
67+
},
68+
);
2869
});

0 commit comments

Comments
 (0)