-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwip-backup.diff
More file actions
488 lines (483 loc) · 19.2 KB
/
Copy pathwip-backup.diff
File metadata and controls
488 lines (483 loc) · 19.2 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
diff --cc src/extension.ts
index c24286080,f02f769a9..000000000
--- a/src/extension.ts
+++ b/src/extension.ts
@@@ -1,33 -1,11 +1,8 @@@
import * as vscode from "vscode"
- import * as dotenvx from "@dotenvx/dotenvx"
- import * as path from "path"
-
- // Load environment variables from .env file
- try {
- // Specify path to .env file in the project root directory
- const envPath = path.join(__dirname, "..", ".env")
- dotenvx.config({ path: envPath })
- } catch (e) {
- // Silently handle environment loading errors
- console.warn("Failed to load environment variables:", e)
- }
-
- import "./utils/path" // Necessary to have access to String.prototype.toPosix.
- import { initializeI18n } from "./i18n"
- import { TheaProvider } from "./core/webview/TheaProvider" // Renamed import
- import { CodeActionProvider } from "./core/CodeActionProvider"
- import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider" // Fixed: removed type-only import
- import { McpServerManager } from "./services/mcp/management/McpServerManager"
- import { telemetryService } from "./services/telemetry/TelemetryService"
- import { TerminalRegistry } from "./integrations/terminal/TerminalRegistry"
- import { API } from "./exports/api"
- import { migrateSettings } from "./utils/migrateSettings"
-
- import { handleUri, registerCommands, registerCodeActions, registerTerminalActions } from "./activate"
- import { formatLanguage } from "./shared/language"
- import { EXTENSION_DISPLAY_NAME, EXTENSION_NAME, configSection } from "./shared/config/thea-config"
+ // Lightweight imports only - heavy modules will be loaded dynamically
+ import { EXTENSION_DISPLAY_NAME, EXTENSION_NAME } from "./shared/config/thea-config"
-// Type-only imports (don't affect runtime)
-import type { TheaProvider as TheaProviderType } from "./core/webview/TheaProvider"
-
/**
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
*
@@@ -38,131 -16,201 +13,178 @@@
let outputChannel: vscode.OutputChannel
let extensionContext: vscode.ExtensionContext
- let provider: TheaProvider | undefined // <-- single shared provider variable
-let provider: TheaProviderType | undefined // <-- single shared provider variable
// This method is called when your extension is activated.
// Your extension is activated the very first time the command is executed.
export async function activate(context: vscode.ExtensionContext) {
- console.log('[Thea Code] activate() function called')
-
- // Detect e2e/test mode to reduce heavy startup during integration tests
- const isE2E = process.env.THEA_E2E === '1' || process.env.NODE_ENV === 'test'
- console.log(`[Thea Code] Test mode: ${isE2E}`)
-
-- extensionContext = context
-- outputChannel = vscode.window.createOutputChannel(String(EXTENSION_DISPLAY_NAME))
-- context.subscriptions.push(outputChannel)
-- outputChannel.appendLine(`${EXTENSION_DISPLAY_NAME} extension activated`)
--
- // Detect e2e/test mode to reduce heavy startup during integration tests
- const isE2E = process.env.THEA_E2E === "1" || process.env.NODE_ENV === "test"
-- outputChannel.appendLine(`Activation starting (testMode=${isE2E})`)
--
-- if (isE2E) {
-- outputChannel.appendLine("E2E mode detected: Performing lightweight activation")
--
- // Create a minimal provider and register it so commands can interact with it
- provider = new TheaProvider(context, outputChannel, "sidebar")
- context.subscriptions.push(
- vscode.window.registerWebviewViewProvider(String(TheaProvider.sideBarId), provider, {
- webviewOptions: { retainContextWhenHidden: true },
- }),
- )
- // Register minimal commands for tests without creating a provider
- const testCommands = [
- `${EXTENSION_NAME}.plusButtonClicked`,
- `${EXTENSION_NAME}.mcpButtonClicked`,
- `${EXTENSION_NAME}.historyButtonClicked`,
- `${EXTENSION_NAME}.popoutButtonClicked`,
- `${EXTENSION_NAME}.settingsButtonClicked`,
- `${EXTENSION_NAME}.openInNewTab`,
- `${EXTENSION_NAME}.explainCode`,
- `${EXTENSION_NAME}.fixCode`,
- `${EXTENSION_NAME}.improveCode`,
- ]
--
- // Register the commands expected by the tests
- registerCommands({ context, outputChannel, provider: provider! })
- // Register stub commands for testing
- for (const command of testCommands) {
- context.subscriptions.push(
- vscode.commands.registerCommand(command, () => {
- outputChannel.appendLine(`Test stub command executed: ${command}`)
- })
- )
- }
--
- // Return the API so the e2e setup can obtain it via extension.exports
- return new API(outputChannel, provider!)
- // Return a minimal API for tests
- const minimalApi = {
- outputChannel,
- isTestMode: true,
- version: context.extension.packageJSON.version
- }
-
- return minimalApi
-- }
--
- // Non-E2E activation continues here; perform full initialization safely
- // Non-E2E activation continues here with lazy loading
- outputChannel.appendLine("Starting lazy initialization...")
-
- // Load heavy modules dynamically
-- try {
- // Migrate old settings to new
- await migrateSettings(context, outputChannel)
- } catch (err) {
- outputChannel.appendLine(`migrateSettings failed in non-E2E activation: ${String(err)}`)
- }
-
- // Initialize telemetry service after environment variables are loaded.
- telemetryService.initialize()
-
- // Initialize i18n for internationalization support
- await initializeI18n(context.globalState.get("language") ?? formatLanguage(vscode.env.language))
-
- // Initialize terminal shell execution handlers.
- TerminalRegistry.initialize()
-
- // Get default commands from configuration.
- const defaultCommands =
- vscode.workspace.getConfiguration((configSection as () => string)()).get<string[]>("allowedCommands") || []
-
- // Initialize global state if not already set.
- if (!context.globalState.get("allowedCommands")) {
- context.globalState.update("allowedCommands", defaultCommands)
- }
-
- outputChannel.appendLine("Creating TheaProvider...")
- provider = new TheaProvider(context, outputChannel, "sidebar") // assign to shared variable
- outputChannel.appendLine("TheaProvider created")
- if (!isE2E) {
- // Load environment variables if needed
- try {
- const dotenvx = await import("@dotenvx/dotenvx")
- const path = await import("path")
- const envPath = path.join(__dirname, "..", ".env")
- dotenvx.config({ path: envPath })
- } catch (e) {
- // Silently handle environment loading errors
- outputChannel.appendLine(`Failed to load .env file: ${e}`)
- }
-
- // Load path utilities first
- await import("./utils/path")
-
- // Load configuration
- const { configSection } = await import("./shared/config/thea-config")
-
- // Migration and settings
- const { migrateSettings } = await import("./utils/migrateSettings")
- try {
- await migrateSettings(context, outputChannel)
- } catch (err) {
- outputChannel.appendLine(`migrateSettings failed: ${String(err)}`)
- }
-
- // Initialize telemetry
- const { telemetryService } = await import("./services/telemetry/TelemetryService")
- telemetryService.initialize()
-
- // Initialize i18n
- const { initializeI18n } = await import("./i18n")
- const { formatLanguage } = await import("./shared/language")
- await initializeI18n(context.globalState.get("language") ?? formatLanguage(vscode.env.language))
-
- // Initialize terminal
- const { TerminalRegistry } = await import("./integrations/terminal/TerminalRegistry")
- TerminalRegistry.initialize()
-
- // Get default commands from configuration
- const defaultCommands =
- vscode.workspace.getConfiguration((configSection as () => string)()).get<string[]>("allowedCommands") || []
-
- // Initialize global state if not already set
- if (!context.globalState.get("allowedCommands")) {
- context.globalState.update("allowedCommands", defaultCommands)
- }
-
- outputChannel.appendLine("Creating TheaProvider...")
- const { TheaProvider } = await import("./core/webview/TheaProvider")
- provider = new TheaProvider(context, outputChannel, "sidebar") as TheaProviderType
- outputChannel.appendLine("TheaProvider created")
-- telemetryService.setProvider(provider!)
- }
--
-- context.subscriptions.push(
-- vscode.window.registerWebviewViewProvider(String(TheaProvider.sideBarId), provider!, {
-- webviewOptions: { retainContextWhenHidden: true },
-- }),
-- )
--
- registerCommands({ context, outputChannel, provider: provider! })
- const { registerCommands } = await import("./activate")
- registerCommands({ context, outputChannel, provider: provider! })
--
-- /**
-- * We use the text document content provider API to show the left side for diff
-- * view by creating a virtual document for the original content. This makes it
-- * readonly so users know to edit the right side if they want to keep their changes.
-- *
-- * This API allows you to create readonly documents in VSCode from arbitrary
-- * sources, and works by claiming an uri-scheme for which your provider then
-- * returns text contents. The scheme must be provided when registering a
-- * provider and cannot change afterwards.
-- *
-- * Note how the provider doesn't create uris for virtual documents - its role
-- * is to provide contents given such an uri. In return, content providers are
-- * wired into the open document logic so that providers are always considered.
-- *
-- * https://code.visualstudio.com/api/extension-guides/virtual-documents
-- */
- const diffContentProvider = new (class implements vscode.TextDocumentContentProvider {
- provideTextDocumentContent(uri: vscode.Uri): string {
- return Buffer.from(uri.query, "base64").toString("utf-8")
- }
- })()
-
- context.subscriptions.push(
- vscode.workspace.registerTextDocumentContentProvider(DIFF_VIEW_URI_SCHEME, diffContentProvider),
- )
-
- context.subscriptions.push(vscode.window.registerUriHandler({ handleUri }))
-
- // Register code actions provider.
- context.subscriptions.push(
- vscode.languages.registerCodeActionsProvider({ pattern: "**/*" }, new CodeActionProvider(), {
- providedCodeActionKinds: CodeActionProvider.providedCodeActionKinds,
- }),
- )
-
- registerCodeActions(context)
- registerTerminalActions(context)
- // Register diff view provider
- const { DIFF_VIEW_URI_SCHEME } = await import("./integrations/editor/DiffViewProvider")
- const diffContentProvider = new (class implements vscode.TextDocumentContentProvider {
- provideTextDocumentContent(uri: vscode.Uri): string {
- return Buffer.from(uri.query, "base64").toString("utf-8")
- }
- })()
-
- context.subscriptions.push(
- vscode.workspace.registerTextDocumentContentProvider(DIFF_VIEW_URI_SCHEME, diffContentProvider),
- )
-
- const { handleUri } = await import("./activate")
- context.subscriptions.push(vscode.window.registerUriHandler({ handleUri }))
--
- // Allows other extensions to activate once Thea is ready.
- vscode.commands.executeCommand(`${EXTENSION_NAME}.activationCompleted`)
- // Register code actions provider
- const { CodeActionProvider } = await import("./core/CodeActionProvider")
- context.subscriptions.push(
- vscode.languages.registerCodeActionsProvider({ pattern: "**/*" }, new CodeActionProvider(), {
- providedCodeActionKinds: CodeActionProvider.providedCodeActionKinds,
- }),
- )
-
- const { registerCodeActions, registerTerminalActions } = await import("./activate")
- registerCodeActions(context)
- registerTerminalActions(context)
--
- // Implements the `TheaCodeAPI` interface.
- return new API(outputChannel, provider!)
- // Allows other extensions to activate once Thea is ready
- vscode.commands.executeCommand(`${EXTENSION_NAME}.activationCompleted`)
-
- // Return the API
- const { API } = await import("./exports/api")
- return new API(outputChannel, provider!)
- } catch (error) {
- outputChannel.appendLine(`Failed to initialize extension: ${error}`)
- console.error('[Thea Code] Failed to initialize:', error)
- throw error
- }
++ console.log('[Thea Code] activate() function called')
++
++ // Detect e2e/test mode to reduce heavy startup during integration tests
++ const isE2E = process.env.THEA_E2E === '1' || process.env.NODE_ENV === 'test'
++ console.log(`[Thea Code] Test mode: ${isE2E}`)
++
++ extensionContext = context
++ outputChannel = vscode.window.createOutputChannel(String(EXTENSION_DISPLAY_NAME))
++ context.subscriptions.push(outputChannel)
++ outputChannel.appendLine(`${EXTENSION_DISPLAY_NAME} extension activated`)
++ outputChannel.appendLine(`Activation starting (testMode=${isE2E})`)
++
++ if (isE2E) {
++ outputChannel.appendLine("E2E mode detected: Performing lightweight activation")
++
++ // Register minimal commands for tests without creating a provider
++ const testCommands = [
++ `${EXTENSION_NAME}.plusButtonClicked`,
++ `${EXTENSION_NAME}.mcpButtonClicked`,
++ `${EXTENSION_NAME}.historyButtonClicked`,
++ `${EXTENSION_NAME}.popoutButtonClicked`,
++ `${EXTENSION_NAME}.settingsButtonClicked`,
++ `${EXTENSION_NAME}.openInNewTab`,
++ `${EXTENSION_NAME}.explainCode`,
++ `${EXTENSION_NAME}.fixCode`,
++ `${EXTENSION_NAME}.improveCode`,
++ ]
++
++ for (const command of testCommands) {
++ context.subscriptions.push(
++ vscode.commands.registerCommand(command, () => {
++ outputChannel.appendLine(`Test stub command executed: ${command}`)
++ }),
++ )
++ }
++
++ // Return a minimal API for tests
++ const minimalApi = {
++ outputChannel,
++ isTestMode: true,
++ version: context.extension.packageJSON.version,
++ }
++ return minimalApi
++ }
++
++ // Non-E2E activation continues here with lazy loading
++ outputChannel.appendLine("Starting lazy initialization...")
++
++ try {
++ // Load environment variables if needed
++ try {
++ const dotenvx = await import("@dotenvx/dotenvx")
++ const path = await import("path")
++ const envPath = path.join(__dirname, "..", ".env")
++ dotenvx.config({ path: envPath })
++ } catch (e) {
++ outputChannel.appendLine(`Failed to load .env file: ${e}`)
++ }
++
++ // Load path utilities first
++ await import("./utils/path")
++
++ // Load configuration
++ const { configSection } = await import("./shared/config/thea-config")
++
++ // Migration and settings
++ const { migrateSettings } = await import("./utils/migrateSettings")
++ try {
++ await migrateSettings(context, outputChannel)
++ } catch (err) {
++ outputChannel.appendLine(`migrateSettings failed: ${String(err)}`)
++ }
++
++ // Initialize telemetry
++ const { telemetryService } = await import("./services/telemetry/TelemetryService")
++ telemetryService.initialize()
++
++ // Initialize i18n
++ const { initializeI18n } = await import("./i18n")
++ const { formatLanguage } = await import("./shared/language")
++ await initializeI18n(context.globalState.get("language") ?? formatLanguage(vscode.env.language))
++
++ // Initialize terminal
++ const { TerminalRegistry } = await import("./integrations/terminal/TerminalRegistry")
++ TerminalRegistry.initialize()
++
++ // Get default commands from configuration
++ const defaultCommands =
++ vscode.workspace.getConfiguration((configSection as () => string)()).get<string[]>("allowedCommands") || []
++
++ if (!context.globalState.get("allowedCommands")) {
++ context.globalState.update("allowedCommands", defaultCommands)
++ }
++
++ outputChannel.appendLine("Creating TheaProvider...")
++ const { TheaProvider } = await import("./core/webview/TheaProvider")
++ const theaProvider = new TheaProvider(context, outputChannel, "sidebar")
++ outputChannel.appendLine("TheaProvider created")
++ telemetryService.setProvider(theaProvider)
++
++ context.subscriptions.push(
++ vscode.window.registerWebviewViewProvider(String(TheaProvider.sideBarId), theaProvider, {
++ webviewOptions: { retainContextWhenHidden: true },
++ }),
++ )
++
++ const { registerCommands } = await import("./activate")
++ registerCommands({ context, outputChannel, provider: theaProvider })
++
++ // Register diff view provider
++ const { DIFF_VIEW_URI_SCHEME } = await import("./integrations/editor/DiffViewProvider")
++ const diffContentProvider = new (class implements vscode.TextDocumentContentProvider {
++ provideTextDocumentContent(uri: vscode.Uri): string {
++ return Buffer.from(uri.query, "base64").toString("utf-8")
++ }
++ })()
++
++ context.subscriptions.push(
++ vscode.workspace.registerTextDocumentContentProvider(DIFF_VIEW_URI_SCHEME, diffContentProvider),
++ )
++
++ const { handleUri } = await import("./activate")
++ context.subscriptions.push(vscode.window.registerUriHandler({ handleUri }))
++
++ // Register code actions provider
++ const { CodeActionProvider } = await import("./core/CodeActionProvider")
++ context.subscriptions.push(
++ vscode.languages.registerCodeActionsProvider({ pattern: "**/*" }, new CodeActionProvider(), {
++ providedCodeActionKinds: CodeActionProvider.providedCodeActionKinds,
++ }),
++ )
++
++ const { registerCodeActions, registerTerminalActions } = await import("./activate")
++ registerCodeActions(context)
++ registerTerminalActions(context)
++
++ // Allows other extensions to activate once Thea is ready
++ vscode.commands.executeCommand(`${EXTENSION_NAME}.activationCompleted`)
++
++ // Return the API
++ const { API } = await import("./exports/api")
++ return new API(outputChannel, theaProvider)
++ } catch (error) {
++ outputChannel.appendLine(`Failed to initialize extension: ${error}`)
++ console.error('[Thea Code] Failed to initialize:', error)
++ throw error
++ }
}
// This method is called when your extension is deactivated
export async function deactivate() {
- outputChannel.appendLine(`${EXTENSION_DISPLAY_NAME} extension deactivated`)
- // Clean up MCP server manager
- await McpServerManager.cleanup(extensionContext)
- await telemetryService.shutdown()
-
- // Clean up terminal handlers
- TerminalRegistry.cleanup()
- if (outputChannel) {
- outputChannel.appendLine(`${EXTENSION_DISPLAY_NAME} extension deactivated`)
- }
-
- // Only cleanup if modules were loaded
- try {
- const { McpServerManager } = await import("./services/mcp/management/McpServerManager")
- await McpServerManager.cleanup(extensionContext)
- } catch {}
-
- try {
- const { telemetryService } = await import("./services/telemetry/TelemetryService")
- await telemetryService.shutdown()
- } catch {}
-
- try {
- const { TerminalRegistry } = await import("./integrations/terminal/TerminalRegistry")
- TerminalRegistry.cleanup()
- } catch {}
++ if (outputChannel) {
++ outputChannel.appendLine(`${EXTENSION_DISPLAY_NAME} extension deactivated`)
++ }
++
++ // Only cleanup if modules were loaded
++ try {
++ const { McpServerManager } = await import("./services/mcp/management/McpServerManager")
++ await McpServerManager.cleanup(extensionContext)
++ } catch {}
++
++ try {
++ const { telemetryService } = await import("./services/telemetry/TelemetryService")
++ await telemetryService.shutdown()
++ } catch {}
++
++ try {
++ const { TerminalRegistry } = await import("./integrations/terminal/TerminalRegistry")
++ TerminalRegistry.cleanup()
++ } catch {}
}