Elffuss BraidHub

kikocis/continue public

main · 4.5 KiBRawPermalink
1import { ContinueConfig } from "core";
2import * as vscode from "vscode";
3
4import { VerticalDiffCodeLens } from "../../diff/vertical/manager";
5
6import * as providers from "./providers";
7import {
8 getQuickActionsConfig,
9 quickActionsEnabledStatus,
10 subscribeToVSCodeQuickActionsSettings,
11} from "./providers/QuickActionsCodeLensProvider";
12
13const { registerCodeLensProvider } = vscode.languages;
14
15export let verticalPerLineCodeLensProvider: vscode.Disposable | undefined =
16 undefined;
17let diffsCodeLensDisposable: vscode.Disposable | undefined = undefined;
18let suggestionsCodeLensDisposable: vscode.Disposable | undefined = undefined;
19let configPyCodeLensDisposable: vscode.Disposable | undefined = undefined;
20let tutorialCodeLensDisposable: vscode.Disposable | undefined = undefined;
21let quickActionsCodeLensDisposable: vscode.Disposable | undefined = undefined;
22let configJsonConverterCodeLensDisposable: vscode.Disposable | undefined =
23 undefined;
24let downloadYamlExtensionCodeLensDisposable: vscode.Disposable | undefined =
25 undefined;
26
27/**
28 * Registers the Quick Actions CodeLens provider if Quick Actions are enabled.
29 *
30 * This function checks if Quick Actions are enabled in the VSCode workspace settings,
31 * and if so, it registers a new QuickActionsCodeLensProvider. If the user has custom
32 * actions defined in their config, it initiaizes the provider with these actions.
33 *
34 * If a previous provider was registered, it is disposed of before the new one is created.
35 *
36 * @param config - The Continue configuration object
37 * @param context - The VS Code extension context
38 */
39function registerQuickActionsProvider(
40 config: ContinueConfig,
41 context: vscode.ExtensionContext,
42) {
43 if (quickActionsCodeLensDisposable) {
44 quickActionsCodeLensDisposable.dispose();
45 }
46
47 if (quickActionsEnabledStatus()) {
48 const quickActionsConfig = getQuickActionsConfig(config);
49
50 quickActionsCodeLensDisposable = registerCodeLensProvider(
51 "*",
52 new providers.QuickActionsCodeLensProvider(quickActionsConfig),
53 );
54
55 context.subscriptions.push(quickActionsCodeLensDisposable);
56 }
57}
58
59/**
60 * Registers all CodeLens providers for the Continue extension.
61 *
62 * This function disposes of any existing CodeLens providers and registers new ones for:
63 * - Vertical per-line diffs
64 * - Suggestions
65 * - Diff viewer
66 * - Config.py
67 * - Tutorial
68 * - Quick Actions
69 *
70 * It also sets up a subscription to VS Code Quick Actions settings changes.
71 *
72 * @param context - The VS Code extension context
73 * @param editorToVerticalDiffCodeLens - A Map of editor IDs to VerticalDiffCodeLens arrays
74 * @param config - The Continue configuration object
75 *
76 * @returns An object containing the verticalDiffCodeLens provider
77 */
78export function registerAllCodeLensProviders(
79 context: vscode.ExtensionContext,
80 editorToVerticalDiffCodeLens: Map<string, VerticalDiffCodeLens[]>,
81 config: ContinueConfig | undefined,
82) {
83 if (verticalPerLineCodeLensProvider) {
84 verticalPerLineCodeLensProvider.dispose();
85 }
86
87 if (suggestionsCodeLensDisposable) {
88 suggestionsCodeLensDisposable.dispose();
89 }
90
91 if (diffsCodeLensDisposable) {
92 diffsCodeLensDisposable.dispose();
93 }
94
95 if (configPyCodeLensDisposable) {
96 configPyCodeLensDisposable.dispose();
97 }
98
99 if (tutorialCodeLensDisposable) {
100 tutorialCodeLensDisposable.dispose();
101 }
102
103 if (configJsonConverterCodeLensDisposable) {
104 configJsonConverterCodeLensDisposable.dispose();
105 }
106
107 if (downloadYamlExtensionCodeLensDisposable) {
108 downloadYamlExtensionCodeLensDisposable.dispose();
109 }
110
111 const verticalDiffCodeLens = new providers.VerticalPerLineCodeLensProvider(
112 editorToVerticalDiffCodeLens,
113 );
114
115 verticalPerLineCodeLensProvider = registerCodeLensProvider(
116 "*",
117 verticalDiffCodeLens,
118 );
119
120 suggestionsCodeLensDisposable = registerCodeLensProvider(
121 "*",
122 new providers.SuggestionsCodeLensProvider(),
123 );
124
125 configJsonConverterCodeLensDisposable = registerCodeLensProvider(
126 "*",
127 new providers.ConfigJsonConverterCodeLensProvider(),
128 );
129
130 downloadYamlExtensionCodeLensDisposable = registerCodeLensProvider(
131 "yaml",
132 new providers.DownloadYamlExtensionCodeLensProvider(),
133 );
134
135 if (config) {
136 registerQuickActionsProvider(config, context);
137
138 subscribeToVSCodeQuickActionsSettings(() =>
139 registerQuickActionsProvider(config, context),
140 );
141 }
142
143 context.subscriptions.push(verticalPerLineCodeLensProvider);
144 context.subscriptions.push(suggestionsCodeLensDisposable);
145 context.subscriptions.push(configJsonConverterCodeLensDisposable);
146
147 return { verticalDiffCodeLens };
148}