mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-17 18:57:04 +00:00
Add a new and improved syntax tree viewer
This commit is contained in:
parent
c0eaff7dd1
commit
5ffe45d8cd
14 changed files with 759 additions and 4 deletions
|
|
@ -31,6 +31,7 @@ import type { LanguageClient } from "vscode-languageclient/node";
|
|||
import { HOVER_REFERENCE_COMMAND } from "./client";
|
||||
import type { DependencyId } from "./dependencies_provider";
|
||||
import { log } from "./util";
|
||||
import type { SyntaxElement } from "./syntax_tree_provider";
|
||||
|
||||
export * from "./ast_inspector";
|
||||
export * from "./run";
|
||||
|
|
@ -357,6 +358,38 @@ export async function execRevealDependency(e: RustEditor): Promise<void> {
|
|||
await vscode.commands.executeCommand("rust-analyzer.revealDependency", e);
|
||||
}
|
||||
|
||||
export function syntaxTreeReveal(): Cmd {
|
||||
return async (element: SyntaxElement) => {
|
||||
const activeEditor = vscode.window.activeTextEditor;
|
||||
|
||||
if (activeEditor !== undefined) {
|
||||
const start = activeEditor.document.positionAt(element.start);
|
||||
const end = activeEditor.document.positionAt(element.end);
|
||||
|
||||
const newSelection = new vscode.Selection(start, end);
|
||||
|
||||
activeEditor.selection = newSelection;
|
||||
activeEditor.revealRange(newSelection);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function syntaxTreeHideWhitespace(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
if (ctx.syntaxTreeProvider !== undefined) {
|
||||
await ctx.syntaxTreeProvider.toggleWhitespace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function syntaxTreeShowWhitespace(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
if (ctx.syntaxTreeProvider !== undefined) {
|
||||
await ctx.syntaxTreeProvider.toggleWhitespace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function ssr(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue