@@ -16,7 +16,7 @@ import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
1616import { byteOffsetAt , getBinPath , getFileArchive } from './util' ;
1717import { TelemetryKey , telemetryReporter } from './goTelemetry' ;
1818
19- const COMMAND = 'gopls.modify_tags' ;
19+ export const COMMAND = 'gopls.modify_tags' ;
2020
2121// Interface for the output from gomodifytags
2222interface GomodifytagsOutput {
@@ -50,14 +50,20 @@ interface GoTagsConfig {
5050 template : string ;
5151}
5252
53- export const addTags : CommandFactory = ( _ctx , goCtx ) => async ( commandArgs : GoTagsConfig ) => {
53+ export const addTags : CommandFactory = ( _ctx , goCtx ) => async ( uri : vscode . Uri ) => {
5454 const useGoplsCommand = goCtx . serverInfo ?. Commands ?. includes ( COMMAND ) ;
5555 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+
5662 const args = getCommonArgs ( ) ;
5763 if ( ! args ) {
5864 return ;
5965 }
60- const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags , commandArgs ) ;
66+ const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags ) ;
6167 if ( ! tags && ! options ) {
6268 return ;
6369 }
@@ -75,11 +81,17 @@ export const addTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: GoTa
7581 }
7682 await vscode . commands . executeCommand ( COMMAND , args ) ;
7783 } 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+
7890 const args = getCommonArgsOld ( ) ;
7991 if ( ! args ) {
8092 return ;
8193 }
82- const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags , commandArgs ) ;
94+ const [ tags , options , transformValue , template ] = await getTagsAndOptions ( getGoConfig ( ) ?. addTags ) ;
8395 if ( ! tags && ! options ) {
8496 return ;
8597 }
@@ -103,14 +115,20 @@ export const addTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: GoTa
103115 }
104116} ;
105117
106- export const removeTags : CommandFactory = ( _ctx , goCtx ) => async ( commandArgs : GoTagsConfig ) => {
118+ export const removeTags : CommandFactory = ( _ctx , goCtx ) => async ( uri : vscode . Uri ) => {
107119 const useGoplsCommand = goCtx . serverInfo ?. Commands ?. includes ( COMMAND ) ;
108120 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+
109127 const args = getCommonArgs ( ) ;
110128 if ( ! args ) {
111129 return ;
112130 }
113- const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags , commandArgs ) ;
131+ const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags ) ;
114132 if ( ! tags && ! options ) {
115133 args . clear = true ;
116134 args . clearOptions = true ;
@@ -123,11 +141,17 @@ export const removeTags: CommandFactory = (_ctx, goCtx) => async (commandArgs: G
123141 }
124142 vscode . commands . executeCommand ( COMMAND , args ) ;
125143 } 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+
126150 const args = getCommonArgsOld ( ) ;
127151 if ( ! args ) {
128152 return ;
129153 }
130- const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags , commandArgs ) ;
154+ const [ tags , options ] = await getTagsAndOptions ( getGoConfig ( ) ?. removeTags ) ;
131155 if ( ! tags && ! options ) {
132156 args . push ( '--clear-tags' ) ;
133157 args . push ( '--clear-options' ) ;
@@ -191,31 +215,25 @@ function getCommonArgs(): GoModifyTagsArgs | undefined {
191215 return args ;
192216}
193217
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 ] ) ;
203221 }
204222
205223 const inputTags = await vscode . window . showInputBox ( {
206- value : tags ,
224+ value : config . tags ,
207225 prompt : 'Enter comma separated tag names'
208226 } ) ;
209227 const inputOptions = await vscode . window . showInputBox ( {
210- value : options ,
228+ value : config . options ,
211229 prompt : 'Enter comma separated options'
212230 } ) ;
213231 const transformOption = await vscode . window . showInputBox ( {
214- value : transformValue ,
232+ value : config . transform ,
215233 prompt : 'Enter transform value'
216234 } ) ;
217235 const template = await vscode . window . showInputBox ( {
218- value : format ,
236+ value : config . template ,
219237 prompt : 'Enter template value'
220238 } ) ;
221239 return [ inputTags , inputOptions , transformOption , template ] ;
0 commit comments