diff --git a/.vscode/launch.json b/.vscode/launch.json index d4df9e9..2bf019d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,3 @@ -// A launch configuration that compiles the extension and then opens it inside a new window -// Use IntelliSense to learn about possible attributes. -// Hover to view descriptions of existing attributes. -// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { "version": "0.2.0", "configurations": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 95ecdc4..cef4337 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,11 +1,9 @@ -// See https://go.microsoft.com/fwlink/?LinkId=733558 -// for the documentation about the tasks.json format { "version": "2.0.0", "tasks": [ { "type": "npm", - "script": "build", + "script": "compile-dist", "problemMatcher": "$ts-webpack-watch", "isBackground": true, "presentation": { diff --git a/package.json b/package.json index 034e99f..34d4756 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,14 @@ { "command": "elixir-tools.uninstall-nextls", "title": "elixir-tools: Uninstall Next LS" + }, + { + "command": "elixir-tools.toPipe", + "title": "Convert to pipe (Next LS)" + }, + { + "command": "elixir-tools.fromPipe", + "title": "Convert from pipe (Next LS)" } ], "grammars": [ @@ -182,6 +190,7 @@ "vscode:prepublish": "yarn run build-base --minify", "package": "vsce package", "compile-tests": "tsc -p . --outDir out", + "compile-dist": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --target=node16 --sourcemap", "watch-tests": "tsc -p . -w --outDir out", "lint": "eslint src --ext ts", "fix": "eslint src --ext ts --fix", @@ -216,4 +225,4 @@ "sinon": "^17.0.1", "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/src/commands/from-pipe.ts b/src/commands/from-pipe.ts new file mode 100644 index 0000000..bf64503 --- /dev/null +++ b/src/commands/from-pipe.ts @@ -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: "from-pipe", + arguments: [ + { + uri: vscode.window.activeTextEditor?.document.uri.toString(), + position: position, + }, + ], + }); +}; + +function registerFromPipeCommand( + client: LanguageClient, + context: vscode.ExtensionContext +) { + const fromPipeCommand = "elixir-tools.fromPipe"; + const fromPipe = async () => run(client); + context.subscriptions.push( + vscode.commands.registerCommand(fromPipeCommand, fromPipe) + ); +} + +export default registerFromPipeCommand; diff --git a/src/commands/to-pipe.ts b/src/commands/to-pipe.ts new file mode 100644 index 0000000..d4742de --- /dev/null +++ b/src/commands/to-pipe.ts @@ -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: "to-pipe", + arguments: [ + { + uri: vscode.window.activeTextEditor?.document.uri.toString(), + position: position, + }, + ], + }); +}; + +function registerToPipeCommand( + client: LanguageClient, + context: vscode.ExtensionContext +) { + const toPipeCommand = "elixir-tools.toPipe"; + const toPipe = async () => run(client); + context.subscriptions.push( + vscode.commands.registerCommand(toPipeCommand, toPipe) + ); +} + +export default registerToPipeCommand; diff --git a/src/commands/uninstall.ts b/src/commands/uninstall.ts index 306129a..3256623 100644 --- a/src/commands/uninstall.ts +++ b/src/commands/uninstall.ts @@ -24,10 +24,10 @@ export const run = async (cacheDir: string) => { ); }; -const registerUninstallCommand = ( +function registerUninstallCommand( config: vscode.WorkspaceConfiguration, context: vscode.ExtensionContext -) => { +) { const uninstallCommand = "elixir-tools.uninstall-nextls"; const uninstall = async () => @@ -36,6 +36,6 @@ const registerUninstallCommand = ( context.subscriptions.push( vscode.commands.registerCommand(uninstallCommand, uninstall) ); -}; +} export default registerUninstallCommand; diff --git a/src/extension.ts b/src/extension.ts index 791b71c..bc5702b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,10 +14,16 @@ import { } from "vscode-languageclient/node"; import registerUninstallCommand from "./commands/uninstall"; +import registerToPipeCommand from "./commands/to-pipe"; +import registerFromPipeCommand from "./commands/from-pipe"; let credoClient: LanguageClient; let nextLSClient: LanguageClient; +const channel = vscode.window.createOutputChannel("elixir-tools.vscode", { + log: true, +}); + async function latestRelease(project: string): Promise { return fetch( `https://api.github.com/repos/elixir-tools/${project}/releases/latest`, @@ -101,8 +107,6 @@ async function activateNextLS( ) { let config = vscode.workspace.getConfiguration("elixir-tools.nextLS"); - registerUninstallCommand(config, context); - if (config.get("enable")) { let serverOptions: ServerOptions; @@ -163,11 +167,15 @@ async function activateNextLS( nextLSClient = new LanguageClient( "elixir-tools.nextLS", - "NextLS", + "Next LS", serverOptions, clientOptions ); + registerToPipeCommand(nextLSClient, context); + registerFromPipeCommand(nextLSClient, context); + registerUninstallCommand(config, context); + // Start the nextLSClient. This will also launch the server nextLSClient.start(); } @@ -206,21 +214,14 @@ export async function ensureNextLSDownloaded( const shouldDownload = opts.force || (await isBinaryMissing(bin)); if (shouldDownload) { + channel.info("Next LS needs to be downloaded"); await fsp.mkdir(cacheDir, { recursive: true }); const platform = getPlatform(); const exe = getExe(platform); const url = `https://github.com/elixir-tools/next-ls/releases/latest/download/${exe}`; - const shouldInstall = await vscode.window.showInformationMessage( - "Install Next LS?", - { modal: true, detail: `Downloading to '${cacheDir}'` }, - { title: "Yes" } - ); - - if (shouldInstall?.title !== "Yes") { - throw new Error("Could not activate Next LS"); - } + channel.info(`Starting download from ${url}`); await fetch(url).then((res) => { if (res.ok) { @@ -230,10 +231,12 @@ export async function ensureNextLSDownloaded( file.on("close", resolve); file.on("error", reject); }) - .then(() => console.log("Downloaded NextLS!!")) - .catch(() => console.log("Failed to download NextLS!!")); + .then(() => channel.info("Downloaded NextLS!")) + .catch(() => + channel.error("Failed to write downloaded executable to a file") + ); } else { - throw new Error(`Download failed (${url}, status=${res.status})`); + channel.error(`Failed to write download Next LS: status=${res.status}`); } }); await fsp.chmod(bin, "755"); @@ -245,8 +248,10 @@ export async function ensureNextLSDownloaded( async function isBinaryMissing(bin: string) { try { await fsp.access(bin, fs.constants.X_OK); + channel.info(`Found Next LS executable at ${bin}`); return false; } catch { + channel.warn(`Did not find Next LS executable at ${bin}`); return true; } } @@ -266,7 +271,7 @@ function getExe(platform: string) { return "next_ls_darwin_amd64"; case "arm64": - return "next_ls_darwin_amd64"; + return "next_ls_darwin_arm64"; } case "linux": diff --git a/tsconfig.json b/tsconfig.json index b9c8ac6..90dd874 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,11 +2,16 @@ "compilerOptions": { "target": "es2020", "module": "commonjs", - "lib": ["ES2020", "DOM"], + "lib": [ + "ES2020", + "DOM" + ], "outDir": "out", "sourceMap": true, "strict": false }, - "exclude": ["node_modules", ".vscode-test", ] -} - + "exclude": [ + "node_modules", + ".vscode-test", + ] +} \ No newline at end of file