Skip to content

Commit cbf466c

Browse files
committedNov 6, 2019
Add applyrefact:applyAll command as hie.commands.applyall
1 parent 0d6c537 commit cbf466c

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed
 

‎package.json

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@
184184
"command": "hie.commands.importIdentifier",
185185
"title": "Haskell: Import identifier",
186186
"description": "Imports a function or type based on a Hoogle search"
187+
},
188+
{
189+
"command": "hie.commands.applyAll",
190+
"title": "Haskell: Apply all refactorings",
191+
"description": "Applies all hlint hints to the file"
187192
}
188193
],
189194
"keybindings": [

‎src/extension.ts

+34-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ExtensionContext,
88
OutputChannel,
99
TextDocument,
10+
TextEditor,
1011
Uri,
1112
window,
1213
workspace,
@@ -210,6 +211,7 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
210211
registerHiePointCommand('hie.commands.deleteDef', 'hare:deletedef', context);
211212
registerHiePointCommand('hie.commands.genApplicative', 'hare:genapplicative', context);
212213
registerHiePointCommand('hie.commands.caseSplit', 'ghcmod:casesplit', context);
214+
registerHieFileCommand('hie.commands.applyAll', 'applyrefact:applyAll', context);
213215
hieCommandsRegistered = true;
214216
}
215217

@@ -246,18 +248,42 @@ async function isHieInstalled(): Promise<boolean> {
246248
}
247249

248250
/*
249-
* Create an editor command that calls an action on the active LSP server.
251+
* Create an editor command that calls an action on the active LSP server at a particular place in the text.
250252
*/
251253
async function registerHiePointCommand(name: string, command: string, context: ExtensionContext) {
252-
const editorCmd = commands.registerTextEditorCommand(name, (editor, edit) => {
254+
registerHieCommand(name, command, context, editor => {
255+
return [
256+
{
257+
file: editor.document.uri.toString(),
258+
pos: editor.selections[0].active
259+
}
260+
];
261+
});
262+
}
263+
264+
/*
265+
* Create an editor command that calls an action on the active LSP server for a file
266+
*/
267+
async function registerHieFileCommand(name: string, command: string, context: ExtensionContext) {
268+
registerHieCommand(name, command, context, editor => {
269+
return [editor.document.uri.toString()];
270+
});
271+
}
272+
273+
/*
274+
* Create an editor command that calls an action on the active LSP server.
275+
*/
276+
async function registerHieCommand(
277+
name: string,
278+
command: string,
279+
context: ExtensionContext,
280+
getArgs: (editor: TextEditor) => any[]
281+
) {
282+
const editorCmd = commands.registerTextEditorCommand(name, editor => {
283+
let args = getArgs(editor);
253284
const cmd = {
254285
command,
255-
arguments: [
256-
{
257-
file: editor.document.uri.toString(),
258-
pos: editor.selections[0].active
259-
}
260-
]
286+
arguments: args
261287
};
262288
// Get the current file and workspace folder.
263289
const uri = editor.document.uri;

0 commit comments

Comments
 (0)