From b0845166029d4bc45619fe7e48736887b9e86c13 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 30 Jan 2021 15:26:18 +0100 Subject: [PATCH 1/5] add expandMacro command --- package.json | 8 +++++ src/extension.ts | 77 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8668a2a..13b4029 100644 --- a/package.json +++ b/package.json @@ -394,6 +394,10 @@ { "command": "extension.copyDebugInfo", "title": "ElixirLS: Copy Debug Info" + }, + { + "command": "extension.expandMacro", + "title": "ElixirLS: Expand macro" } ], "menus": { @@ -401,6 +405,10 @@ { "command": "extension.copyDebugInfo", "when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex" + }, + { + "command": "extension.expandMacro", + "title": "editorLangId == elixir" } ] } diff --git a/src/extension.ts b/src/extension.ts index e9d2d59..21ff825 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,4 @@ +import { window } from 'vscode'; /* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. @@ -11,10 +12,11 @@ import * as path from "path"; import { workspace, ExtensionContext, WorkspaceFolder, Uri } from "vscode"; import { + ExecuteCommandParams, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, - ServerOptions, + ServerOptions } from "vscode-languageclient"; import * as os from "os"; import Commands from "./constants/commands"; @@ -28,6 +30,8 @@ interface TerminalLinkWithData extends vscode.TerminalLink { } } +const ExpandMacroTitle = 'Expand macro result' + export let defaultClient: LanguageClient; const clients: Map = new Map(); let _sortedWorkspaceFolders: string[] | undefined; @@ -139,6 +143,76 @@ function configureCopyDebugInfo(context: ExtensionContext) { context.subscriptions.push(disposable); } +function getExpandMacroWebviewContent(content: Record) { + let body = ""; + for (const [key, value] of Object.entries(content)) { + body += `
+

${key}

+
${value}
+
` + } + + return ` + + + + + ${ExpandMacroTitle} + + + ${body} + +`; +} + +function configureExpandMacro(context: ExtensionContext) { + const disposable = vscode.commands.registerCommand("extension.expandMacro", async () => { + const extension = vscode.extensions.getExtension("jakebecker.elixir-ls"); + const editor = vscode.window.activeTextEditor; + if (!extension || !editor) { + return; + } + + const uri = editor.document.uri; + let client = null; + if (uri.scheme === "untitled") { + client = defaultClient; + } else { + let folder = workspace.getWorkspaceFolder(uri); + + if (folder) { + folder = getOuterMostWorkspaceFolder(folder); + client = clients.get(folder.uri.toString()) + } + } + + if (!client) { + return; + } + + if (editor.selection.isEmpty) { + return; + } + + const params: ExecuteCommandParams = { + command: "expandMacro", + arguments: [uri.toString(), editor.document.getText(editor.selection), editor.selection.start.line] + }; + + const res: Record = await client.sendRequest("workspace/executeCommand", params); + + const panel = vscode.window.createWebviewPanel( + 'expandMacro', + ExpandMacroTitle, + vscode.ViewColumn.One, + {} + ); + panel.webview.html = getExpandMacroWebviewContent(res); + }); + + context.subscriptions.push(disposable); +} + class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescriptorFactory { createDebugAdapterDescriptor(session: vscode.DebugSession, executable: vscode.DebugAdapterExecutable): vscode.ProviderResult { if (session.workspaceFolder) { @@ -233,6 +307,7 @@ export function activate(context: ExtensionContext): void { configureRunTestFromCodeLens() configureCopyDebugInfo(context); + configureExpandMacro(context); configureDebugger(context); configureTerminalLinkProvider(context); From 8cd21cb921f333bd411e4c2a3c85d7468ccccfb5 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sun, 28 Feb 2021 22:04:45 +0100 Subject: [PATCH 2/5] update elixir-ls --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index dccd34d..48478a6 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit dccd34dbd856ae34efc925d014c6f84012549c90 +Subproject commit 48478a6521cfb94811b3c888e7fc4f87c9608ef5 From dce92ddffa03f49ffbe4ca9f7fa0b1bfc20de292 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 6 Mar 2021 12:40:14 +0100 Subject: [PATCH 3/5] cleanup --- src/extension.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 21ff825..6ece3ca 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,3 @@ -import { window } from 'vscode'; /* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. From 49563f8b51cac8733d0f67f46557ac9a68b37750 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 6 Mar 2021 12:40:58 +0100 Subject: [PATCH 4/5] get command name with server instance id from initialise result --- src/extension.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 6ece3ca..549e8b6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -193,8 +193,11 @@ function configureExpandMacro(context: ExtensionContext) { return; } + const command = client.initializeResult!.capabilities.executeCommandProvider!.commands + .find(c => c.startsWith("expandMacro:"))!; + const params: ExecuteCommandParams = { - command: "expandMacro", + command: command, arguments: [uri.toString(), editor.document.getText(editor.selection), editor.selection.start.line] }; From 187d248531c239bd6444044483b7475164fd222d Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 6 Mar 2021 12:41:04 +0100 Subject: [PATCH 5/5] update ex --- elixir-ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elixir-ls b/elixir-ls index 48478a6..7fa1f58 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit 48478a6521cfb94811b3c888e7fc4f87c9608ef5 +Subproject commit 7fa1f5840be4ca0c02647d27b790122810d5ac22