Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push disposables to subscriptions #2254

Merged
merged 1 commit into from
Jul 5, 2024
Merged
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
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
Loading