vscode: migrate expand_macro to rust-analyzer-api.ts

This commit is contained in:
Veetaha 2020-02-25 00:50:36 +02:00
parent 603bc71a57
commit 31d9932d18

View file

@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import * as ra from '../rust-analyzer-api';
import { Ctx, Cmd } from '../ctx';
@ -26,12 +26,7 @@ export function expandMacro(ctx: Ctx): Cmd {
};
}
interface ExpandedMacro {
name: string;
expansion: string;
}
function codeFormat(expanded: ExpandedMacro): string {
function codeFormat(expanded: ra.ExpandedMacro): string {
let result = `// Recursive expansion of ${expanded.name}! macro\n`;
result += '// ' + '='.repeat(result.length - 3);
result += '\n\n';
@ -54,14 +49,11 @@ class TextDocumentContentProvider
if (!editor || !client) return '';
const position = editor.selection.active;
const request: lc.TextDocumentPositionParams = {
const expanded = await client.sendRequest(ra.expandMacro, {
textDocument: { uri: editor.document.uri.toString() },
position,
};
const expanded = await client.sendRequest<ExpandedMacro>(
'rust-analyzer/expandMacro',
request,
);
});
if (expanded == null) return 'Not available';