@@ -8,6 +8,7 @@ import * as config from './config'
8
8
import { ExtContext } from '../shared/extensions'
9
9
import { createCommonButtons } from '../shared/ui/buttons'
10
10
import { createQuickPick } from '../shared/ui/pickerPrompter'
11
+ import { SkipPrompter } from '../shared/ui/common/skipPrompter'
11
12
import { DevSettings } from '../shared/settings'
12
13
import { FileProvider , VirtualFileSystem } from '../shared/virtualFilesystem'
13
14
import { Commands } from '../shared/vscode/commands2'
@@ -45,7 +46,7 @@ const menuOptions: Record<string, MenuOption> = {
45
46
openTerminal : {
46
47
label : 'Open Remote Terminal' ,
47
48
description : 'CodeCatalyst' ,
48
- detail : 'Open a new terminal connected to the remote environment' ,
49
+ detail : 'Opens a new terminal connected to the remote environment' ,
49
50
executor : openTerminalCommand ,
50
51
} ,
51
52
deleteDevEnv : {
@@ -55,16 +56,16 @@ const menuOptions: Record<string, MenuOption> = {
55
56
executor : deleteDevEnvCommand ,
56
57
} ,
57
58
editStorage : {
58
- label : 'Edit Storage' ,
59
+ label : 'Show or Edit Global Storage' ,
59
60
description : 'VS Code' ,
60
- detail : 'Edit a key in global /secret storage as a JSON document' ,
61
+ detail : 'Shows all globalState values, or edit a specific globalState /secret key as a JSON document' ,
61
62
executor : openStorageFromInput ,
62
63
} ,
63
- showGlobalState : {
64
- label : 'Show Global State ' ,
64
+ showEnvVars : {
65
+ label : 'Show Environment Variables ' ,
65
66
description : 'AWS Toolkit' ,
66
- detail : 'Shows various state (including environment variables) ' ,
67
- executor : showGlobalState ,
67
+ detail : 'Shows all environment variable values ' ,
68
+ executor : ( ) => showState ( 'envvars' ) ,
68
69
} ,
69
70
deleteSsoConnections : {
70
71
label : 'Auth: Delete SSO Connections' ,
@@ -78,13 +79,33 @@ const menuOptions: Record<string, MenuOption> = {
78
79
} ,
79
80
}
80
81
81
- export class GlobalStateDocumentProvider implements vscode . TextDocumentContentProvider {
82
+ /**
83
+ * Provides (readonly, as opposed to `ObjectEditor`) content for the aws-dev2:/ URI scheme.
84
+ *
85
+ * ```
86
+ * aws-dev2:/state/envvars
87
+ * aws-dev2:/state/globalstate
88
+ * ```
89
+ *
90
+ * TODO: This only purpose of this provider is to avoid an annoying unsaved, empty document that
91
+ * re-appears after vscode restart. Ideally there should be only one scheme (aws-dev:/).
92
+ */
93
+ export class DevDocumentProvider implements vscode . TextDocumentContentProvider {
94
+ constructor ( private readonly ctx : ExtContext ) { }
82
95
provideTextDocumentContent ( uri : vscode . Uri ) : string {
83
- let s = 'Environment variables known to AWS Toolkit:\n'
84
- for ( const [ k , v ] of Object . entries ( process . env ) ) {
85
- s += `${ k } =${ v } \n`
96
+ if ( uri . path === '/envvars' ) {
97
+ let s = 'Environment variables known to AWS Toolkit:\n\n'
98
+ for ( const [ k , v ] of Object . entries ( process . env ) ) {
99
+ s += `${ k } =${ v } \n`
100
+ }
101
+ return s
102
+ } else if ( uri . path === '/globalstate' ) {
103
+ // lol hax
104
+ // as of November 2023, all of a memento's properties are stored as property `f` when minified
105
+ return JSON . stringify ( ( this . ctx . extensionContext . globalState as any ) . f , undefined , 4 )
106
+ } else {
107
+ return `unknown URI path: ${ uri } `
86
108
}
87
- return s
88
109
}
89
110
}
90
111
@@ -105,7 +126,7 @@ export function activate(ctx: ExtContext): void {
105
126
ctx . extensionContext . subscriptions . push (
106
127
devSettings . onDidChangeActiveSettings ( updateMode ) ,
107
128
vscode . commands . registerCommand ( 'aws.dev.openMenu' , ( ) => openMenu ( ctx , menuOptions ) ) ,
108
- vscode . workspace . registerTextDocumentContentProvider ( 'aws-dev2' , new GlobalStateDocumentProvider ( ) )
129
+ vscode . workspace . registerTextDocumentContentProvider ( 'aws-dev2' , new DevDocumentProvider ( ctx ) )
109
130
)
110
131
111
132
updateMode ( )
@@ -130,6 +151,8 @@ async function openMenu(ctx: ExtContext, options: typeof menuOptions): Promise<v
130
151
const prompter = createQuickPick ( items , {
131
152
title : 'Developer Menu' ,
132
153
buttons : createCommonButtons ( ) ,
154
+ matchOnDescription : true ,
155
+ matchOnDetail : true ,
133
156
} )
134
157
135
158
await prompter . prompt ( )
@@ -169,12 +192,10 @@ class VirtualObjectFile implements FileProvider {
169
192
const value = ( await this . storage . get ( key ) ) ?? ''
170
193
return JSON . stringify ( JSON . parse ( value ) , undefined , 4 )
171
194
} else {
172
- if ( key ! == '' ) {
173
- return JSON . stringify ( this . storage . get ( key , { } ) , undefined , 4 )
195
+ if ( key = == '' ) {
196
+ return '(empty key)'
174
197
}
175
- // lol hax
176
- // as of November 2023, all of a memento's properties are stored as property `f` when minified
177
- return JSON . stringify ( ( this . storage as any ) . f , undefined , 4 )
198
+ return JSON . stringify ( this . storage . get ( key , { } ) , undefined , 4 )
178
199
}
179
200
}
180
201
@@ -208,8 +229,10 @@ class ObjectEditor {
208
229
vscode . workspace . registerFileSystemProvider ( ObjectEditor . scheme , this . fs )
209
230
}
210
231
211
- public async openStorage ( type : 'globals' | 'secrets' , key : string ) : Promise < void > {
232
+ public async openStorage ( type : 'globalsView' | ' globals' | 'secrets' , key : string ) : Promise < void > {
212
233
switch ( type ) {
234
+ case 'globalsView' :
235
+ return showState ( 'globalstate' )
213
236
case 'globals' :
214
237
return this . openState ( this . context . globalState , key )
215
238
case 'secrets' :
@@ -263,14 +286,15 @@ class ObjectEditor {
263
286
}
264
287
265
288
async function openStorageFromInput ( ctx : ExtContext ) {
266
- const wizard = new ( class extends Wizard < { target : 'globals' | 'secrets' ; key : string } > {
289
+ const wizard = new ( class extends Wizard < { target : 'globalsView' | ' globals' | 'secrets' ; key : string } > {
267
290
constructor ( ) {
268
291
super ( )
269
292
270
293
this . form . target . bindPrompter ( ( ) =>
271
294
createQuickPick (
272
295
[
273
- { label : 'Global State' , data : 'globals' } ,
296
+ { label : 'Show all globalState' , data : 'globalsView' } ,
297
+ { label : 'Edit globalState' , data : 'globals' } ,
274
298
{ label : 'Secrets' , data : 'secrets' } ,
275
299
] ,
276
300
{
@@ -284,7 +308,10 @@ async function openStorageFromInput(ctx: ExtContext) {
284
308
return createInputBox ( {
285
309
title : 'Enter a key' ,
286
310
} )
311
+ } else if ( target === 'globalsView' ) {
312
+ return new SkipPrompter ( '' )
287
313
} else if ( target === 'globals' ) {
314
+ // List all globalState keys in the quickpick menu.
288
315
const items = ctx . extensionContext . globalState
289
316
. keys ( )
290
317
. map ( key => {
@@ -296,12 +323,8 @@ async function openStorageFromInput(ctx: ExtContext) {
296
323
. sort ( ( a , b ) => {
297
324
return a . data . localeCompare ( b . data )
298
325
} )
299
- items . unshift ( {
300
- data : '' ,
301
- label : "SHOW ALL (edits here won't write to global state)" ,
302
- } )
303
326
304
- return createQuickPick ( items , { title : 'Pick a global state key' } )
327
+ return createQuickPick ( items , { title : 'Select a key' } )
305
328
} else {
306
329
throw new Error ( 'invalid storage target' )
307
330
}
@@ -330,8 +353,8 @@ async function expireSsoConnections() {
330
353
vscode . window . showInformationMessage ( `Expired: ${ ssoConns . map ( c => c . startUrl ) . join ( ', ' ) } ` )
331
354
}
332
355
333
- async function showGlobalState ( ) {
334
- const uri = vscode . Uri . parse ( ' aws-dev2:global- state' )
356
+ async function showState ( path : string ) {
357
+ const uri = vscode . Uri . parse ( ` aws-dev2:// state/ ${ path } ` )
335
358
const doc = await vscode . workspace . openTextDocument ( uri )
336
359
await vscode . window . showTextDocument ( doc , { preview : false } )
337
360
}
0 commit comments