Elffuss BraidHub

kikocis/continue public

627d7d0d1f85 · 2.0 KiBRawPermalink
1import * as path from "path";
2
3import { getContinueRcPath, getTsConfigPath } from "core/util/paths";
4import { Telemetry } from "core/util/posthog";
5import * as vscode from "vscode";
6
7import { VsCodeExtension } from "../extension/VsCodeExtension";
8import registerQuickFixProvider from "../lang-server/codeActions";
9import { getExtensionVersion } from "../util/util";
10
11import { VsCodeContinueApi } from "./api";
12import setupInlineTips from "./InlineTipManager";
13
14export async function activateExtension(context: vscode.ExtensionContext) {
15 // Add necessary files
16 getTsConfigPath();
17 getContinueRcPath();
18
19 // Register commands and providers
20 registerQuickFixProvider();
21 setupInlineTips(context);
22
23 const vscodeExtension = new VsCodeExtension(context);
24
25 // Load Continue configuration
26 if (!context.globalState.get("hasBeenInstalled")) {
27 void context.globalState.update("hasBeenInstalled", true);
28 void Telemetry.capture(
29 "install",
30 {
31 extensionVersion: getExtensionVersion(),
32 },
33 true,
34 );
35 }
36
37 // Register config.yaml schema by removing old entries and adding new one (uri.fsPath changes with each version)
38 const yamlMatcher = ".continue/**/*.yaml";
39 const yamlConfig = vscode.workspace.getConfiguration("yaml");
40
41 const newPath = path.join(
42 context.extension.extensionUri.fsPath,
43 "config-yaml-schema.json",
44 );
45
46 try {
47 await yamlConfig.update(
48 "schemas",
49 { [newPath]: [yamlMatcher] },
50 vscode.ConfigurationTarget.Global,
51 );
52 } catch (error) {
53 console.error(
54 "Failed to register Continue config.yaml schema, most likely, YAML extension is not installed",
55 error,
56 );
57 }
58
59 const api = new VsCodeContinueApi(vscodeExtension);
60 const continuePublicApi = {
61 registerCustomContextProvider: api.registerCustomContextProvider.bind(api),
62 };
63
64 // 'export' public api-surface
65 // or entire extension for testing
66 return process.env.NODE_ENV === "test"
67 ? {
68 ...continuePublicApi,
69 extension: vscodeExtension,
70 }
71 : continuePublicApi;
72}