mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Rename syntaxtree text provider to SyntaxTreeContentProvider
This commit is contained in:
parent
c2d3203d0c
commit
1b4e0ec1c8
3 changed files with 11 additions and 13 deletions
|
@ -5,7 +5,7 @@ import { Server } from '../server';
|
||||||
|
|
||||||
export const syntaxTreeUri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
export const syntaxTreeUri = vscode.Uri.parse('rust-analyzer://syntaxtree');
|
||||||
|
|
||||||
export class TextDocumentContentProvider
|
export class SyntaxTreeContentProvider
|
||||||
implements vscode.TextDocumentContentProvider {
|
implements vscode.TextDocumentContentProvider {
|
||||||
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||||
public syntaxTree: string = 'Not available';
|
public syntaxTree: string = 'Not available';
|
||||||
|
@ -54,7 +54,7 @@ type SyntaxTreeResult = string;
|
||||||
// Opens the virtual file that will show the syntax tree
|
// Opens the virtual file that will show the syntax tree
|
||||||
//
|
//
|
||||||
// The contents of the file come from the `TextDocumentContentProvider`
|
// The contents of the file come from the `TextDocumentContentProvider`
|
||||||
export function createHandle(provider: TextDocumentContentProvider) {
|
export function createHandle(provider: SyntaxTreeContentProvider) {
|
||||||
return async () => {
|
return async () => {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
const rangeEnabled = !!(editor && !editor.selection.isEmpty);
|
const rangeEnabled = !!(editor && !editor.selection.isEmpty);
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
syntaxTreeUri,
|
SyntaxTreeContentProvider,
|
||||||
TextDocumentContentProvider
|
syntaxTreeUri
|
||||||
} from '../commands/syntaxTree';
|
} from '../commands/syntaxTree';
|
||||||
|
|
||||||
export function createHandler(
|
export function createHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
|
||||||
textDocumentContentProvider: TextDocumentContentProvider
|
|
||||||
) {
|
|
||||||
return (event: vscode.TextDocumentChangeEvent) => {
|
return (event: vscode.TextDocumentChangeEvent) => {
|
||||||
const doc = event.document;
|
const doc = event.document;
|
||||||
if (doc.languageId !== 'rust') {
|
if (doc.languageId !== 'rust') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
afterLs(() => {
|
afterLs(() => {
|
||||||
textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri);
|
syntaxTreeProvider.eventEmitter.fire(syntaxTreeUri);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
|
|
||||||
import * as commands from './commands';
|
import * as commands from './commands';
|
||||||
import { TextDocumentContentProvider } from './commands/syntaxTree';
|
import { SyntaxTreeContentProvider } from './commands/syntaxTree';
|
||||||
import * as events from './events';
|
import * as events from './events';
|
||||||
import * as notifications from './notifications';
|
import * as notifications from './notifications';
|
||||||
import { Server } from './server';
|
import { Server } from './server';
|
||||||
|
@ -100,21 +100,21 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
events.changeActiveTextEditor.handle
|
events.changeActiveTextEditor.handle
|
||||||
);
|
);
|
||||||
|
|
||||||
const textDocumentContentProvider = new TextDocumentContentProvider();
|
const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
textDocumentContentProvider
|
syntaxTreeContentProvider
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.syntaxTree',
|
'rust-analyzer.syntaxTree',
|
||||||
commands.syntaxTree.createHandle(textDocumentContentProvider)
|
commands.syntaxTree.createHandle(syntaxTreeContentProvider)
|
||||||
);
|
);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument(
|
vscode.workspace.onDidChangeTextDocument(
|
||||||
events.changeTextDocument.createHandler(textDocumentContentProvider),
|
events.changeTextDocument.createHandler(syntaxTreeContentProvider),
|
||||||
null,
|
null,
|
||||||
context.subscriptions
|
context.subscriptions
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue