Skip to content

Commit

Permalink
Improve debug workspace selection (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Jan 5, 2024
1 parent 91d8a61 commit d6cc550
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
25 changes: 15 additions & 10 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export class Debugger
{
private debugProcess?: ChildProcessWithoutNullStreams;
private readonly console = vscode.debug.activeDebugConsole;
private readonly currentActiveWorkspace: () => Workspace | undefined;
private readonly workspaceResolver: (
uri: vscode.Uri,
) => Workspace | undefined;

constructor(
context: vscode.ExtensionContext,
currentActiveWorkspace: () => Workspace | undefined,
workspaceResolver: (uri: vscode.Uri) => Workspace | undefined,
) {
this.currentActiveWorkspace = currentActiveWorkspace;
this.workspaceResolver = workspaceResolver;

context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider("ruby_lsp", this),
Expand Down Expand Up @@ -80,14 +82,18 @@ export class Debugger
// insert defaults for the user. The most important thing is making sure the Ruby environment is a part of it so that
// we launch using the right bundle and Ruby version
resolveDebugConfiguration?(
_folder: vscode.WorkspaceFolder | undefined,
folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
_token?: vscode.CancellationToken,
): vscode.ProviderResult<vscode.DebugConfiguration> {
const workspace = this.currentActiveWorkspace();
if (!folder) {
throw new Error("Debugging requires a workspace folder to be opened");
}

const workspace = this.workspaceResolver(folder.uri);

if (!workspace) {
throw new Error("Debugging requires a workspace folder to be opened");
throw new Error(`Couldn't find workspace ${folder.name}`);
}

if (debugConfiguration.env) {
Expand Down Expand Up @@ -159,13 +165,12 @@ export class Debugger
let initialMessage = "";
let initialized = false;

const workspace = this.currentActiveWorkspace();

if (!workspace) {
const workspaceFolder = session.workspaceFolder;
if (!workspaceFolder) {
throw new Error("Debugging requires a workspace folder to be opened");
}

const cwd = workspace.workspaceFolder.uri.fsPath;
const cwd = workspaceFolder.uri.fsPath;
const sockPath = this.socketPath(cwd);
const configuration = session.configuration;

Expand Down
2 changes: 1 addition & 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.currentActiveWorkspace.bind(this));
this.debug = new Debugger(context, this.getWorkspace.bind(this));
this.registerCommands(context);

this.statusItems = new StatusItems();
Expand Down
7 changes: 2 additions & 5 deletions src/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class TestController {
);
}

return vscode.debug.startDebugging(undefined, {
return vscode.debug.startDebugging(workspace.workspaceFolder, {
type: "ruby_lsp",
name: "Debug",
request: "launch",
Expand Down Expand Up @@ -264,6 +264,7 @@ export class TestController {
} else {
this.testController.items.forEach(enqueue);
}
const workspace = this.currentWorkspace();

while (queue.length > 0 && !token.isCancellationRequested) {
const test = queue.pop()!;
Expand All @@ -277,8 +278,6 @@ export class TestController {
if (test.tags.find((tag) => tag.id === "example")) {
const start = Date.now();
try {
const workspace = this.currentWorkspace();

if (!workspace) {
run.errored(test, new vscode.TestMessage("No workspace found"));
continue;
Expand Down Expand Up @@ -335,8 +334,6 @@ export class TestController {
// Make sure to end the run after all tests have been executed
run.end();

const workspace = this.currentWorkspace();

if (workspace?.lspClient?.serverVersion) {
await this.telemetry.sendCodeLensEvent(
"test",
Expand Down

0 comments on commit d6cc550

Please sign in to comment.