From 573db4225f1ef7e26ed6de91a7e32890072e4279 Mon Sep 17 00:00:00 2001 From: Mic Neale Date: Thu, 10 Oct 2024 20:17:14 +1100 Subject: [PATCH] lens only show when there is space --- src/extension.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a9aa1a0..9ee7fad 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -91,21 +91,27 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(sendToGooseDisposable); + // Register code lens provider vscode.languages.registerCodeLensProvider('*', { provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken) { const editor = vscode.window.activeTextEditor; if (!editor) { return []; - } - const codeLens = new vscode.CodeLens(editor.selection, { + } + // Check for a blank line above the selection + const line = editor.selection.start.line - 1; + if (line < 0 || document.lineAt(line).isEmptyOrWhitespace) { + const codeLens = new vscode.CodeLens(editor.selection, { command: 'extension.sendToGoose', title: '🪿 Ask Goose 🪿' }); return [codeLens]; } + return []; + } }); - + // Completion suggestion: ask Goose to explain it vscode.languages.registerCodeActionsProvider('*', { provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken) {