mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
vscode: migrate expand_macro to rust-analyzer-api.ts
This commit is contained in:
parent
603bc71a57
commit
31d9932d18
1 changed files with 5 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as ra from '../rust-analyzer-api';
|
||||||
|
|
||||||
import { Ctx, Cmd } from '../ctx';
|
import { Ctx, Cmd } from '../ctx';
|
||||||
|
|
||||||
|
@ -26,12 +26,7 @@ export function expandMacro(ctx: Ctx): Cmd {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExpandedMacro {
|
function codeFormat(expanded: ra.ExpandedMacro): string {
|
||||||
name: string;
|
|
||||||
expansion: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function codeFormat(expanded: ExpandedMacro): string {
|
|
||||||
let result = `// Recursive expansion of ${expanded.name}! macro\n`;
|
let result = `// Recursive expansion of ${expanded.name}! macro\n`;
|
||||||
result += '// ' + '='.repeat(result.length - 3);
|
result += '// ' + '='.repeat(result.length - 3);
|
||||||
result += '\n\n';
|
result += '\n\n';
|
||||||
|
@ -54,14 +49,11 @@ class TextDocumentContentProvider
|
||||||
if (!editor || !client) return '';
|
if (!editor || !client) return '';
|
||||||
|
|
||||||
const position = editor.selection.active;
|
const position = editor.selection.active;
|
||||||
const request: lc.TextDocumentPositionParams = {
|
|
||||||
|
const expanded = await client.sendRequest(ra.expandMacro, {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
position,
|
position,
|
||||||
};
|
});
|
||||||
const expanded = await client.sendRequest<ExpandedMacro>(
|
|
||||||
'rust-analyzer/expandMacro',
|
|
||||||
request,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (expanded == null) return 'Not available';
|
if (expanded == null) return 'Not available';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue