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

Commit

Permalink
Reduce workspace dependency for launching debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 12, 2024
1 parent 7903625 commit 9f42a97
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class Debugger
private debugProcess?: ChildProcessWithoutNullStreams;
private readonly console = vscode.debug.activeDebugConsole;
private readonly workspaceResolver: (
uri: vscode.Uri,
uri: vscode.Uri | undefined,
) => Workspace | undefined;

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

Expand Down Expand Up @@ -86,14 +86,12 @@ export class Debugger
debugConfiguration: vscode.DebugConfiguration,
_token?: vscode.CancellationToken,
): vscode.ProviderResult<vscode.DebugConfiguration> {
if (!folder) {
throw new Error("Debugging requires a workspace folder to be opened");
}

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

if (!workspace) {
throw new Error(`Couldn't find workspace ${folder.name}`);
throw new Error(
`Couldn't find a workspace for URI: ${folder?.uri} or editor: ${vscode.window.activeTextEditor}`,
);
}

if (debugConfiguration.env) {
Expand All @@ -106,6 +104,8 @@ export class Debugger
debugConfiguration.env = workspace.ruby.env;
}

debugConfiguration.workspace = workspace;

const workspacePath = workspace.workspaceFolder.uri.fsPath;

let customGemfilePath = path.join(workspacePath, ".ruby-lsp", "Gemfile");
Expand Down Expand Up @@ -165,14 +165,11 @@ export class Debugger
let initialMessage = "";
let initialized = false;

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

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

return new Promise((resolve, reject) => {
const args = [
Expand Down Expand Up @@ -241,14 +238,14 @@ export class Debugger

// Generate a socket path so that Ruby debug doesn't have to create one for us. This makes coordination easier since
// we always know the path to the socket
private socketPath(cwd: string) {
private socketPath(workspaceName: string) {
const socketsDir = path.join("/", "tmp", "ruby-lsp-debug-sockets");
if (!fs.existsSync(socketsDir)) {
fs.mkdirSync(socketsDir);
}

let socketIndex = 0;
const prefix = `ruby-debug-${path.basename(cwd)}`;
const prefix = `ruby-debug-${workspaceName}`;
const existingSockets = fs
.readdirSync(socketsDir)
.map((file) => file)
Expand Down

0 comments on commit 9f42a97

Please sign in to comment.