diff --git a/elixir-ls b/elixir-ls index dccd34d..7fa1f58 160000 --- a/elixir-ls +++ b/elixir-ls @@ -1 +1 @@ -Subproject commit dccd34dbd856ae34efc925d014c6f84012549c90 +Subproject commit 7fa1f5840be4ca0c02647d27b790122810d5ac22 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..549e8b6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,10 +11,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 +29,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 +142,79 @@ 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 command = client.initializeResult!.capabilities.executeCommandProvider!.commands + .find(c => c.startsWith("expandMacro:"))!; + + const params: ExecuteCommandParams = { + command: command, + 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 +309,7 @@ export function activate(context: ExtensionContext): void { configureRunTestFromCodeLens() configureCopyDebugInfo(context); + configureExpandMacro(context); configureDebugger(context); configureTerminalLinkProvider(context);