Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@
"qute-html",
"qute-json",
"qute-yaml",
"qute-txt"
"qute-txt",
"java"
],
"configurationAttributes": {
"attach": {
Expand Down
66 changes: 62 additions & 4 deletions src/qute/debugAdapter/quteDebugAdapterTrackerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
},
Expand All @@ -74,6 +119,19 @@ export class QuteDebugAdapterTrackerFactory implements vscode.DebugAdapterTracke
}
}

async function resolveJavaSourceForTemplate(args: JavaSourceLocationArguments): Promise<JavaSourceLocationResponse | null> {
try {
// Appel JDT LS pour récupérer la source Java
const result = await vscode.commands.executeCommand<JavaSourceLocationResponse>(
'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.
*/
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down