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

Print debugger output to the Ruby LSP output channel as well as the debug console #2957

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
33 changes: 22 additions & 11 deletions vscode/src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ export class Debugger

args.push("--open", "--command", "--", configuration.program);

LOG_CHANNEL.info(`Spawning debugger in directory ${cwd}`);
LOG_CHANNEL.info(` Command bundle ${args.join(" ")}`);
LOG_CHANNEL.info(` Environment ${JSON.stringify(configuration.env)}`);
this.logDebuggerMessage(`Spawning debugger in directory ${cwd}`);
this.logDebuggerMessage(` Command bundle ${args.join(" ")}`);
this.logDebuggerMessage(
` Environment ${JSON.stringify(configuration.env)}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing comma accidental?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's required by linting rules:

Screenshot 2024-12-04 at 20 56 27

When I save the file, it's automatically added back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it seems the linter is defaulting to an 80 character line limit.

);

this.debugProcess = spawn("bundle", args, {
shell: true,
Expand All @@ -268,8 +270,7 @@ export class Debugger

this.debugProcess.stderr.on("data", (data) => {
const message = data.toString();
// Print whatever data we get in stderr in the debug console since it might be relevant for the user
this.console.append(message);
this.logDebuggerMessage(message);

if (!initialized) {
initialMessage += message;
Expand All @@ -296,14 +297,14 @@ export class Debugger
}
});

// Anything printed by debug to stdout we want to show in the debug console
// Anything printed by debug to stdout we want to show in the Ruby LSP output channel
this.debugProcess.stdout.on("data", (data) => {
this.console.append(data.toString());
this.logDebuggerMessage(data.toString());
});

// If any errors occur in the server, we have to show that in the debug console and reject the promise
// If any errors occur in the server, we have to show that in the Ruby LSP output channel and reject the promise
this.debugProcess.on("error", (error) => {
this.console.append(error.message);
this.logDebuggerMessage(error.message);
reject(error);
});

Expand All @@ -312,8 +313,10 @@ export class Debugger
// actually an error
this.debugProcess.on("close", (code) => {
if (code) {
const message = `Debugger exited with status ${code}. Check the output channel for more information.`;
this.console.append(message);
const message =
`Debugger exited with status ${code}. ` +
"Check the Ruby LSP output channel for more information.";
this.logDebuggerMessage(message);
reject(new Error(message));
}
});
Expand Down Expand Up @@ -341,4 +344,12 @@ export class Debugger
});
});
}

private logDebuggerMessage(message: string) {
const trimmedMessage = message.trimEnd();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the debugger prints messages containing a \n in the end, it'd create an empty line in the log, which takes up space and doesn't help understanding the message. So IMO it's better to remove them.

if (trimmedMessage.length > 0) {
LOG_CHANNEL.info(`[debugger]: ${trimmedMessage}`);
this.console.append(trimmedMessage);
}
}
}
Loading