-
Notifications
You must be signed in to change notification settings - Fork 520
Sync breakpoints outside of DAP with onDidChangeBreakpoints event
#4065
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
Draft
+210
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
57f106f
Add a debug config with JmC enabled
SeeminglyScience b535814
Add bp manager for syncing outside of DAP
SeeminglyScience 0a11920
hook up bp manager
SeeminglyScience 63f2aa3
Merge branch 'main' into bp-sync
SeeminglyScience 9504512
Fix build errors and add error logging
SeeminglyScience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
src/features/BreakpointManager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import vscode = require("vscode"); | ||
| import { LanguageClient } from "vscode-languageclient/node"; | ||
| import { Range, NotificationType, RequestType } from "vscode-languageserver-protocol"; | ||
| import { LanguageClientConsumer } from "../languageClientConsumer"; | ||
| import { Logger } from "../logging"; | ||
|
|
||
| export const BreakpointChangedNotificationType = new NotificationType<IPsesBreakpointChangedEventArgs>("powerShell/breakpointsChanged"); | ||
| export const SetBreakpointRequestType = new RequestType<IPsesBreakpoint, string, void>("powerShell/setBreakpoint"); | ||
| export const BreakpointRemovedNotificationType = new NotificationType<IPsesBreakpoint>("powerShell/breakpointRemoved"); | ||
| export const BreakpointEnabledChanged = new NotificationType<IPsesBreakpoint>("powerShell/breakpointEnabledChanged"); | ||
|
|
||
| interface IPsesBreakpoint { | ||
| id: string, | ||
| enabled: boolean, | ||
| condition?: string, | ||
| hitCondition?: string, | ||
| logMessage?: string, | ||
| location?: IPsesLocation, | ||
| functionName?: string, | ||
| } | ||
|
|
||
| interface IPsesLocation { | ||
| uri: string, | ||
| range: Range, | ||
| } | ||
|
|
||
| interface IPsesBreakpointChangedEventArgs { | ||
| added: IPsesBreakpoint[], | ||
| removed: IPsesBreakpoint[], | ||
| changed: IPsesBreakpoint[], | ||
| } | ||
|
|
||
| export class BreakpointManager extends LanguageClientConsumer{ | ||
| private eventRegistration: vscode.Disposable | undefined; | ||
|
|
||
| private notificationRegistration: vscode.Disposable | undefined; | ||
|
|
||
| private requestRegistration: vscode.Disposable | undefined; | ||
|
|
||
| private logger: Logger; | ||
|
|
||
| constructor(logger: Logger) { | ||
| super(); | ||
|
|
||
| this.logger = logger; | ||
| } | ||
|
|
||
| public override setLanguageClient(languageClient: LanguageClient): void { | ||
| this.languageClient = languageClient; | ||
|
|
||
| this.requestRegistration = this.languageClient.onRequest( | ||
| SetBreakpointRequestType, | ||
| bp => { | ||
| const clientBp: vscode.Breakpoint | undefined = this.toVSCodeBreakpoint(bp); | ||
| if (clientBp === undefined) { | ||
| return -1; | ||
| } | ||
|
|
||
| vscode.debug.addBreakpoints([clientBp]); | ||
| return clientBp.id; | ||
| }); | ||
|
|
||
| this.notificationRegistration = this.languageClient.onNotification( | ||
| BreakpointChangedNotificationType.method, | ||
| (eventArgs) => { | ||
| this.handleServerBreakpointChanged(this.toVSCodeBreakpointsChanged(eventArgs)); | ||
| }); | ||
|
|
||
| this.eventRegistration = vscode.debug.onDidChangeBreakpoints( | ||
| (eventArgs) => { | ||
| this.handleClientBreakpointChanged(eventArgs) | ||
| .catch((reason) => { | ||
| this.logger.writeError(`Error occurred while handling client breakpoint changed: ${reason}`); | ||
| }); | ||
| }, | ||
| this); | ||
| } | ||
|
|
||
| private handleServerBreakpointChanged(eventArgs: vscode.BreakpointsChangeEvent): void { | ||
| vscode.debug.removeBreakpoints(eventArgs.removed); | ||
| } | ||
|
|
||
| private async handleClientBreakpointChanged(eventArgs: vscode.BreakpointsChangeEvent): Promise<void> { | ||
| if (this.languageClient === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| await this.languageClient.sendNotification( | ||
| BreakpointChangedNotificationType, | ||
| this.toPsesBreakpointsChanged(eventArgs)); | ||
| } | ||
|
|
||
| private toVSCodeBreakpointsChanged(eventArgs: IPsesBreakpointChangedEventArgs): vscode.BreakpointsChangeEvent { | ||
| const map: Map<string, vscode.Breakpoint> = new Map<string, vscode.Breakpoint>( | ||
| vscode.debug.breakpoints.map(bp => [bp.id, bp])); | ||
|
|
||
| const isBreakpoint = (bp: vscode.Breakpoint | undefined): bp is vscode.Breakpoint => bp !== undefined; | ||
| return { | ||
| added: eventArgs.added.map((bp) => this.toVSCodeBreakpoint(bp, map)).filter(isBreakpoint), | ||
| removed: eventArgs.removed.map((bp) => this.toVSCodeBreakpoint(bp, map)).filter(isBreakpoint), | ||
| changed: eventArgs.changed.map((bp) => this.toVSCodeBreakpoint(bp, map)).filter(isBreakpoint), | ||
| }; | ||
| } | ||
|
|
||
| private toPsesBreakpointsChanged(eventArgs: vscode.BreakpointsChangeEvent): IPsesBreakpointChangedEventArgs { | ||
| return { | ||
| added: eventArgs.added.map((bp) => this.toPsesBreakpoint(bp)), | ||
| removed: eventArgs.removed.map((bp) => this.toPsesBreakpoint(bp)), | ||
| changed: eventArgs.changed.map((bp) => this.toPsesBreakpoint(bp)), | ||
| }; | ||
| } | ||
|
|
||
| private toVSCodeBreakpoint(breakpoint: IPsesBreakpoint, map?: Map<string, vscode.Breakpoint>): vscode.Breakpoint | undefined { | ||
| const existing: vscode.Breakpoint | undefined = map?.get(breakpoint.id); | ||
| if (existing !== undefined) { | ||
| return existing; | ||
| } | ||
|
|
||
| if (breakpoint.location !== undefined) { | ||
| const bp = new vscode.SourceBreakpoint( | ||
| new vscode.Location( | ||
| vscode.Uri.parse(breakpoint.location.uri), | ||
| new vscode.Range( | ||
| breakpoint.location.range.start.line, | ||
| breakpoint.location.range.start.character, | ||
| breakpoint.location.range.end.line, | ||
| breakpoint.location.range.end.character)), | ||
| breakpoint.enabled, | ||
| breakpoint.condition, | ||
| breakpoint.hitCondition, | ||
| breakpoint.logMessage); | ||
|
|
||
| return bp; | ||
| } | ||
|
|
||
| if (breakpoint.functionName !== undefined) { | ||
| const fbp = new vscode.FunctionBreakpoint( | ||
| breakpoint.functionName, | ||
| breakpoint.enabled, | ||
| breakpoint.condition, | ||
| breakpoint.hitCondition, | ||
| breakpoint.logMessage); | ||
|
|
||
| return fbp; | ||
| } | ||
|
|
||
| this.logger.writeError(`Unable to translate PSES breakpoint: ${JSON.stringify(breakpoint)}`); | ||
| return undefined; | ||
| } | ||
|
|
||
| private toPsesBreakpoint(breakpoint: vscode.Breakpoint): IPsesBreakpoint { | ||
| let psesLocation: IPsesLocation | undefined = undefined; | ||
| if (breakpoint instanceof vscode.SourceBreakpoint) { | ||
| psesLocation = { | ||
| uri: breakpoint.location.uri.toString(), | ||
| range: { | ||
| start: { | ||
| character: breakpoint.location.range.start.character, | ||
| line: breakpoint.location.range.start.line, | ||
| }, | ||
| end: { | ||
| character: breakpoint.location.range.end.character, | ||
| line: breakpoint.location.range.end.line, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| let functionName: string | undefined = undefined; | ||
| if (breakpoint instanceof vscode.FunctionBreakpoint) { | ||
| functionName = breakpoint.functionName; | ||
| } | ||
|
|
||
| return { | ||
| id: breakpoint.id, | ||
| enabled: breakpoint.enabled, | ||
| condition: breakpoint.condition, | ||
| hitCondition: breakpoint.hitCondition, | ||
| logMessage: breakpoint.logMessage, | ||
| location: psesLocation, | ||
| functionName, | ||
| }; | ||
| } | ||
|
|
||
| dispose(): void { | ||
| this.eventRegistration?.dispose(); | ||
| this.notificationRegistration?.dispose(); | ||
| this.requestRegistration?.dispose(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.