diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-07-17 13:33:29 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-07-17 13:33:29 -0700 |
commit | 1a647a7321a31d7ccf29f27e56c3df0828c3e9c8 (patch) | |
tree | 3e20e038d06449d6dff677566e1bdf6ed148eb96 /extension/src/lang-server | |
parent | 062b0872797fb4734ed36ea3a14f653dc685a86a (diff) | |
parent | d0dc7811eb71d9d53055a1aa684827502748b794 (diff) | |
download | sncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.tar.gz sncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.tar.bz2 sncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.zip |
Merge branch 'main' of https://github.com/continuedev/continue into anthropic
Diffstat (limited to 'extension/src/lang-server')
-rw-r--r-- | extension/src/lang-server/codeActions.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/extension/src/lang-server/codeActions.ts b/extension/src/lang-server/codeActions.ts new file mode 100644 index 00000000..f0d61ace --- /dev/null +++ b/extension/src/lang-server/codeActions.ts @@ -0,0 +1,55 @@ +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( + Math.max(0, range.start.line - 3), + 0, + Math.min(document.lineCount, range.end.line + 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, + } + ); +} |