Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@
"configuration": "./elixir-language-configuration.json"
}
],
"commands": [],
"commands": [
{
"command": "elixir-tools.uninstall-nextls",
"title": "elixir-tools: Uninstall Next LS"
}
],
"grammars": [
{
"language": "elixir",
Expand All @@ -140,6 +145,7 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "yarn run compile-tests && yarn run compile",
"lint": "eslint src --ext ts",
"fix": "eslint src --ext ts --fix",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
Expand Down
45 changes: 37 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,52 @@ async function activateCredo(
}

async function activateNextLS(
_context: vscode.ExtensionContext,
context: vscode.ExtensionContext,
_mixfile: vscode.Uri
) {
let config = vscode.workspace.getConfiguration("elixir-tools.nextls");

const command = "elixir-tools.uninstall-nextls";

const uninstallNextLS = async () => {
let cacheDir: string = config.get("installationDirectory")!;
if (cacheDir[0] === "~") {
cacheDir = path.join(os.homedir(), cacheDir.slice(1));
}
const bin = path.join(cacheDir, "nextls");
await fsp
.rm(bin)
.then(
async () =>
await vscode.window.showInformationMessage(
`Uninstalled Next LS from ${bin}`
)
)
.catch(
async () =>
await vscode.window.showErrorMessage(
`Failed to uninstall Next LS from ${bin}`
)
);
};

context.subscriptions.push(
vscode.commands.registerCommand(command, uninstallNextLS)
);

if (config.get("enable")) {
let serverOptions: ServerOptions;

switch (config.get("adapter")) {
case "stdio":
const command = await ensureNextLSDownloaded(
config.get("installationDirectory")!,
{ force: false }
);
let cacheDir: string = config.get("installationDirectory")!;

if (cacheDir[0] === "~") {
cacheDir = path.join(os.homedir(), cacheDir.slice(1));
}
const command = await ensureNextLSDownloaded(cacheDir, {
force: false,
});

serverOptions = {
command,
Expand Down Expand Up @@ -179,9 +211,6 @@ async function ensureNextLSDownloaded(
cacheDir: string,
opts: { force?: boolean } = {}
): Promise<string> {
if (cacheDir[0] === "~") {
cacheDir = path.join(os.homedir(), cacheDir.slice(1));
}
const bin = path.join(cacheDir, "nextls");

const shouldDownload = opts.force || (await isBinaryMissing(bin));
Expand Down