mike-lischke / vscode-antlr4

ANTLR4 language support for Visual Studio Code
http://www.soft-gems.net
MIT License
421 stars 58 forks source link

breakpoints are ignored in debug mode #268

Open Krysl opened 4 months ago

Krysl commented 4 months ago

test code from #74

If I have another file also have some breakpoints (such as Ztest.g, which is used by setBreakPointsRequest() later than test.g). The breakpoints set by test.g will be clear by Ztest.g in this.debugger.clearBreakPoints();https://github.com/mike-lischke/vscode-antlr4/blob/bc5e7469d1db1769ee97129ecc1da6101c9588ba/src/frontend/AntlrDebugAdapter.ts#L239-L245

Krysl commented 4 months ago

path in this.contexts need to be normalized, otherwise entry.fileName === breakPoint.source may be false

https://github.com/mike-lischke/vscode-antlr4/blob/bc5e7469d1db1769ee97129ecc1da6101c9588ba/src/backend/GrammarDebugger.ts#L485-L489

Krysl commented 4 months ago
a simple patch just work for myself just to solve my own problem, without studying the code carefully, this patch may cause other problems. ```patch src/backend/facade.ts | 2 ++ src/frontend/AntlrDebugAdapter.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/facade.ts b/src/backend/facade.ts index 88e712a..4f5a732 100644 --- a/src/backend/facade.ts +++ b/src/backend/facade.ts @@ -24,6 +24,7 @@ import { } from "../types.js"; import { IATNGraphData } from "../webview-scripts/types.js"; import { SentenceGenerator } from "./SentenceGenerator.js"; +import { Uri } from 'vscode'; export class AntlrFacade { // Mapping file names to SourceContext instances. @@ -362,6 +363,7 @@ export class AntlrFacade { } public createDebugger(fileName: string, actionFile: string, dataDir: string): GrammarDebugger | undefined { + fileName = Uri.file(fileName).fsPath; const context = this.getContext(fileName); if (!context) { return; diff --git a/src/frontend/AntlrDebugAdapter.ts b/src/frontend/AntlrDebugAdapter.ts index 24bf0d6..9e90e99 100644 --- a/src/frontend/AntlrDebugAdapter.ts +++ b/src/frontend/AntlrDebugAdapter.ts @@ -239,7 +239,6 @@ export class AntlrDebugSession extends DebugSession { protected override setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void { if (this.debugger) { - this.debugger.clearBreakPoints(); if (args.breakpoints && args.source.path) { const actualBreakpoints = args.breakpoints.map((sourceBreakPoint) => { const { validated, line, id } = this.debugger!.addBreakPoint(args.source.path!, ```
mike-lischke commented 4 months ago

Thanks for reporting the issue and providing a possible solution. I'll look at this later when I come back to the extension development.