@@ -58,6 +58,8 @@ export async function activate(context: ExtensionContext) {
58
58
} ) ;
59
59
context . subscriptions . push ( restartCmd ) ;
60
60
61
+ registerHiePointCommand ( CommandNames . HlintApplyOneCommandName , "hlint:applyOne" , context ) ;
62
+ registerHieFileCommand ( CommandNames . HlintApplyAllCommandName , "hlint:applyAll" , context ) ;
61
63
}
62
64
63
65
function findManualExecutable ( uri : Uri , folder ?: WorkspaceFolder ) : string | null {
@@ -247,5 +249,69 @@ function showNotInstalledErrorMessage(uri: Uri) {
247
249
}
248
250
const notInstalledMsg : string =
249
251
variant + ' executable missing, please make sure it is installed, see https://github.com' + projectUrl + '.' ;
250
- window . showErrorMessage ( notInstalledMsg ) ;
252
+ workspace . showMessage ( notInstalledMsg , 'error' ) ;
253
+ }
254
+
255
+
256
+ /*
257
+ * Create an editor command that calls an action on the active LSP server.
258
+ */
259
+ async function registerHiePointCommand ( name : string , command : string , context : ExtensionContext ) {
260
+ registerHieCommand ( name , command , context , async ( ) => {
261
+ const { document, position } = await workspace . getCurrentState ( ) ;
262
+ return [
263
+ {
264
+ file : document . uri . toString ( ) ,
265
+ pos : position
266
+ }
267
+ ] ;
268
+ } ) ;
269
+ }
270
+
271
+ /*
272
+ * Create an editor command that calls an action on the active LSP server for a file
273
+ */
274
+ async function registerHieFileCommand ( name : string , command : string , context : ExtensionContext ) {
275
+ registerHieCommand ( name , command , context , async ( ) => {
276
+ const { document } = await workspace . getCurrentState ( ) ;
277
+ return [ document . uri . toString ( ) ] ;
278
+ } ) ;
279
+ }
280
+
281
+ /*
282
+ * Create an editor command that calls an action on the active LSP server.
283
+ */
284
+ async function registerHieCommand (
285
+ name : string ,
286
+ command : string ,
287
+ context : ExtensionContext ,
288
+ getArgs : ( ) => Promise < any [ ] >
289
+ ) {
290
+ const editorCmd = commands . registerCommand ( name , async ( ) => {
291
+ const { document } = await workspace . getCurrentState ( ) ;
292
+ const args = await getArgs ( ) ;
293
+ workspace . showMessage ( `hie: ${ JSON . stringify ( args ) } ` ) ;
294
+ const cmd = {
295
+ command,
296
+ arguments : args
297
+ } ;
298
+ // Get the current file and workspace folder.
299
+ const uri = document . uri ;
300
+ const folder = workspace . getWorkspaceFolder ( uri ) ;
301
+ // If there is a client registered for this workspace, use that client.
302
+ if ( folder !== undefined && folder !== null && clients . has ( folder . uri . toString ( ) ) ) {
303
+ const client = clients . get ( folder . uri . toString ( ) ) ;
304
+ if ( client !== undefined && client !== null ) {
305
+ client . sendRequest ( 'workspace/executeCommand' , cmd ) . then (
306
+ hints => {
307
+ return true ;
308
+ } ,
309
+ e => {
310
+ console . error ( e ) ;
311
+ }
312
+ ) ;
313
+ }
314
+ }
315
+ } ) ;
316
+ context . subscriptions . push ( editorCmd ) ;
251
317
}
0 commit comments