diff --git a/vscode/src/ruby.ts b/vscode/src/ruby.ts index b628c8233..78f2c8905 100644 --- a/vscode/src/ruby.ts +++ b/vscode/src/ruby.ts @@ -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; } diff --git a/vscode/src/test/suite/workspace.test.ts b/vscode/src/test/suite/workspace.test.ts index 326f23069..c095b5b70 100644 --- a/vscode/src/test/suite/workspace.test.ts +++ b/vscode/src/test/suite/workspace.test.ts @@ -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); }); diff --git a/vscode/src/workspace.ts b/vscode/src/workspace.ts index e916aa46d..b771563f4 100644 --- a/vscode/src/workspace.ts +++ b/vscode/src/workspace.ts @@ -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); @@ -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