Elffuss BraidHub

kikocis/continue public

main · 2.8 KiBRawPermalink
1import { getContinueRcPath, getTsConfigPath } from "core/util/paths";
2import { Telemetry } from "core/util/posthog";
3import * as vscode from "vscode";
4
5import { VsCodeExtension } from "../extension/VsCodeExtension";
6import { getExtensionVersion, isUnsupportedPlatform } from "../util/util";
7
8import { GlobalContext } from "core/util/GlobalContext";
9import { VsCodeContinueApi } from "./api";
10import setupInlineTips from "./InlineTipManager";
11
12export async function activateExtension(context: vscode.ExtensionContext) {
13 const platformCheck = isUnsupportedPlatform();
14 const globalContext = new GlobalContext();
15 const hasShownUnsupportedPlatformWarning = globalContext.get(
16 "hasShownUnsupportedPlatformWarning",
17 );
18
19 if (platformCheck.isUnsupported && !hasShownUnsupportedPlatformWarning) {
20 const platformTarget = "windows-arm64";
21
22 globalContext.update("hasShownUnsupportedPlatformWarning", true);
23 void vscode.window.showInformationMessage(
24 `Continue detected that you are using ${platformTarget}. Due to native dependencies, Continue may not be able to start`,
25 );
26
27 void Telemetry.capture(
28 "unsupported_platform_activation_attempt",
29 {
30 platform: platformTarget,
31 extensionVersion: getExtensionVersion(),
32 reason: platformCheck.reason,
33 },
34 true,
35 );
36 }
37
38 // Add necessary files
39 getTsConfigPath();
40 getContinueRcPath();
41
42 // Register commands and providers
43 setupInlineTips(context);
44
45 const vscodeExtension = new VsCodeExtension(context);
46
47 // Load Continue configuration
48 if (!context.globalState.get("hasBeenInstalled")) {
49 void context.globalState.update("hasBeenInstalled", true);
50 void Telemetry.capture(
51 "install",
52 {
53 extensionVersion: getExtensionVersion(),
54 },
55 true,
56 );
57 }
58
59 // Register config.yaml schema by removing old entries and adding new one (uri.fsPath changes with each version)
60 const yamlMatcher = ".continue/**/*.yaml";
61 const yamlConfig = vscode.workspace.getConfiguration("yaml");
62
63 const newPath = vscode.Uri.joinPath(
64 context.extension.extensionUri,
65 "config-yaml-schema.json",
66 ).toString();
67
68 try {
69 await yamlConfig.update(
70 "schemas",
71 { [newPath]: [yamlMatcher] },
72 vscode.ConfigurationTarget.Global,
73 );
74 } catch (error) {
75 console.error(
76 "Failed to register Continue config.yaml schema, most likely, YAML extension is not installed",
77 error,
78 );
79 }
80
81 const api = new VsCodeContinueApi(vscodeExtension);
82 const continuePublicApi = {
83 registerCustomContextProvider: api.registerCustomContextProvider.bind(api),
84 };
85
86 // 'export' public api-surface
87 // or entire extension for testing
88 return process.env.NODE_ENV === "test"
89 ? {
90 ...continuePublicApi,
91 extension: vscodeExtension,
92 }
93 : continuePublicApi;
94}