mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Cleanup
This commit is contained in:
parent
260df66b77
commit
68f47a5b10
@ -1,8 +1,8 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { Ctx, Cmd } from '../ctx';
|
import { Ctx, Cmd } from '../ctx';
|
||||||
// Shows status of rust-analyzer (for debugging)
|
|
||||||
|
|
||||||
|
// Shows status of rust-analyzer (for debugging)
|
||||||
export function analyzerStatus(ctx: Ctx): Cmd {
|
export function analyzerStatus(ctx: Ctx): Cmd {
|
||||||
let poller: NodeJS.Timer | null = null;
|
let poller: NodeJS.Timer | null = null;
|
||||||
const tdcp = new TextDocumentContentProvider(ctx);
|
const tdcp = new TextDocumentContentProvider(ctx);
|
||||||
|
@ -7,12 +7,12 @@ import { Ctx, Cmd } from '../ctx';
|
|||||||
//
|
//
|
||||||
// The contents of the file come from the `TextDocumentContentProvider`
|
// The contents of the file come from the `TextDocumentContentProvider`
|
||||||
export function syntaxTree(ctx: Ctx): Cmd {
|
export function syntaxTree(ctx: Ctx): Cmd {
|
||||||
const stcp = new SyntaxTreeContentProvider(ctx);
|
const tdcp = new TextDocumentContentProvider(ctx);
|
||||||
|
|
||||||
ctx.pushCleanup(
|
ctx.pushCleanup(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
stcp,
|
tdcp,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
|||||||
(event: vscode.TextDocumentChangeEvent) => {
|
(event: vscode.TextDocumentChangeEvent) => {
|
||||||
const doc = event.document;
|
const doc = event.document;
|
||||||
if (doc.languageId !== 'rust') return;
|
if (doc.languageId !== 'rust') return;
|
||||||
afterLs(() => stcp.eventEmitter.fire(stcp.uri));
|
afterLs(() => tdcp.eventEmitter.fire(tdcp.uri));
|
||||||
},
|
},
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
@ -28,7 +28,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
|||||||
vscode.window.onDidChangeActiveTextEditor(
|
vscode.window.onDidChangeActiveTextEditor(
|
||||||
(editor: vscode.TextEditor | undefined) => {
|
(editor: vscode.TextEditor | undefined) => {
|
||||||
if (!editor || editor.document.languageId !== 'rust') return;
|
if (!editor || editor.document.languageId !== 'rust') return;
|
||||||
stcp.eventEmitter.fire(stcp.uri);
|
tdcp.eventEmitter.fire(tdcp.uri);
|
||||||
},
|
},
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
@ -38,12 +38,12 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
|||||||
const rangeEnabled = !!(editor && !editor.selection.isEmpty);
|
const rangeEnabled = !!(editor && !editor.selection.isEmpty);
|
||||||
|
|
||||||
const uri = rangeEnabled
|
const uri = rangeEnabled
|
||||||
? vscode.Uri.parse(`${stcp.uri.toString()}?range=true`)
|
? vscode.Uri.parse(`${tdcp.uri.toString()}?range=true`)
|
||||||
: stcp.uri;
|
: tdcp.uri;
|
||||||
|
|
||||||
const document = await vscode.workspace.openTextDocument(uri);
|
const document = await vscode.workspace.openTextDocument(uri);
|
||||||
|
|
||||||
stcp.eventEmitter.fire(uri);
|
tdcp.eventEmitter.fire(uri);
|
||||||
|
|
||||||
return vscode.window.showTextDocument(
|
return vscode.window.showTextDocument(
|
||||||
document,
|
document,
|
||||||
@ -64,7 +64,7 @@ interface SyntaxTreeParams {
|
|||||||
range?: lc.Range;
|
range?: lc.Range;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SyntaxTreeContentProvider
|
class TextDocumentContentProvider
|
||||||
implements vscode.TextDocumentContentProvider {
|
implements vscode.TextDocumentContentProvider {
|
||||||
ctx: Ctx;
|
ctx: Ctx;
|
||||||
uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
||||||
@ -86,8 +86,8 @@ export class SyntaxTreeContentProvider
|
|||||||
range = editor.selection.isEmpty
|
range = editor.selection.isEmpty
|
||||||
? undefined
|
? undefined
|
||||||
: this.ctx.client.code2ProtocolConverter.asRange(
|
: this.ctx.client.code2ProtocolConverter.asRange(
|
||||||
editor.selection,
|
editor.selection,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const request: SyntaxTreeParams = {
|
const request: SyntaxTreeParams = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user