Skip to content

Commit 673e808

Browse files
authored
feat(nextls): to-pipe and from-pipe (#80)
1 parent b18f0d5 commit 673e808

File tree

8 files changed

+110
-31
lines changed

8 files changed

+110
-31
lines changed

.vscode/launch.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// A launch configuration that compiles the extension and then opens it inside a new window
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
51
{
62
"version": "0.2.0",
73
"configurations": [

.vscode/tasks.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// See https://go.microsoft.com/fwlink/?LinkId=733558
2-
// for the documentation about the tasks.json format
31
{
42
"version": "2.0.0",
53
"tasks": [
64
{
75
"type": "npm",
8-
"script": "build",
6+
"script": "compile-dist",
97
"problemMatcher": "$ts-webpack-watch",
108
"isBackground": true,
119
"presentation": {

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@
168168
{
169169
"command": "elixir-tools.uninstall-nextls",
170170
"title": "elixir-tools: Uninstall Next LS"
171+
},
172+
{
173+
"command": "elixir-tools.toPipe",
174+
"title": "Convert to pipe (Next LS)"
175+
},
176+
{
177+
"command": "elixir-tools.fromPipe",
178+
"title": "Convert from pipe (Next LS)"
171179
}
172180
],
173181
"grammars": [
@@ -182,6 +190,7 @@
182190
"vscode:prepublish": "yarn run build-base --minify",
183191
"package": "vsce package",
184192
"compile-tests": "tsc -p . --outDir out",
193+
"compile-dist": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --target=node16 --sourcemap",
185194
"watch-tests": "tsc -p . -w --outDir out",
186195
"lint": "eslint src --ext ts",
187196
"fix": "eslint src --ext ts --fix",
@@ -216,4 +225,4 @@
216225
"sinon": "^17.0.1",
217226
"typescript": "^4.9.5"
218227
}
219-
}
228+
}

src/commands/from-pipe.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: "from-pipe",
13+
arguments: [
14+
{
15+
uri: vscode.window.activeTextEditor?.document.uri.toString(),
16+
position: position,
17+
},
18+
],
19+
});
20+
};
21+
22+
function registerFromPipeCommand(
23+
client: LanguageClient,
24+
context: vscode.ExtensionContext
25+
) {
26+
const fromPipeCommand = "elixir-tools.fromPipe";
27+
const fromPipe = async () => run(client);
28+
context.subscriptions.push(
29+
vscode.commands.registerCommand(fromPipeCommand, fromPipe)
30+
);
31+
}
32+
33+
export default registerFromPipeCommand;

src/commands/to-pipe.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: "to-pipe",
13+
arguments: [
14+
{
15+
uri: vscode.window.activeTextEditor?.document.uri.toString(),
16+
position: position,
17+
},
18+
],
19+
});
20+
};
21+
22+
function registerToPipeCommand(
23+
client: LanguageClient,
24+
context: vscode.ExtensionContext
25+
) {
26+
const toPipeCommand = "elixir-tools.toPipe";
27+
const toPipe = async () => run(client);
28+
context.subscriptions.push(
29+
vscode.commands.registerCommand(toPipeCommand, toPipe)
30+
);
31+
}
32+
33+
export default registerToPipeCommand;

src/commands/uninstall.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export const run = async (cacheDir: string) => {
2424
);
2525
};
2626

27-
const registerUninstallCommand = (
27+
function registerUninstallCommand(
2828
config: vscode.WorkspaceConfiguration,
2929
context: vscode.ExtensionContext
30-
) => {
30+
) {
3131
const uninstallCommand = "elixir-tools.uninstall-nextls";
3232

3333
const uninstall = async () =>
@@ -36,6 +36,6 @@ const registerUninstallCommand = (
3636
context.subscriptions.push(
3737
vscode.commands.registerCommand(uninstallCommand, uninstall)
3838
);
39-
};
39+
}
4040

4141
export default registerUninstallCommand;

src/extension.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ import {
1414
} from "vscode-languageclient/node";
1515

1616
import registerUninstallCommand from "./commands/uninstall";
17+
import registerToPipeCommand from "./commands/to-pipe";
18+
import registerFromPipeCommand from "./commands/from-pipe";
1719

1820
let credoClient: LanguageClient;
1921
let nextLSClient: LanguageClient;
2022

23+
const channel = vscode.window.createOutputChannel("elixir-tools.vscode", {
24+
log: true,
25+
});
26+
2127
async function latestRelease(project: string): Promise<string> {
2228
return fetch(
2329
`https://api.github.com/repos/elixir-tools/${project}/releases/latest`,
@@ -101,8 +107,6 @@ async function activateNextLS(
101107
) {
102108
let config = vscode.workspace.getConfiguration("elixir-tools.nextLS");
103109

104-
registerUninstallCommand(config, context);
105-
106110
if (config.get("enable")) {
107111
let serverOptions: ServerOptions;
108112

@@ -163,11 +167,15 @@ async function activateNextLS(
163167

164168
nextLSClient = new LanguageClient(
165169
"elixir-tools.nextLS",
166-
"NextLS",
170+
"Next LS",
167171
serverOptions,
168172
clientOptions
169173
);
170174

175+
registerToPipeCommand(nextLSClient, context);
176+
registerFromPipeCommand(nextLSClient, context);
177+
registerUninstallCommand(config, context);
178+
171179
// Start the nextLSClient. This will also launch the server
172180
nextLSClient.start();
173181
}
@@ -206,21 +214,14 @@ export async function ensureNextLSDownloaded(
206214
const shouldDownload = opts.force || (await isBinaryMissing(bin));
207215

208216
if (shouldDownload) {
217+
channel.info("Next LS needs to be downloaded");
209218
await fsp.mkdir(cacheDir, { recursive: true });
210219

211220
const platform = getPlatform();
212221
const exe = getExe(platform);
213222
const url = `https://github.com/elixir-tools/next-ls/releases/latest/download/${exe}`;
214223

215-
const shouldInstall = await vscode.window.showInformationMessage(
216-
"Install Next LS?",
217-
{ modal: true, detail: `Downloading to '${cacheDir}'` },
218-
{ title: "Yes" }
219-
);
220-
221-
if (shouldInstall?.title !== "Yes") {
222-
throw new Error("Could not activate Next LS");
223-
}
224+
channel.info(`Starting download from ${url}`);
224225

225226
await fetch(url).then((res) => {
226227
if (res.ok) {
@@ -230,10 +231,12 @@ export async function ensureNextLSDownloaded(
230231
file.on("close", resolve);
231232
file.on("error", reject);
232233
})
233-
.then(() => console.log("Downloaded NextLS!!"))
234-
.catch(() => console.log("Failed to download NextLS!!"));
234+
.then(() => channel.info("Downloaded NextLS!"))
235+
.catch(() =>
236+
channel.error("Failed to write downloaded executable to a file")
237+
);
235238
} else {
236-
throw new Error(`Download failed (${url}, status=${res.status})`);
239+
channel.error(`Failed to write download Next LS: status=${res.status}`);
237240
}
238241
});
239242
await fsp.chmod(bin, "755");
@@ -245,8 +248,10 @@ export async function ensureNextLSDownloaded(
245248
async function isBinaryMissing(bin: string) {
246249
try {
247250
await fsp.access(bin, fs.constants.X_OK);
251+
channel.info(`Found Next LS executable at ${bin}`);
248252
return false;
249253
} catch {
254+
channel.warn(`Did not find Next LS executable at ${bin}`);
250255
return true;
251256
}
252257
}
@@ -266,7 +271,7 @@ function getExe(platform: string) {
266271
return "next_ls_darwin_amd64";
267272

268273
case "arm64":
269-
return "next_ls_darwin_amd64";
274+
return "next_ls_darwin_arm64";
270275
}
271276

272277
case "linux":

tsconfig.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
"compilerOptions": {
33
"target": "es2020",
44
"module": "commonjs",
5-
"lib": ["ES2020", "DOM"],
5+
"lib": [
6+
"ES2020",
7+
"DOM"
8+
],
69
"outDir": "out",
710
"sourceMap": true,
811
"strict": false
912
},
10-
"exclude": ["node_modules", ".vscode-test", ]
11-
}
12-
13+
"exclude": [
14+
"node_modules",
15+
".vscode-test",
16+
]
17+
}

0 commit comments

Comments
 (0)