Elffuss BraidHub

kikocis/continue public

e2e21eef33bd · 2.3 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 context.globalState.update("hasBeenInstalled", true);
28 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 existingSchemas = yamlConfig.get("schemas") || {};
42 const newSchemas = Object.entries(existingSchemas).filter(
43 ([_, value]) => Array.isArray(value) && value.includes(yamlMatcher), // remove old ones
44 );
45
46 const newPath = path.join(
47 context.extension.extensionUri.fsPath,
48 "config-yaml-schema.json",
49 );
50 newSchemas.push([newPath, [yamlMatcher]]);
51
52 try {
53 await yamlConfig.update(
54 "schemas",
55 Object.fromEntries(newSchemas),
56 vscode.ConfigurationTarget.Global,
57 );
58 } catch (error) {
59 console.error(
60 "Failed to register Continue config.yaml schema, most likely, YAML extension is not installed",
61 error,
62 );
63 }
64
65 const api = new VsCodeContinueApi(vscodeExtension);
66 const continuePublicApi = {
67 registerCustomContextProvider: api.registerCustomContextProvider.bind(api),
68 };
69
70 // 'export' public api-surface
71 // or entire extension for testing
72 return process.env.NODE_ENV === "test"
73 ? {
74 ...continuePublicApi,
75 extension: vscodeExtension,
76 }
77 : continuePublicApi;
78}