mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
vscode: migrate syntax_tree to rust-analyzer-api.ts
This commit is contained in:
parent
9ea63d5a86
commit
8aea0ec511
1 changed files with 7 additions and 20 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';
|
||||||
|
|
||||||
|
@ -61,13 +61,8 @@ function afterLs(f: () => void) {
|
||||||
setTimeout(f, 10);
|
setTimeout(f, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SyntaxTreeParams {
|
|
||||||
textDocument: lc.TextDocumentIdentifier;
|
|
||||||
range?: lc.Range;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TextDocumentContentProvider
|
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
|
||||||
implements vscode.TextDocumentContentProvider {
|
|
||||||
uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
||||||
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||||
|
|
||||||
|
@ -79,23 +74,15 @@ class TextDocumentContentProvider
|
||||||
const client = this.ctx.client;
|
const client = this.ctx.client;
|
||||||
if (!editor || !client) return '';
|
if (!editor || !client) return '';
|
||||||
|
|
||||||
let range: lc.Range | undefined;
|
|
||||||
|
|
||||||
// When the range based query is enabled we take the range of the selection
|
// When the range based query is enabled we take the range of the selection
|
||||||
if (uri.query === 'range=true') {
|
const range = uri.query === 'range=true' && !editor.selection.isEmpty
|
||||||
range = editor.selection.isEmpty
|
? client.code2ProtocolConverter.asRange(editor.selection)
|
||||||
? undefined
|
: null;
|
||||||
: client.code2ProtocolConverter.asRange(editor.selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
const request: SyntaxTreeParams = {
|
return client.sendRequest(ra.syntaxTree, {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
range,
|
range,
|
||||||
};
|
});
|
||||||
return client.sendRequest<string>(
|
|
||||||
'rust-analyzer/syntaxTree',
|
|
||||||
request,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||||
|
|
Loading…
Reference in a new issue