Skip to content

Use in-memory debug adapter instead of spinning up new process #2672

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

Merged

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Apr 29, 2020

PR Summary

This leverages a newish feature in VS Code called a DebugAdapter type. I heard about it from this issue:

microsoft/vscode#84643 (comment)

This gives us:

  • The debug adapter client actually being in the same process as the extension
  • logging to the vscode-powershell.log file instead of some other file.
  • cleaner code (less weird callbacks)

This partially solves #2358 because now, the debug adapter won't die... it'll kick the extension on and say "run it again in a bit once the extension fully starts"

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

This is not my area of expertise but it seems like we are using more of VSCode's native facilities rather than our own custom solution. Sounds good to me.

private static readonly HEADER_LINESEPARATOR = /\r?\n/; // allow for non-RFC 2822 conforming line separators
private static readonly HEADER_FIELDSEPARATOR = /: */;

private _rawData = Buffer.allocUnsafe(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the initialisation here used for? I'm guessing there's somewhere we can pass in undefined and this is the cheapest way to pass in an empty buffer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly, this comes from VS Code's implementation that's quite challenging to fully understand... they also set this in the constructor... so I'm really unsure why.

onDidSendMessage: Event<DebugProtocolMessage> = this._sendMessage.event;

constructor(namedPipe: string, logger: Logger) {
this._debugServiceSocket = connect(namedPipe);
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry a bit about objects that can't be constructed without connecting to an IPC stream, but really it's probably fine

Copy link
Member Author

Choose a reason for hiding this comment

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

now the constructor does almost nothing and start() method does the connection.

private _isConnected: boolean = false;
private _debugMessageQueue: DebugProtocolMessage[] = [];

private _debugServiceSocket: Socket;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these be added to the constructor for injection-initialisation?

Copy link
Member Author

Choose a reason for hiding this comment

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

decided against this because I wanted the _ prefix.

@TylerLeonhardt TylerLeonhardt merged commit 8436c5a into PowerShell:master May 1, 2020
@TylerLeonhardt TylerLeonhardt deleted the use-in-memory-debug-adapter branch May 1, 2020 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants