Skip to content

Commit ea0fc64

Browse files
authored
feat: alias-refactor command (#86)
1 parent 1986b3b commit ea0fc64

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@
176176
{
177177
"command": "elixir-tools.fromPipe",
178178
"title": "Convert from pipe (Next LS)"
179+
},
180+
{
181+
"command": "elixir-tools.aliasRefactor",
182+
"title": "Refactor a module to an alias (Next LS)"
179183
}
180184
],
181185
"grammars": [
@@ -224,4 +228,4 @@
224228
"sinon": "^17.0.1",
225229
"typescript": "^4.9.5"
226230
}
227-
}
231+
}

src/commands/alias-refactor.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from "vscode";
2+
3+
import {
4+
LanguageClient,
5+
ExecuteCommandRequest,
6+
} from "vscode-languageclient/node";
7+
8+
export const run = async (client: LanguageClient) => {
9+
const position = vscode.window.activeTextEditor?.selection.start;
10+
11+
client.sendRequest(ExecuteCommandRequest.type, {
12+
command: "alias-refactor",
13+
arguments: [
14+
{
15+
uri: vscode.window.activeTextEditor?.document.uri.toString(),
16+
position: position,
17+
},
18+
],
19+
});
20+
};
21+
22+
function registerAliasRefactorCommand(
23+
client: LanguageClient,
24+
context: vscode.ExtensionContext
25+
) {
26+
const aliasRefactorCommand = "elixir-tools.aliasRefactor";
27+
const aliasRefactor = async () => run(client);
28+
context.subscriptions.push(
29+
vscode.commands.registerCommand(aliasRefactorCommand, aliasRefactor)
30+
);
31+
}
32+
33+
export default registerAliasRefactorCommand;

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import registerUninstallCommand from "./commands/uninstall";
1717
import registerToPipeCommand from "./commands/to-pipe";
1818
import registerFromPipeCommand from "./commands/from-pipe";
19+
import registerAliasRefactorCommand from "./commands/alias-refactor";
1920

2021
let credoClient: LanguageClient;
2122
let nextLSClient: LanguageClient;
@@ -193,6 +194,7 @@ async function activateNextLS(
193194
registerToPipeCommand(nextLSClient, context);
194195
registerFromPipeCommand(nextLSClient, context);
195196
registerUninstallCommand(config, context);
197+
registerAliasRefactorCommand(nextLSClient, context);
196198

197199
// Start the nextLSClient. This will also launch the server
198200
nextLSClient.start();

0 commit comments

Comments
 (0)