forked from continuedev/continue
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathactivate.ts
More file actions
161 lines (134 loc) · 5.26 KB
/
activate.ts
File metadata and controls
161 lines (134 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { getContinueRcPath, getTsConfigPath, migrate } from "core/util/paths";
import { Telemetry } from "core/util/posthog";
import path from "node:path";
import * as vscode from "vscode";
import { VsCodeExtension } from "../extension/VsCodeExtension";
import registerQuickFixProvider from "../lang-server/codeActions";
import { getExtensionVersion } from "../util/util";
import { VsCodeContinueApi } from "./api";
import { setupInlineTips } from "./inlineTips";
import { isFirstLaunch, OLD_FIRST_LAUNCH_KEY } from "../copySettings";
export let vscodeExtension: VsCodeExtension | undefined;
export async function isVSCodeExtensionInstalled(extensionId: string): Promise<boolean> {
return vscode.extensions.getExtension(extensionId) !== undefined;
};
export async function attemptInstallExtension(extensionId: string): Promise<void> {
// Check if extension is already installed
const extension = vscode.extensions.getExtension(extensionId);
if (extension) {
// vscode.window.showInformationMessage(`Extension ${extensionId} is already installed.`);
return;
}
try {
await vscode.commands.executeCommand('workbench.extensions.installExtension', extensionId);
// vscode.window.showInformationMessage(`Successfully installed extension: ${extensionId}`);
} catch (error) {
// vscode.window.showErrorMessage(`Failed to install extension: ${extensionId}`);
console.error(error);
}
}
export async function attemptUninstallExtension(extensionId: string): Promise<void> {
// Check if extension is installed
const extension = vscode.extensions.getExtension(extensionId);
if (!extension) {
// Extension is not installed
return;
}
try {
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', extensionId);
// vscode.window.showInformationMessage(`Successfully uninstalled extension: ${extensionId}`);
} catch (error) {
// vscode.window.showErrorMessage(`Failed to uninstall extension: ${extensionId}`);
console.error(error);
}
}
export async function activateExtension(context: vscode.ExtensionContext) {
// Add necessary files
getTsConfigPath();
getContinueRcPath();
// Register commands and providers
registerQuickFixProvider();
setupInlineTips(context);
// If state is set and is true, it's not first launch
if (context.globalState.get(OLD_FIRST_LAUNCH_KEY)) {
vscode.commands.executeCommand("pearai.welcome.markNewOnboardingComplete")
// mark the old key false, so that this condition only runs once and never again.
await context.globalState.update(OLD_FIRST_LAUNCH_KEY, false);
}
vscodeExtension = new VsCodeExtension(context);
// migrate("showWelcome_1", () => {
// vscode.commands.executeCommand(
// "markdown.showPreview",
// vscode.Uri.file(
// path.join(getExtensionUri().fsPath, "media", "welcome.md"),
// ),
// );
// vscode.commands.executeCommand("pearai.focusContinueInput");
// });
// for DEV'ing welcome page
// if (true || isFirstLaunch(context)) {
// vscode.commands.executeCommand("pearai.startOnboarding");
// }
setupPearAppLayout(context);
if (isFirstLaunch(context)) {
vscode.commands.executeCommand("pearai.startOnboarding");
}
// Load PearAI configuration
if (!context.globalState.get("hasBeenInstalled")) {
context.globalState.update("hasBeenInstalled", true);
Telemetry.capture(
"install",
{
extensionVersion: getExtensionVersion(),
},
true,
);
}
// Force PearAI view mode
try {
await vscode.workspace.getConfiguration().update('workbench.sideBar.location', 'left', true);
} catch (error) {
console.dir(error);
}
// Force PearAI update mode
try {
const currentUpdateMode = vscode.workspace.getConfiguration().get('update.mode');
if (currentUpdateMode !== 'default') {
await vscode.workspace.getConfiguration().update('update.mode', 'default', true);
}
} catch (error) {
console.dir(error);
}
const api = new VsCodeContinueApi(vscodeExtension);
const continuePublicApi = {
registerCustomContextProvider: api.registerCustomContextProvider.bind(api),
};
// 'export' public api-surface
// or entire extension for testing
return {
...continuePublicApi,
extension: vscodeExtension,
};
}
// Custom Layout settings that we want default for PearAPP
const setupPearAppLayout = async (context: vscode.ExtensionContext) => {
if (!vscode.workspace.workspaceFolders) {
console.log("No workspace folders found");
vscode.commands.executeCommand("workbench.action.closeSidebar");
vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar");
} else {
// Get auxiliary bar visibility state
vscode.commands.executeCommand("workbench.action.movePearExtensionToAuxBar");
const pearAIVisible = vscode.workspace.getConfiguration().get('workbench.auxiliaryBar.visible');
// Show auxiliary bar if it's not already visible
if (!pearAIVisible) {
await vscode.commands.executeCommand('workbench.action.toggleAuxiliaryBar');
}
// Default to agent view
vscode.commands.executeCommand("pearai.focusAgentView");
}
if (isFirstLaunch(context)) {
// set activity bar position to top
vscode.commands.executeCommand("workbench.action.activityBarLocation.top");
}
};