Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Fallback to guessing the active workspace if none is found based on URI #976

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class RubyLsp {
this.telemetry,
this.currentActiveWorkspace.bind(this),
);
this.debug = new Debugger(context, this.getWorkspace.bind(this));
this.debug = new Debugger(context, this.workspaceResolver.bind(this));
this.registerCommands(context);

this.statusItems = new StatusItems();
Expand Down Expand Up @@ -359,6 +359,28 @@ export class RubyLsp {
return this.workspaces.get(uri.toString());
}

private workspaceResolver(
uri: vscode.Uri | undefined,
): Workspace | undefined {
// If no URI is passed, we try to figured out what the active workspace is
if (!uri) {
return this.currentActiveWorkspace();
}

// If a workspace is found for that URI, then we return that one
const workspace = this.workspaces.get(uri.toString());
if (workspace) {
return workspace;
}

// Otherwise, if there's a URI, but we can't find a workspace for it, we fallback to trying to figure out what the
// active workspace is. This situation may happen if we receive a workspace folder URI that is not the actual
// workspace where the Ruby application exists. For example, if you have a monorepo with client and server
// directories and the `launch.json` file is in the top level directory, then we may receive the URI for the top
// level, but the actual workspace is the server directory
return this.currentActiveWorkspace();
vinistock marked this conversation as resolved.
Show resolved Hide resolved
}

// Displays a quick pick to select which workspace to perform an action on. For example, if multiple workspaces exist,
// then we need to know which workspace to restart the language server on
private async showWorkspacePick(): Promise<Workspace | undefined> {
Expand Down