1
+ import { window } from 'vscode' ;
1
2
/* --------------------------------------------------------------------------------------------
2
3
* Copyright (c) Microsoft Corporation. All rights reserved.
3
4
* Licensed under the MIT License. See License.txt in the project root for license information.
@@ -11,10 +12,11 @@ import * as path from "path";
11
12
12
13
import { workspace , ExtensionContext , WorkspaceFolder , Uri } from "vscode" ;
13
14
import {
15
+ ExecuteCommandParams ,
14
16
LanguageClient ,
15
17
LanguageClientOptions ,
16
18
RevealOutputChannelOn ,
17
- ServerOptions ,
19
+ ServerOptions
18
20
} from "vscode-languageclient" ;
19
21
import * as os from "os" ;
20
22
import Commands from "./constants/commands" ;
@@ -28,6 +30,8 @@ interface TerminalLinkWithData extends vscode.TerminalLink {
28
30
}
29
31
}
30
32
33
+ const ExpandMacroTitle = 'Expand macro result'
34
+
31
35
export let defaultClient : LanguageClient ;
32
36
const clients : Map < string , LanguageClient > = new Map ( ) ;
33
37
let _sortedWorkspaceFolders : string [ ] | undefined ;
@@ -139,6 +143,76 @@ function configureCopyDebugInfo(context: ExtensionContext) {
139
143
context . subscriptions . push ( disposable ) ;
140
144
}
141
145
146
+ function getExpandMacroWebviewContent ( content : Record < string , string > ) {
147
+ let body = "" ;
148
+ for ( const [ key , value ] of Object . entries ( content ) ) {
149
+ body += `<div>
150
+ <h4>${ key } </h4>
151
+ <code><pre>${ value } </pre></code>
152
+ </div>`
153
+ }
154
+
155
+ return `<!DOCTYPE html>
156
+ <html lang="en">
157
+ <head>
158
+ <meta charset="UTF-8">
159
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
160
+ <title>${ ExpandMacroTitle } </title>
161
+ </head>
162
+ <body>
163
+ ${ body }
164
+ </body>
165
+ </html>` ;
166
+ }
167
+
168
+ function configureExpandMacro ( context : ExtensionContext ) {
169
+ const disposable = vscode . commands . registerCommand ( "extension.expandMacro" , async ( ) => {
170
+ const extension = vscode . extensions . getExtension ( "jakebecker.elixir-ls" ) ;
171
+ const editor = vscode . window . activeTextEditor ;
172
+ if ( ! extension || ! editor ) {
173
+ return ;
174
+ }
175
+
176
+ const uri = editor . document . uri ;
177
+ let client = null ;
178
+ if ( uri . scheme === "untitled" ) {
179
+ client = defaultClient ;
180
+ } else {
181
+ let folder = workspace . getWorkspaceFolder ( uri ) ;
182
+
183
+ if ( folder ) {
184
+ folder = getOuterMostWorkspaceFolder ( folder ) ;
185
+ client = clients . get ( folder . uri . toString ( ) )
186
+ }
187
+ }
188
+
189
+ if ( ! client ) {
190
+ return ;
191
+ }
192
+
193
+ if ( editor . selection . isEmpty ) {
194
+ return ;
195
+ }
196
+
197
+ const params : ExecuteCommandParams = {
198
+ command : "expandMacro" ,
199
+ arguments : [ uri . toString ( ) , editor . document . getText ( editor . selection ) , editor . selection . start . line ]
200
+ } ;
201
+
202
+ const res : Record < string , string > = await client . sendRequest ( "workspace/executeCommand" , params ) ;
203
+
204
+ const panel = vscode . window . createWebviewPanel (
205
+ 'expandMacro' ,
206
+ ExpandMacroTitle ,
207
+ vscode . ViewColumn . One ,
208
+ { }
209
+ ) ;
210
+ panel . webview . html = getExpandMacroWebviewContent ( res ) ;
211
+ } ) ;
212
+
213
+ context . subscriptions . push ( disposable ) ;
214
+ }
215
+
142
216
class DebugAdapterExecutableFactory implements vscode . DebugAdapterDescriptorFactory {
143
217
createDebugAdapterDescriptor ( session : vscode . DebugSession , executable : vscode . DebugAdapterExecutable ) : vscode . ProviderResult < vscode . DebugAdapterDescriptor > {
144
218
if ( session . workspaceFolder ) {
@@ -233,6 +307,7 @@ export function activate(context: ExtensionContext): void {
233
307
234
308
configureRunTestFromCodeLens ( )
235
309
configureCopyDebugInfo ( context ) ;
310
+ configureExpandMacro ( context ) ;
236
311
configureDebugger ( context ) ;
237
312
configureTerminalLinkProvider ( context ) ;
238
313
0 commit comments