@@ -33,7 +33,6 @@ import { activate as activateSam } from './shared/sam/activation'
33
33
import { activate as activateS3 } from './s3/activation'
34
34
import * as awsFiletypes from './shared/awsFiletypes'
35
35
import { activate as activateCodeWhisperer , shutdown as codewhispererShutdown } from './codewhisperer/activation'
36
- import { ExtContext } from './shared/extensions'
37
36
import { activate as activateApiGateway } from './apigateway/activation'
38
37
import { activate as activateStepFunctions } from './stepFunctions/activation'
39
38
import { activate as activateSsmDocument } from './ssmDocument/activation'
@@ -46,7 +45,6 @@ import { activate as activateApplicationComposer } from './applicationcomposer/a
46
45
import { activate as activateRedshift } from './redshift/activation'
47
46
import { activate as activateCWChat } from './amazonq/activation'
48
47
import { activate as activateQGumby } from './amazonqGumby/activation'
49
- import { getSamCliContext } from './shared/sam/cli/samCliContext'
50
48
import { Ec2CredentialsProvider } from './auth/providers/ec2CredentialsProvider'
51
49
import { EnvVarsCredentialsProvider } from './auth/providers/envVarsCredentialsProvider'
52
50
import { EcsCredentialsProvider } from './auth/providers/ecsCredentialsProvider'
@@ -55,58 +53,31 @@ import { AwsResourceManager } from './dynamicResources/awsResourceManager'
55
53
import globals from './shared/extensionGlobals'
56
54
import { Experiments , Settings } from './shared/settings'
57
55
import { isReleaseVersion } from './shared/vscode/env'
58
- import { Commands , registerErrorHandler as registerCommandErrorHandler } from './shared/vscode/commands2'
59
- import { UriHandler } from './shared/vscode/uriHandler'
60
56
import { telemetry } from './shared/telemetry/telemetry'
61
57
import { Auth } from './auth/auth'
62
- import { isUserCancelledError , resolveErrorMessageToDisplay , ToolkitError } from './shared/errors'
63
- import { Logging } from './shared/logger/commands'
64
- import { showMessageWithUrl , showViewLogsMessage } from './shared/utilities/messages'
65
- import { registerWebviewErrorHandler } from './webviews/server'
66
- import { ChildProcess } from './shared/utilities/childProcess'
58
+ import { showViewLogsMessage } from './shared/utilities/messages'
67
59
import { initializeNetworkAgent } from './codewhisperer/client/agent'
68
60
import { Timeout } from './shared/utilities/timeoutUtils'
69
61
import { submitFeedback } from './feedback/vue/submitFeedback'
70
- import { showQuickStartWebview } from './shared/extensionStartup'
71
- import { activateShared } from './extensionShared'
62
+ import { activateShared , deactivateShared } from './extensionShared'
72
63
73
64
let localize : nls . LocalizeFunc
74
65
66
+ /**
67
+ * The entrypoint for the nodejs version of the toolkit
68
+ *
69
+ * **CONTIBUTORS** If you are adding code to this function prioritize adding it to
70
+ * {@link activateShared} if appropriate
71
+ */
75
72
export async function activate ( context : vscode . ExtensionContext ) {
76
73
const activationStartedOn = Date . now ( )
77
74
localize = nls . loadMessageBundle ( )
78
75
79
- globals . machineId = await getMachineId ( )
80
-
81
- const remoteInvokeOutputChannel = vscode . window . createOutputChannel (
82
- localize ( 'AWS.channel.aws.remoteInvoke' , '{0} Remote Invocations' , getIdeProperties ( ) . company )
83
- )
84
-
85
- registerCommandErrorHandler ( ( info , error ) => {
86
- const defaultMessage = localize ( 'AWS.generic.message.error' , 'Failed to run command: {0}' , info . id )
87
- void logAndShowError ( error , info . id , defaultMessage )
88
- } )
89
-
90
- registerWebviewErrorHandler ( ( error : unknown , webviewId : string , command : string ) => {
91
- logAndShowWebviewError ( error , webviewId , command )
92
- } )
93
-
94
- if ( isCloud9 ( ) ) {
95
- vscode . window . withProgress = wrapWithProgressForCloud9 ( globals . outputChannel )
96
- context . subscriptions . push (
97
- Commands . register ( 'aws.quickStart' , async ( ) => {
98
- try {
99
- await showQuickStartWebview ( context )
100
- } finally {
101
- telemetry . aws_helpQuickstart . emit ( { result : 'Succeeded' } )
102
- }
103
- } )
104
- )
105
- }
106
-
107
76
try {
108
77
// IMPORTANT: If you are doing setup that should also work in browser, it should be done in the function below
109
- await activateShared ( context , ( ) => RegionProvider . fromEndpointsProvider ( makeEndpointsProvider ( ) ) )
78
+ const extContext = await activateShared ( context , ( ) =>
79
+ RegionProvider . fromEndpointsProvider ( makeEndpointsProvider ( ) )
80
+ )
110
81
111
82
initializeNetworkAgent ( )
112
83
initializeCredentialsProviderManager ( )
@@ -121,9 +92,6 @@ export async function activate(context: vscode.ExtensionContext) {
121
92
globals . awsContextCommands = new AwsContextCommands ( globals . regionProvider , Auth . instance )
122
93
globals . schemaService = new SchemaService ( )
123
94
globals . resourceManager = new AwsResourceManager ( context )
124
- // Create this now, but don't call vscode.window.registerUriHandler() until after all
125
- // Toolkit services have a chance to register their path handlers. #4105
126
- globals . uriHandler = new UriHandler ( )
127
95
128
96
const settings = Settings . instance
129
97
const experiments = Experiments . instance
@@ -139,18 +107,6 @@ export async function activate(context: vscode.ExtensionContext) {
139
107
await globals . schemaService . start ( )
140
108
awsFiletypes . activate ( )
141
109
142
- const extContext : ExtContext = {
143
- extensionContext : context ,
144
- awsContext : globals . awsContext ,
145
- samCliContext : getSamCliContext ,
146
- regionProvider : globals . regionProvider ,
147
- outputChannel : globals . outputChannel ,
148
- invokeOutputChannel : remoteInvokeOutputChannel ,
149
- telemetryService : globals . telemetry ,
150
- uriHandler : globals . uriHandler ,
151
- credentialsStore : globals . loginManager . store ,
152
- }
153
-
154
110
try {
155
111
await activateDev ( context )
156
112
} catch ( error ) {
@@ -174,7 +130,7 @@ export async function activate(context: vscode.ExtensionContext) {
174
130
context : extContext ,
175
131
regionProvider : globals . regionProvider ,
176
132
toolkitOutputChannel : globals . outputChannel ,
177
- remoteInvokeOutputChannel,
133
+ remoteInvokeOutputChannel : globals . invokeOutputChannel ,
178
134
} )
179
135
180
136
await activateCodeWhisperer ( extContext )
@@ -183,7 +139,7 @@ export async function activate(context: vscode.ExtensionContext) {
183
139
184
140
await activateApiGateway ( {
185
141
extContext : extContext ,
186
- outputChannel : remoteInvokeOutputChannel ,
142
+ outputChannel : globals . invokeOutputChannel ,
187
143
} )
188
144
189
145
await activateLambda ( extContext )
@@ -273,8 +229,8 @@ export async function activate(context: vscode.ExtensionContext) {
273
229
}
274
230
275
231
export async function deactivate ( ) {
232
+ await deactivateShared ( )
276
233
await codewhispererShutdown ( )
277
- await globals . telemetry . shutdown ( )
278
234
await globals . resourceManager . dispose ( )
279
235
}
280
236
@@ -309,87 +265,6 @@ function recordToolkitInitialization(activationStartedOn: number, settingsValid:
309
265
}
310
266
}
311
267
312
- /**
313
- * Wraps the `vscode.window.withProgress` functionality with functionality that also writes to the output channel.
314
- *
315
- * Cloud9 does not show a progress notification.
316
- */
317
- function wrapWithProgressForCloud9 ( channel : vscode . OutputChannel ) : ( typeof vscode . window ) [ 'withProgress' ] {
318
- const withProgress = vscode . window . withProgress . bind ( vscode . window )
319
-
320
- return ( options , task ) => {
321
- if ( options . title ) {
322
- channel . appendLine ( options . title )
323
- }
324
-
325
- return withProgress ( options , ( progress , token ) => {
326
- const newProgress : typeof progress = {
327
- ...progress ,
328
- report : value => {
329
- if ( value . message ) {
330
- channel . appendLine ( value . message )
331
- }
332
- progress . report ( value )
333
- } ,
334
- }
335
-
336
- return task ( newProgress , token )
337
- } )
338
- }
339
- }
340
-
341
- /**
342
- * Logs the error. Then determines what kind of error message should be shown, if
343
- * at all.
344
- *
345
- * @param error The error itself
346
- * @param topic The prefix of the error message
347
- * @param defaultMessage The message to show if once cannot be resolved from the given error
348
- *
349
- * SIDE NOTE:
350
- * This is only being used for errors from commands and webview, there's plenty of other places
351
- * (explorer, nodes, ...) where it could be used. It needs to be apart of some sort of `core`
352
- * module that is guaranteed to initialize prior to every other Toolkit component.
353
- * Logging and telemetry would fit well within this core module.
354
- */
355
- export async function logAndShowError ( error : unknown , topic : string , defaultMessage : string ) {
356
- if ( isUserCancelledError ( error ) ) {
357
- getLogger ( ) . verbose ( `${ topic } : user cancelled` )
358
- return
359
- }
360
- const logsItem = localize ( 'AWS.generic.message.viewLogs' , 'View Logs...' )
361
- const logId = getLogger ( ) . error ( `${ topic } : %s` , error )
362
- const message = resolveErrorMessageToDisplay ( error , defaultMessage )
363
-
364
- if ( error instanceof ToolkitError && error . documentationUri ) {
365
- await showMessageWithUrl ( message , error . documentationUri , 'View Documentation' , 'error' )
366
- } else {
367
- await vscode . window . showErrorMessage ( message , logsItem ) . then ( async resp => {
368
- if ( resp === logsItem ) {
369
- await Logging . declared . viewLogsAtMessage . execute ( logId )
370
- }
371
- } )
372
- }
373
- }
374
-
375
- /**
376
- * Show a webview related error to the user + button that links to the logged error
377
- *
378
- * @param err The error that was thrown in the backend
379
- * @param webviewId Arbitrary value that identifies which webview had the error
380
- * @param command The high level command/function that was run which triggered the error
381
- */
382
- export function logAndShowWebviewError ( err : unknown , webviewId : string , command : string ) {
383
- // HACK: The following implementation is a hack, influenced by the implementation of handleError().
384
- // The userFacingError message will be seen in the UI, and the detailedError message will provide the
385
- // detailed information in the logs.
386
- const detailedError = ToolkitError . chain ( err , `Webview backend command failed: "${ command } ()"` )
387
- const userFacingError = ToolkitError . chain ( detailedError , 'Webview error' )
388
- logAndShowError ( userFacingError , `webviewId="${ webviewId } "` , 'Webview error' ) . catch ( e => {
389
- getLogger ( ) . error ( 'logAndShowError failed: %s' , ( e as Error ) . message )
390
- } )
391
- }
392
-
393
268
async function checkSettingsHealth ( settings : Settings ) : Promise < boolean > {
394
269
const r = await settings . isValid ( )
395
270
switch ( r ) {
@@ -415,11 +290,6 @@ async function checkSettingsHealth(settings: Settings): Promise<boolean> {
415
290
}
416
291
}
417
292
418
- async function getMachineId ( ) : Promise < string > {
419
- const proc = new ChildProcess ( 'hostname' , [ ] , { collect : true , logging : 'no' } )
420
- return ( await proc . run ( ) ) . stdout . trim ( ) ?? 'unknown-host'
421
- }
422
-
423
293
// Unique extension entrypoint names, so that they can be obtained from the webpack bundle
424
294
export const awsToolkitActivate = activate
425
295
export const awsToolkitDeactivate = deactivate
0 commit comments