@@ -16,7 +16,7 @@ import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
16
16
import { byteOffsetAt , getBinPath , getFileArchive } from './util' ;
17
17
import { TelemetryKey , telemetryReporter } from './goTelemetry' ;
18
18
19
- const COMMAND = 'gopls.modify_tags' ;
19
+ export const COMMAND = 'gopls.modify_tags' ;
20
20
21
21
// Interface for the output from gomodifytags
22
22
interface GomodifytagsOutput {
@@ -50,14 +50,20 @@ interface GoTagsConfig {
50
50
template : string ;
51
51
}
52
52
53
- export const addTags : CommandFactory = ( _ctx , goCtx ) => async ( commandArgs : GoTagsConfig ) => {
53
+ export const addTags : CommandFactory = ( _ctx , goCtx ) => async ( uri : vscode . Uri ) => {
54
54
const useGoplsCommand = goCtx . serverInfo ?. Commands ?. includes ( COMMAND ) ;
55
55
if ( useGoplsCommand ) {
56
+ if ( uri ) {
57
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOPLS_MODIFY_TAGS_CONTEXT_MENU , 1 ) ;
58
+ } else {
59
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOPLS_MODIFY_TAGS_COMMAND_PALETTE , 1 ) ;
60
+ }
61
+
56
62
const args = getCommonArgs ( ) ;
57
63
if ( ! args ) {
58
64
return ;
59
65
}
60
- const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags , commandArgs ) ;
66
+ const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags ) ;
61
67
if ( ! tags && ! options ) {
62
68
return ;
63
69
}
@@ -75,11 +81,17 @@ export const addTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: GoTa
75
81
}
76
82
await vscode . commands . executeCommand ( COMMAND , args ) ;
77
83
} else {
84
+ if ( uri ) {
85
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOMODIFYTAGS_CONTEXT_MENU , 1 ) ;
86
+ } else {
87
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOMODIFYTAGS_COMMAND_PALETTE , 1 ) ;
88
+ }
89
+
78
90
const args = getCommonArgsOld ( ) ;
79
91
if ( ! args ) {
80
92
return ;
81
93
}
82
- const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags , commandArgs ) ;
94
+ const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags ) ;
83
95
if ( ! tags && ! options ) {
84
96
return ;
85
97
}
@@ -103,14 +115,20 @@ export const addTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: GoTa
103
115
}
104
116
} ;
105
117
106
- export const removeTags : CommandFactory = ( _ctx , goCtx ) => async ( commandArgs : GoTagsConfig ) => {
118
+ export const removeTags : CommandFactory = ( _ctx , goCtx ) => async ( uri : vscode . Uri ) => {
107
119
const useGoplsCommand = goCtx . serverInfo ?. Commands ?. includes ( COMMAND ) ;
108
120
if ( useGoplsCommand ) {
121
+ if ( uri ) {
122
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOPLS_MODIFY_TAGS_CONTEXT_MENU , 1 ) ;
123
+ } else {
124
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOPLS_MODIFY_TAGS_COMMAND_PALETTE , 1 ) ;
125
+ }
126
+
109
127
const args = getCommonArgs ( ) ;
110
128
if ( ! args ) {
111
129
return ;
112
130
}
113
- const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags , commandArgs ) ;
131
+ const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags ) ;
114
132
if ( ! tags && ! options ) {
115
133
args . clear = true ;
116
134
args . clearOptions = true ;
@@ -123,11 +141,17 @@ export const removeTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: G
123
141
}
124
142
vscode . commands . executeCommand ( COMMAND , args ) ;
125
143
} else {
144
+ if ( uri ) {
145
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOMODIFYTAGS_CONTEXT_MENU , 1 ) ;
146
+ } else {
147
+ telemetryReporter . add ( TelemetryKey . COMMAND_TRIGGER_GOMODIFYTAGS_COMMAND_PALETTE , 1 ) ;
148
+ }
149
+
126
150
const args = getCommonArgsOld ( ) ;
127
151
if ( ! args ) {
128
152
return ;
129
153
}
130
- const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags , commandArgs ) ;
154
+ const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags ) ;
131
155
if ( ! tags && ! options ) {
132
156
args . push ( '--clear-tags' ) ;
133
157
args . push ( '--clear-options' ) ;
@@ -191,31 +215,25 @@ function getCommonArgs(): GoModifyTagsArgs | undefined {
191
215
return args ;
192
216
}
193
217
194
- async function getTagsAndOptions ( config : GoTagsConfig , commandArgs : GoTagsConfig ) : Promise < ( string | undefined ) [ ] > {
195
- const tags = commandArgs && commandArgs . tags ? commandArgs . tags : config . tags ;
196
- const options = commandArgs && commandArgs . options ? commandArgs . options : config . options ;
197
- const promptForTags = commandArgs && commandArgs . promptForTags ? commandArgs . promptForTags : config . promptForTags ;
198
- const transformValue : string = commandArgs && commandArgs . transform ? commandArgs . transform : config . transform ;
199
- const format : string = commandArgs && commandArgs . template ? commandArgs . template : config . template ;
200
-
201
- if ( ! promptForTags ) {
202
- return Promise . resolve ( [ tags , options , transformValue , format ] ) ;
218
+ async function getTagsAndOptions ( config : GoTagsConfig ) : Promise < ( string | undefined ) [ ] > {
219
+ if ( ! config . promptForTags ) {
220
+ return Promise . resolve ( [ config . tags , config . options , config . transform , config . template ] ) ;
203
221
}
204
222
205
223
const inputTags = await vscode . window . showInputBox ( {
206
- value : tags ,
224
+ value : config . tags ,
207
225
prompt : 'Enter comma separated tag names'
208
226
} ) ;
209
227
const inputOptions = await vscode . window . showInputBox ( {
210
- value : options ,
228
+ value : config . options ,
211
229
prompt : 'Enter comma separated options'
212
230
} ) ;
213
231
const transformOption = await vscode . window . showInputBox ( {
214
- value : transformValue ,
232
+ value : config . transform ,
215
233
prompt : 'Enter transform value'
216
234
} ) ;
217
235
const template = await vscode . window . showInputBox ( {
218
- value : format ,
236
+ value : config . template ,
219
237
prompt : 'Enter template value'
220
238
} ) ;
221
239
return [ inputTags , inputOptions , transformOption , template ] ;
0 commit comments