Skip to content

Commit

Permalink
Add a custom command to trigger mix clean inside language server (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Sep 19, 2022
1 parent d4bc10b commit c683f43
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,16 @@
"command": "extension.restart",
"title": "Restart language server"
},
{
"category": "Elixir",
"command": "extension.mixClean",
"title": "Trigger mix clean in language server"
},
{
"category": "Elixir",
"command": "extension.mixCleanIncludeDeps",
"title": "Trigger mix clean --deps in language server"
},
{
"category": "Elixir",
"command": "extension.toPipe",
Expand Down Expand Up @@ -483,6 +493,16 @@
"command": "extension.restart",
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
},
{
"category": "Elixir",
"command": "extension.mixClean",
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
},
{
"category": "Elixir",
"command": "extension.mixCleanIncludeDeps",
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
},
{
"category": "Elixir",
"command": "extension.toPipe",
Expand Down
33 changes: 32 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { execSync } from "child_process";
import * as shell from "shelljs";
import * as path from "path";

import { workspace, ExtensionContext, WorkspaceFolder, Uri, Disposable } from "vscode";
import { workspace, ExtensionContext, WorkspaceFolder, Uri } from "vscode";
import {
ExecuteCommandParams,
LanguageClient,
Expand Down Expand Up @@ -238,6 +238,35 @@ function configureRestart(context: ExtensionContext) {
context.subscriptions.push(disposable);
}

function configureMixClean(context: ExtensionContext, cleanDeps: boolean) {
const commandName = "extension." + (cleanDeps ? "mixCleanIncludeDeps" : "mixClean");
const disposable = vscode.commands.registerCommand(commandName, async () => {
const extension = vscode.extensions.getExtension("jakebecker.elixir-ls");
const editor = vscode.window.activeTextEditor;

if (!extension || !editor) {
return;
}

const client = getClient(editor.document);
if (!client) {
return;
}

const command = client.initializeResult!.capabilities.executeCommandProvider!.commands
.find(c => c.startsWith("mixClean:"))!;

const params: ExecuteCommandParams = {
command: command,
arguments: [cleanDeps]
};

await client.sendRequest("workspace/executeCommand", params);
});

context.subscriptions.push(disposable);
}

function configureManipulatePipes(context: ExtensionContext, operation: "toPipe" | "fromPipe") {
const commandName = `extension.${operation}`;

Expand Down Expand Up @@ -412,6 +441,8 @@ export function activate(context: ExtensionContext): void {
configureCopyDebugInfo(context);
configureExpandMacro(context);
configureRestart(context);
configureMixClean(context, false);
configureMixClean(context, true);
configureManipulatePipes(context, "fromPipe");
configureManipulatePipes(context, "toPipe");
configureDebugger(context);
Expand Down

0 comments on commit c683f43

Please sign in to comment.