Skip to content
Open
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
5 changes: 5 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export class Ruby implements RubyInterface {
}
}

// Files watched to restart the server when the project's Ruby version changes.
get versionDefinitionFiles(): string[] {
return [".ruby-version", ".tool-versions", "mise.toml", ".mise.toml"];
}

get env() {
return this._env;
}
Expand Down
18 changes: 18 additions & 0 deletions vscode/src/test/suite/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,22 @@ suite("Workspace", () => {
assert.strictEqual(startStub.callCount, 0);
assert.strictEqual(restartSpy.callCount, 0);
}).timeout(10000);

test("restarts when the Ruby version file is modified", async () => {
const versionFileUri = vscode.Uri.file(path.join(workspacePath, ".ruby-version"));
await vscode.workspace.fs.writeFile(versionFileUri, Buffer.from("3.3.0"));

await workspace.activate();

const startStub = sandbox.stub(workspace, "start");
const restartSpy = sandbox.spy(workspace, "restart");

await vscode.workspace.fs.writeFile(versionFileUri, Buffer.from("3.4.0"));

// Give enough time for the watcher to fire and the debounce to run off
await new Promise((resolve) => setTimeout(resolve, 6000));

assert.strictEqual(startStub.callCount, 1);
assert.strictEqual(restartSpy.callCount, 1);
}).timeout(10000);
});
3 changes: 2 additions & 1 deletion vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Workspace implements WorkspaceInterface {
this.registerRestarts();

// Eagerly calculate SHAs for the watched files to avoid unnecessary restarts
for (const file of WATCHED_FILES) {
for (const file of [...WATCHED_FILES, ...this.ruby.versionDefinitionFiles]) {
const uri = vscode.Uri.joinPath(this.workspaceFolder.uri, file);
const currentSha = await this.fileContentsSha(uri);

Expand Down Expand Up @@ -345,6 +345,7 @@ export class Workspace implements WorkspaceInterface {

private registerRestarts() {
this.createRestartWatcher(`{${WATCHED_FILES.join(",")}}`);
this.createRestartWatcher(`{${this.ruby.versionDefinitionFiles.join(",")}}`);

// If a configuration that affects the Ruby LSP has changed, update the client options using the latest
// configuration and restart the server
Expand Down
Loading