mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Simplify
This commit is contained in:
parent
dc559dbe1c
commit
2008f9e0b9
1 changed files with 39 additions and 42 deletions
|
@ -1,14 +1,48 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
|
// Shows status of rust-analyzer (for debugging)
|
||||||
|
|
||||||
const statusUri = vscode.Uri.parse('rust-analyzer-status://status');
|
export function makeCommand(context: vscode.ExtensionContext) {
|
||||||
|
let poller: NodeJS.Timer | null = null;
|
||||||
|
const tdcp = new TextDocumentContentProvider();
|
||||||
|
|
||||||
export class TextDocumentContentProvider
|
context.subscriptions.push(
|
||||||
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
|
'rust-analyzer-status',
|
||||||
|
tdcp,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
context.subscriptions.push({
|
||||||
|
dispose() {
|
||||||
|
if (poller != null) {
|
||||||
|
clearInterval(poller);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return async function handle() {
|
||||||
|
if (poller == null) {
|
||||||
|
poller = setInterval(
|
||||||
|
() => tdcp.eventEmitter.fire(tdcp.uri),
|
||||||
|
1000,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
||||||
|
return vscode.window.showTextDocument(
|
||||||
|
document,
|
||||||
|
vscode.ViewColumn.Two,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class TextDocumentContentProvider
|
||||||
implements vscode.TextDocumentContentProvider {
|
implements vscode.TextDocumentContentProvider {
|
||||||
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
uri = vscode.Uri.parse('rust-analyzer-status://status');
|
||||||
public syntaxTree: string = 'Not available';
|
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||||
|
|
||||||
public provideTextDocumentContent(
|
provideTextDocumentContent(
|
||||||
_uri: vscode.Uri,
|
_uri: vscode.Uri,
|
||||||
): vscode.ProviderResult<string> {
|
): vscode.ProviderResult<string> {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
|
@ -25,40 +59,3 @@ export class TextDocumentContentProvider
|
||||||
return this.eventEmitter.event;
|
return this.eventEmitter.event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let poller: NodeJS.Timer | null = null;
|
|
||||||
|
|
||||||
// Shows status of rust-analyzer (for debugging)
|
|
||||||
|
|
||||||
export function makeCommand(context: vscode.ExtensionContext) {
|
|
||||||
const textDocumentContentProvider = new TextDocumentContentProvider();
|
|
||||||
context.subscriptions.push(
|
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
|
||||||
'rust-analyzer-status',
|
|
||||||
textDocumentContentProvider,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.subscriptions.push({
|
|
||||||
dispose() {
|
|
||||||
if (poller != null) {
|
|
||||||
clearInterval(poller);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return async function handle() {
|
|
||||||
if (poller == null) {
|
|
||||||
poller = setInterval(
|
|
||||||
() => textDocumentContentProvider.eventEmitter.fire(statusUri),
|
|
||||||
1000,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const document = await vscode.workspace.openTextDocument(statusUri);
|
|
||||||
return vscode.window.showTextDocument(
|
|
||||||
document,
|
|
||||||
vscode.ViewColumn.Two,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue