Skip to content

Commit f463a47

Browse files
authored
Replace CodeLens with Markdown Hover (#28)
1 parent 31863ba commit f463a47

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

client/src/extension.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function activate(context: vscode.ExtensionContext) {
2929
initStatusBar(context);
3030
initCommandPalette(context);
3131
initWebview(context);
32-
initCodeLens(context);
32+
initHover();
3333

3434
logger.client.info("Activating LiquidJava extension...");
3535

@@ -148,37 +148,26 @@ function initWebview(context: vscode.ExtensionContext) {
148148
}
149149

150150
/**
151-
* Initializes code lens with clickable "View Details" button
152-
* @param context The extension context
151+
* Initializes hover provider for LiquidJava diagnostics
153152
*/
154-
function initCodeLens(context: vscode.ExtensionContext) {
155-
const codeLensEventEmitter = new vscode.EventEmitter<void>();
156-
const codeLensProvider: vscode.CodeLensProvider = {
157-
provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[] {
153+
function initHover() {
154+
vscode.languages.registerHoverProvider('java', {
155+
provideHover(document, position) {
156+
// if webview is visible, do not show hover
157+
if (webviewProvider?.isVisible()) return null;
158+
159+
// get lj diagnostic at the current position
158160
const diagnostics = vscode.languages.getDiagnostics(document.uri);
159-
return diagnostics
160-
.filter(d => d.source === "liquidjava" && d.severity === vscode.DiagnosticSeverity.Error)
161-
.map(d => {
162-
const range = new vscode.Range(d.range.start.line, 0, d.range.end.line, 0);
163-
return new vscode.CodeLens(range, {
164-
title: "View " + (d.message.split(":")[0] || "Error"),
165-
command: "liquidjava.showView",
166-
tooltip: "Open LiquidJava View",
167-
});
168-
});
169-
},
170-
onDidChangeCodeLenses: codeLensEventEmitter.event
171-
};
172-
context.subscriptions.push(
173-
vscode.languages.registerCodeLensProvider({ language: "java" }, codeLensProvider)
174-
);
175-
// update code lenses when diagnostics change
176-
context.subscriptions.push(
177-
vscode.languages.onDidChangeDiagnostics(() => {
178-
codeLensEventEmitter.fire();
179-
})
180-
);
181-
context.subscriptions.push(codeLensEventEmitter);
161+
const diagnostic = diagnostics.find(d => d.range.contains(position) && d.source === 'liquidjava');
162+
if (!diagnostic) return null;
163+
164+
// create hover content with link to open webview
165+
const hoverContent = new vscode.MarkdownString();
166+
hoverContent.isTrusted = true;
167+
hoverContent.appendMarkdown(`\n\n[Open LiquidJava view](command:liquidjava.showView) for more details.`);
168+
return new vscode.Hover(hoverContent);
169+
}
170+
});
182171
}
183172

184173
/**

client/src/webview/provider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ export class LiquidJavaWebviewProvider implements vscode.WebviewViewProvider {
5656
this.view?.webview.postMessage(message);
5757
}
5858

59+
/**
60+
* Checks if the webview is currently visible
61+
* @returns true if the webview is visible, false otherwise
62+
*/
63+
public isVisible(): boolean {
64+
return this.view?.visible ?? false;
65+
}
66+
5967
/**
6068
* Generates the HTML content for the webview
6169
* @param webview

0 commit comments

Comments
 (0)