Elffuss BraidHub

kikocis/continue public

4e7d29ea58e1 · 1.6 KiBRawPermalink
1import { EXTENSION_NAME } from "core/control-plane/env";
2import * as vscode from "vscode";
3
4class ContinueQuickFixProvider implements vscode.CodeActionProvider {
5 public static readonly providedCodeActionKinds = [
6 vscode.CodeActionKind.QuickFix,
7 ];
8
9 provideCodeActions(
10 document: vscode.TextDocument,
11 range: vscode.Range | vscode.Selection,
12 context: vscode.CodeActionContext,
13 token: vscode.CancellationToken,
14 ): vscode.ProviderResult<(vscode.Command | vscode.CodeAction)[]> {
15 if (context.diagnostics.length === 0) {
16 return [];
17 }
18
19 const diagnostic = context.diagnostics[0];
20
21 const quickFix = new vscode.CodeAction(
22 "Ask Continue",
23 vscode.CodeActionKind.QuickFix,
24 );
25
26 quickFix.isPreferred = false;
27
28 const surroundingRange = new vscode.Range(
29 Math.max(0, range.start.line - 3),
30 0,
31 Math.min(document.lineCount, range.end.line + 3),
32 0,
33 );
34
35 quickFix.command = {
36 command: "continue.quickFix",
37 title: "Continue Quick Fix",
38 arguments: [surroundingRange, diagnostic.message],
39 };
40
41 return [quickFix];
42 }
43}
44
45export default function registerQuickFixProvider() {
46 const isDisabled =
47 !!vscode.workspace
48 .getConfiguration(EXTENSION_NAME)
49 .get<boolean>("disableQuickFix") === true;
50
51 if (isDisabled) {
52 return;
53 }
54
55 // In your extension's activate function:
56 vscode.languages.registerCodeActionsProvider(
57 { language: "*" },
58 new ContinueQuickFixProvider(),
59 {
60 providedCodeActionKinds: ContinueQuickFixProvider.providedCodeActionKinds,
61 },
62 );
63}