@@ -11,6 +11,15 @@ const localize = nls.loadMessageBundle();
11
11
const TEXT_ALWAYS = localize ( 'status.text.auto.attach.always' , 'Auto Attach: Always' ) ;
12
12
const TEXT_SMART = localize ( 'status.text.auto.attach.smart' , 'Auto Attach: Smart' ) ;
13
13
const TEXT_WITH_FLAG = localize ( 'status.text.auto.attach.withFlag' , 'Auto Attach: With Flag' ) ;
14
+ const TEXT_STATE_LABEL = {
15
+ [ State . Disabled ] : localize ( 'debug.javascript.autoAttach.disabled.label' , 'Disabled' ) ,
16
+ [ State . Always ] : localize ( 'debug.javascript.autoAttach.always.label' , 'Always' ) ,
17
+ [ State . Smart ] : localize ( 'debug.javascript.autoAttach.smart.label' , 'Smart' ) ,
18
+ [ State . OnlyWithFlag ] : localize (
19
+ 'debug.javascript.autoAttach.onlyWithFlag.label' ,
20
+ 'Only With Flag' ,
21
+ ) ,
22
+ } ;
14
23
const TEXT_STATE_DESCRIPTION = {
15
24
[ State . Disabled ] : localize (
16
25
'debug.javascript.autoAttach.disabled.description' ,
@@ -29,6 +38,8 @@ const TEXT_STATE_DESCRIPTION = {
29
38
'Only auto attach when the `--inspect` flag is given' ,
30
39
) ,
31
40
} ;
41
+ const TEXT_TOGGLE_WORKSPACE = localize ( 'scope.workspace' , 'Toggle auto attach in this workspace' ) ;
42
+ const TEXT_TOGGLE_GLOBAL = localize ( 'scope.global' , 'Toggle auto attach on this machine' ) ;
32
43
33
44
const TOGGLE_COMMAND = 'extension.node-debug.toggleAutoAttach' ;
34
45
const STORAGE_IPC = 'jsDebugIpcState' ;
@@ -82,11 +93,6 @@ export async function deactivate(): Promise<void> {
82
93
await destroyAttachServer ( ) ;
83
94
}
84
95
85
- type StatePickItem =
86
- | ( vscode . QuickPickItem & { state : State } )
87
- | ( vscode . QuickPickItem & { scope : vscode . ConfigurationTarget } )
88
- | ( vscode . QuickPickItem & { type : 'separator' } ) ;
89
-
90
96
function getDefaultScope ( info : ReturnType < vscode . WorkspaceConfiguration [ 'inspect' ] > ) {
91
97
if ( ! info ) {
92
98
return vscode . ConfigurationTarget . Global ;
@@ -101,39 +107,44 @@ function getDefaultScope(info: ReturnType<vscode.WorkspaceConfiguration['inspect
101
107
return vscode . ConfigurationTarget . Global ;
102
108
}
103
109
110
+ type PickResult = { state : State } | { scope : vscode . ConfigurationTarget } | undefined ;
111
+
104
112
async function toggleAutoAttachSetting ( scope ?: vscode . ConfigurationTarget ) : Promise < void > {
105
113
const section = vscode . workspace . getConfiguration ( SETTING_SECTION ) ;
106
114
scope = scope || getDefaultScope ( section . inspect ( SETTING_STATE ) ) ;
107
115
108
- const stateItems = [ State . Always , State . Smart , State . OnlyWithFlag , State . Disabled ] . map ( state => ( {
116
+ const isGlobalScope = scope === vscode . ConfigurationTarget . Global ;
117
+ const quickPick = vscode . window . createQuickPick < vscode . QuickPickItem & { state : State } > ( ) ;
118
+ const current = readCurrentState ( ) ;
119
+
120
+ quickPick . items = [ State . Always , State . Smart , State . OnlyWithFlag , State . Disabled ] . map ( state => ( {
109
121
state,
110
- label : state . slice ( 0 , 1 ) . toUpperCase ( ) + state . slice ( 1 ) ,
122
+ label : TEXT_STATE_LABEL [ state ] ,
111
123
description : TEXT_STATE_DESCRIPTION [ state ] ,
112
124
alwaysShow : true ,
113
125
} ) ) ;
114
126
115
- const scopeItem =
116
- scope === vscode . ConfigurationTarget . Global
117
- ? {
118
- label : localize ( 'scope.workspace' , 'Toggle in this workspace $(arrow-right)' ) ,
119
- scope : vscode . ConfigurationTarget . Workspace ,
120
- }
121
- : {
122
- label : localize ( 'scope.global' , 'Toggle for this machine $(arrow-right)' ) ,
123
- scope : vscode . ConfigurationTarget . Global ,
124
- } ;
125
-
126
- const quickPick = vscode . window . createQuickPick < StatePickItem > ( ) ;
127
- // todo: have a separator here, see https://github.com/microsoft/vscode/issues/74967
128
- quickPick . items = [ ...stateItems , scopeItem ] ;
127
+ quickPick . activeItems = quickPick . items . filter ( i => i . state === current ) ;
128
+ quickPick . title = isGlobalScope ? TEXT_TOGGLE_GLOBAL : TEXT_TOGGLE_WORKSPACE ;
129
+ quickPick . buttons = [
130
+ {
131
+ iconPath : new vscode . ThemeIcon ( isGlobalScope ? 'folder' : 'globe' ) ,
132
+ tooltip : isGlobalScope ? TEXT_TOGGLE_WORKSPACE : TEXT_TOGGLE_GLOBAL ,
133
+ } ,
134
+ ] ;
129
135
130
136
quickPick . show ( ) ;
131
- const current = readCurrentState ( ) ;
132
- quickPick . activeItems = stateItems . filter ( i => i . state === current ) ;
133
137
134
- const result = await new Promise < StatePickItem | undefined > ( resolve => {
138
+ const result = await new Promise < PickResult > ( resolve => {
135
139
quickPick . onDidAccept ( ( ) => resolve ( quickPick . selectedItems [ 0 ] ) ) ;
136
140
quickPick . onDidHide ( ( ) => resolve ( ) ) ;
141
+ quickPick . onDidTriggerButton ( ( ) => {
142
+ resolve ( {
143
+ scope : isGlobalScope
144
+ ? vscode . ConfigurationTarget . Workspace
145
+ : vscode . ConfigurationTarget . Global ,
146
+ } ) ;
147
+ } ) ;
137
148
} ) ;
138
149
139
150
quickPick . dispose ( ) ;
0 commit comments