mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { TextDocumentIdentifier } from 'vscode-languageclient';
|
|
|
|
import { Server } from '../server';
|
|
|
|
export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree');
|
|
|
|
export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
|
|
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
|
public syntaxTree: string = 'Not available';
|
|
|
|
public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
|
|
const editor = vscode.window.activeTextEditor;
|
|
if (editor == null) { return ''; }
|
|
const request: SyntaxTreeParams = {
|
|
textDocument: { uri: editor.document.uri.toString() },
|
|
};
|
|
return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request);
|
|
}
|
|
|
|
get onDidChange(): vscode.Event<vscode.Uri> {
|
|
return this.eventEmitter.event;
|
|
}
|
|
}
|
|
|
|
interface SyntaxTreeParams {
|
|
textDocument: TextDocumentIdentifier;
|
|
}
|
|
|
|
type SyntaxTreeResult = string;
|
|
|
|
// Opens the virtual file that will show the syntax tree
|
|
//
|
|
// The contents of the file come from the `TextDocumentContentProvider`
|
|
export async function handle() {
|
|
const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
|
|
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
|
|
}
|