Skip to content

Commit

Permalink
Add hlint commands
Browse files Browse the repository at this point in the history
  • Loading branch information
expipiplus1 committed Aug 26, 2020
1 parent b5df91f commit 6c1d055
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export async function activate(context: ExtensionContext) {
});
context.subscriptions.push(restartCmd);

registerHiePointCommand(CommandNames.HlintApplyOneCommandName, "hlint:applyOne", context);
registerHieFileCommand(CommandNames.HlintApplyAllCommandName, "hlint:applyAll", context);
}

function findManualExecutable(uri: Uri, folder?: WorkspaceFolder): string | null {
Expand Down Expand Up @@ -247,5 +249,69 @@ function showNotInstalledErrorMessage(uri: Uri) {
}
const notInstalledMsg: string =
variant + ' executable missing, please make sure it is installed, see https://github.com' + projectUrl + '.';
window.showErrorMessage(notInstalledMsg);
workspace.showMessage(notInstalledMsg, 'error');
}


/*
* Create an editor command that calls an action on the active LSP server.
*/
async function registerHiePointCommand(name: string, command: string, context: ExtensionContext) {
registerHieCommand(name, command, context, async () => {
const { document, position } = await workspace.getCurrentState();
return [
{
file: document.uri.toString(),
pos: position
}
];
});
}

/*
* Create an editor command that calls an action on the active LSP server for a file
*/
async function registerHieFileCommand(name: string, command: string, context: ExtensionContext) {
registerHieCommand(name, command, context, async () => {
const { document } = await workspace.getCurrentState();
return [document.uri.toString()];
});
}

/*
* Create an editor command that calls an action on the active LSP server.
*/
async function registerHieCommand(
name: string,
command: string,
context: ExtensionContext,
getArgs: () => Promise<any[]>
) {
const editorCmd = commands.registerCommand(name, async () => {
const { document } = await workspace.getCurrentState();
const args = await getArgs();
workspace.showMessage(`hie: ${JSON.stringify(args)}`);
const cmd = {
command,
arguments: args
};
// Get the current file and workspace folder.
const uri = document.uri;
const folder = workspace.getWorkspaceFolder(uri);
// If there is a client registered for this workspace, use that client.
if (folder !== undefined && folder !== null && clients.has(folder.uri.toString())) {
const client = clients.get(folder.uri.toString());
if (client !== undefined && client !== null) {
client.sendRequest('workspace/executeCommand', cmd).then(
hints => {
return true;
},
e => {
console.error(e);
}
);
}
}
});
context.subscriptions.push(editorCmd);
}

0 comments on commit 6c1d055

Please sign in to comment.