From a52227dccf50f9e2d7df3262fd895918afbd36f2 Mon Sep 17 00:00:00 2001 From: azerr Date: Thu, 8 Jan 2026 14:30:51 +0100 Subject: [PATCH] Support for debugging Qute template in Java annotation Signed-off-by: azerr --- package.json | 3 +- .../quteDebugAdapterTrackerFactory.ts | 66 +++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 728364c8..3e367638 100644 --- a/package.json +++ b/package.json @@ -208,7 +208,8 @@ "qute-html", "qute-json", "qute-yaml", - "qute-txt" + "qute-txt", + "java" ], "configurationAttributes": { "attach": { diff --git a/src/qute/debugAdapter/quteDebugAdapterTrackerFactory.ts b/src/qute/debugAdapter/quteDebugAdapterTrackerFactory.ts index bf76d258..a56579a4 100644 --- a/src/qute/debugAdapter/quteDebugAdapterTrackerFactory.ts +++ b/src/qute/debugAdapter/quteDebugAdapterTrackerFactory.ts @@ -5,6 +5,28 @@ interface ResponsePromise { timerStart: number; } +interface JavaSourceLocationArguments { + javaElementUri: string; + typeName?: string; + method?: string; + annotation?: string; +} + +interface JavaSourceLocationEventArguments { + id: string; + args: JavaSourceLocationArguments; +} + +interface JavaSourceLocationEventResponse { + id: string; + response: JavaSourceLocationResponse; +} + +interface JavaSourceLocationResponse { + javaFileUri?: string; + startLine?: number; +} + enum Trace { Off, Messages, Verbose } @@ -55,6 +77,29 @@ export class QuteDebugAdapterTrackerFactory implements vscode.DebugAdapterTracke if (message.type === 'response') { handleResponse(message); } else if (message.type === 'event') { + if (message.event === 'qute/onResolveJavaSource') { + // Collect startLine of the declared annotation + // which hosts Qute template + // ex : @TemplateContents(value="Hello {name}!") + // record Hello(String name) + const args: JavaSourceLocationEventArguments = message.body; + resolveJavaSourceForTemplate(args.args) + .then((javaResponse: JavaSourceLocationResponse | null) => { + const eventResponse: JavaSourceLocationEventResponse = { + id: args.id, + response: javaResponse + }; + // The start line has been collected, notify the Qute debugger + // with this start line. + session.customRequest('qute/onJavaSourceResolved', eventResponse); + }).catch(err => { + console.error("Failed to resolve Java source", err); + session.customRequest('qute/onJavaSourceResolved', { + id: args.id, + response: null + }); + }); + } traceReceivedNotification(message); } }, @@ -74,6 +119,19 @@ export class QuteDebugAdapterTrackerFactory implements vscode.DebugAdapterTracke } } +async function resolveJavaSourceForTemplate(args: JavaSourceLocationArguments): Promise { + try { + // Appel JDT LS pour récupérer la source Java + const result = await vscode.commands.executeCommand( + 'java.execute.workspaceCommand', 'qute/debug/resolveJavaSource', args + ); + return result ?? null; + } catch (err) { + console.error("Failed to resolve Java source via JDT LS", err); + return null; + } +} + /** * Update trace level from current settings. */ @@ -106,9 +164,9 @@ function traceReceivedNotification(message: any): void { let data: string | undefined = undefined; if (trace === Trace.Verbose) { - data = message.body - ? `Params: ${stringifyTrace(message.body)}` - : 'No parameters provided.'; + data = message.body + ? `Params: ${stringifyTrace(message.body)}` + : 'No parameters provided.'; } showTrace(`Received notification '${message.event}'.`, data); } @@ -172,7 +230,7 @@ function stringifyTrace(params: any): string | undefined { } function showTrace(message: string, data?: any | undefined): void { - outputChannel!.trace(getLogMessage(message, data)); + outputChannel!.info(getLogMessage(message, data)); } function showError(message: string): void {