Skip to content

Commit

Permalink
Push disposables to subscriptions (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Jul 5, 2024
1 parent a4391c6 commit 0f82994
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
72 changes: 39 additions & 33 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Range } from "vscode-languageclient/node";
import { Telemetry } from "./telemetry";
import DocumentProvider from "./documentProvider";
import { Workspace } from "./workspace";
import { Command, STATUS_EMITTER } from "./common";
import { Command, LOG_CHANNEL, STATUS_EMITTER } from "./common";
import { ManagerIdentifier, ManagerConfiguration } from "./ruby";
import { StatusItems } from "./status";
import { TestController } from "./testController";
Expand Down Expand Up @@ -35,45 +35,51 @@ export class RubyLsp {

this.statusItems = new StatusItems();
const dependenciesTree = new DependenciesTree();
context.subscriptions.push(this.statusItems, this.debug, dependenciesTree);

// Switch the status items based on which workspace is currently active
vscode.window.onDidChangeActiveTextEditor((editor) => {
STATUS_EMITTER.fire(this.currentActiveWorkspace(editor));
});

vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
// Stop the language server and dispose all removed workspaces
for (const workspaceFolder of event.removed) {
const workspace = this.getWorkspace(workspaceFolder.uri);
context.subscriptions.push(
this.statusItems,
this.debug,
dependenciesTree,

if (workspace) {
await workspace.stop();
await workspace.dispose();
this.workspaces.delete(workspaceFolder.uri.toString());
// Switch the status items based on which workspace is currently active
vscode.window.onDidChangeActiveTextEditor((editor) => {
STATUS_EMITTER.fire(this.currentActiveWorkspace(editor));
}),
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
// Stop the language server and dispose all removed workspaces
for (const workspaceFolder of event.removed) {
const workspace = this.getWorkspace(workspaceFolder.uri);

if (workspace) {
await workspace.stop();
await workspace.dispose();
this.workspaces.delete(workspaceFolder.uri.toString());
}
}
}
});
}),

// Lazily activate workspaces that do not contain a lockfile
vscode.workspace.onDidOpenTextDocument(async (document) => {
if (document.languageId !== "ruby") {
return;
}
// Lazily activate workspaces that do not contain a lockfile
vscode.workspace.onDidOpenTextDocument(async (document) => {
if (document.languageId !== "ruby") {
return;
}

const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
document.uri,
);

if (!workspaceFolder) {
return;
}
if (!workspaceFolder) {
return;
}

const workspace = this.getWorkspace(workspaceFolder.uri);
const workspace = this.getWorkspace(workspaceFolder.uri);

// If the workspace entry doesn't exist, then we haven't activated the workspace yet
if (!workspace) {
await this.activateWorkspace(workspaceFolder, false);
}
});
// If the workspace entry doesn't exist, then we haven't activated the workspace yet
if (!workspace) {
await this.activateWorkspace(workspaceFolder, false);
}
}),
LOG_CHANNEL,
);
}

// Activate the extension. This method should perform all actions necessary to start the extension, such as booting
Expand Down
7 changes: 3 additions & 4 deletions vscode/src/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ export class TestController {
this.debugTag,
);

vscode.window.onDidCloseTerminal((terminal: vscode.Terminal): void => {
if (terminal === this.terminal) this.terminal = undefined;
});

context.subscriptions.push(
this.testController,
this.testDebugProfile,
this.testRunProfile,
vscode.window.onDidCloseTerminal((terminal: vscode.Terminal): void => {
if (terminal === this.terminal) this.terminal = undefined;
}),
);
}

Expand Down
28 changes: 15 additions & 13 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,22 @@ export class Workspace implements WorkspaceInterface {

// If a configuration that affects the Ruby LSP has changed, update the client options using the latest
// configuration and restart the server
vscode.workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration("rubyLsp")) {
// Re-activate Ruby if the version manager changed
if (
event.affectsConfiguration("rubyLsp.rubyVersionManager") ||
event.affectsConfiguration("rubyLsp.bundleGemfile") ||
event.affectsConfiguration("rubyLsp.customRubyCommand")
) {
await this.ruby.activateRuby();
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration("rubyLsp")) {
// Re-activate Ruby if the version manager changed
if (
event.affectsConfiguration("rubyLsp.rubyVersionManager") ||
event.affectsConfiguration("rubyLsp.bundleGemfile") ||
event.affectsConfiguration("rubyLsp.customRubyCommand")
) {
await this.ruby.activateRuby();
}

await this.restart();
}

await this.restart();
}
});
}),
);
}

private createRestartWatcher(
Expand Down

0 comments on commit 0f82994

Please sign in to comment.