Skip to content

Commit

Permalink
feat: alias-refactor command (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Apr 20, 2024
1 parent 1986b3b commit ea0fc64
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
{
"command": "elixir-tools.fromPipe",
"title": "Convert from pipe (Next LS)"
},
{
"command": "elixir-tools.aliasRefactor",
"title": "Refactor a module to an alias (Next LS)"
}
],
"grammars": [
Expand Down Expand Up @@ -224,4 +228,4 @@
"sinon": "^17.0.1",
"typescript": "^4.9.5"
}
}
}
33 changes: 33 additions & 0 deletions src/commands/alias-refactor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as vscode from "vscode";

import {
LanguageClient,
ExecuteCommandRequest,
} from "vscode-languageclient/node";

export const run = async (client: LanguageClient) => {
const position = vscode.window.activeTextEditor?.selection.start;

client.sendRequest(ExecuteCommandRequest.type, {
command: "alias-refactor",
arguments: [
{
uri: vscode.window.activeTextEditor?.document.uri.toString(),
position: position,
},
],
});
};

function registerAliasRefactorCommand(
client: LanguageClient,
context: vscode.ExtensionContext
) {
const aliasRefactorCommand = "elixir-tools.aliasRefactor";
const aliasRefactor = async () => run(client);
context.subscriptions.push(
vscode.commands.registerCommand(aliasRefactorCommand, aliasRefactor)
);
}

export default registerAliasRefactorCommand;
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import registerUninstallCommand from "./commands/uninstall";
import registerToPipeCommand from "./commands/to-pipe";
import registerFromPipeCommand from "./commands/from-pipe";
import registerAliasRefactorCommand from "./commands/alias-refactor";

let credoClient: LanguageClient;
let nextLSClient: LanguageClient;
Expand Down Expand Up @@ -193,6 +194,7 @@ async function activateNextLS(
registerToPipeCommand(nextLSClient, context);
registerFromPipeCommand(nextLSClient, context);
registerUninstallCommand(config, context);
registerAliasRefactorCommand(nextLSClient, context);

// Start the nextLSClient. This will also launch the server
nextLSClient.start();
Expand Down

0 comments on commit ea0fc64

Please sign in to comment.