From 9af39a67829a6770b93ffdaa6ea70af3125c7daf Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 16 Jul 2023 12:49:47 -0700 Subject: feat: :sparkles: Continue Quick Fix --- extension/src/lang-server/codeActions.ts | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 extension/src/lang-server/codeActions.ts (limited to 'extension/src/lang-server/codeActions.ts') diff --git a/extension/src/lang-server/codeActions.ts b/extension/src/lang-server/codeActions.ts new file mode 100644 index 00000000..07cf5f4e --- /dev/null +++ b/extension/src/lang-server/codeActions.ts @@ -0,0 +1,53 @@ +import * as vscode from "vscode"; + +class ContinueQuickFixProvider implements vscode.CodeActionProvider { + public static readonly providedCodeActionKinds = [ + vscode.CodeActionKind.QuickFix, + ]; + + provideCodeActions( + document: vscode.TextDocument, + range: vscode.Range | vscode.Selection, + context: vscode.CodeActionContext, + token: vscode.CancellationToken + ): vscode.ProviderResult<(vscode.Command | vscode.CodeAction)[]> { + if (context.diagnostics.length === 0) { + return []; + } + + const createQuickFix = (edit: boolean) => { + const diagnostic = context.diagnostics[0]; + const quickFix = new vscode.CodeAction( + edit ? "Fix with Continue" : "Ask Continue", + vscode.CodeActionKind.QuickFix + ); + quickFix.isPreferred = false; + const surroundingRange = new vscode.Range( + range.start.translate(-3, 0), + range.end.translate(3, 0) + ); + quickFix.command = { + command: "continue.quickFix", + title: "Continue Quick Fix", + arguments: [ + diagnostic.message, + document.getText(surroundingRange), + edit, + ], + }; + return quickFix; + }; + return [createQuickFix(true), createQuickFix(false)]; + } +} + +export default function registerQuickFixProvider() { + // In your extension's activate function: + vscode.languages.registerCodeActionsProvider( + { language: "*" }, + new ContinueQuickFixProvider(), + { + providedCodeActionKinds: ContinueQuickFixProvider.providedCodeActionKinds, + } + ); +} -- cgit v1.2.3-70-g09d2 From 9687c05a5c8d6aeb15e7386129cdb16c0255b56e Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 16 Jul 2023 21:08:13 -0700 Subject: quick fix for quick fix --- extension/src/bridge.ts | 6 +----- extension/src/lang-server/codeActions.ts | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'extension/src/lang-server/codeActions.ts') diff --git a/extension/src/bridge.ts b/extension/src/bridge.ts index 7e6398be..d614ace4 100644 --- a/extension/src/bridge.ts +++ b/extension/src/bridge.ts @@ -1,11 +1,7 @@ import fetch from "node-fetch"; import * as path from "path"; import * as vscode from "vscode"; -import { - Configuration, - DebugApi, - UnittestApi, -} from "./client"; +import { Configuration, DebugApi, UnittestApi } from "./client"; import { convertSingleToDoubleQuoteJSON } from "./util/util"; import { getExtensionUri } from "./util/vscode"; import { extensionContext } from "./activation/activate"; diff --git a/extension/src/lang-server/codeActions.ts b/extension/src/lang-server/codeActions.ts index 07cf5f4e..f0d61ace 100644 --- a/extension/src/lang-server/codeActions.ts +++ b/extension/src/lang-server/codeActions.ts @@ -23,8 +23,10 @@ class ContinueQuickFixProvider implements vscode.CodeActionProvider { ); quickFix.isPreferred = false; const surroundingRange = new vscode.Range( - range.start.translate(-3, 0), - range.end.translate(3, 0) + Math.max(0, range.start.line - 3), + 0, + Math.min(document.lineCount, range.end.line + 3), + 0 ); quickFix.command = { command: "continue.quickFix", -- cgit v1.2.3-70-g09d2 From 96b65afeb56402c635f52d005823eeb16a0f0603 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 23 Jul 2023 16:21:24 -0700 Subject: remove quick fix, it's unreliable rn --- extension/src/lang-server/codeActions.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'extension/src/lang-server/codeActions.ts') diff --git a/extension/src/lang-server/codeActions.ts b/extension/src/lang-server/codeActions.ts index f0d61ace..892c69be 100644 --- a/extension/src/lang-server/codeActions.ts +++ b/extension/src/lang-server/codeActions.ts @@ -39,7 +39,10 @@ class ContinueQuickFixProvider implements vscode.CodeActionProvider { }; return quickFix; }; - return [createQuickFix(true), createQuickFix(false)]; + return [ + // createQuickFix(true), + createQuickFix(false), + ]; } } -- cgit v1.2.3-70-g09d2