diff options
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands.ts | 50 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 6 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 |
4 files changed, 62 insertions, 0 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 1743b374c..17d9281ff 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -110,6 +110,11 @@ | |||
110 | "category": "Rust Analyzer" | 110 | "category": "Rust Analyzer" |
111 | }, | 111 | }, |
112 | { | 112 | { |
113 | "command": "rust-analyzer.viewItemTree", | ||
114 | "title": "Debug ItemTree", | ||
115 | "category": "Rust Analyzer" | ||
116 | }, | ||
117 | { | ||
113 | "command": "rust-analyzer.viewCrateGraph", | 118 | "command": "rust-analyzer.viewCrateGraph", |
114 | "title": "View Crate Graph", | 119 | "title": "View Crate Graph", |
115 | "category": "Rust Analyzer" | 120 | "category": "Rust Analyzer" |
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 8ab259af2..8f672e68d 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -429,6 +429,56 @@ export function viewHir(ctx: Ctx): Cmd { | |||
429 | }; | 429 | }; |
430 | } | 430 | } |
431 | 431 | ||
432 | export function viewItemTree(ctx: Ctx): Cmd { | ||
433 | const tdcp = new class implements vscode.TextDocumentContentProvider { | ||
434 | readonly uri = vscode.Uri.parse('rust-analyzer://viewItemTree/itemtree.txt'); | ||
435 | readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); | ||
436 | constructor() { | ||
437 | vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, ctx.subscriptions); | ||
438 | vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, ctx.subscriptions); | ||
439 | } | ||
440 | |||
441 | private onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) { | ||
442 | if (isRustDocument(event.document)) { | ||
443 | // We need to order this after language server updates, but there's no API for that. | ||
444 | // Hence, good old sleep(). | ||
445 | void sleep(10).then(() => this.eventEmitter.fire(this.uri)); | ||
446 | } | ||
447 | } | ||
448 | private onDidChangeActiveTextEditor(editor: vscode.TextEditor | undefined) { | ||
449 | if (editor && isRustEditor(editor)) { | ||
450 | this.eventEmitter.fire(this.uri); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | provideTextDocumentContent(_uri: vscode.Uri, ct: vscode.CancellationToken): vscode.ProviderResult<string> { | ||
455 | const rustEditor = ctx.activeRustEditor; | ||
456 | const client = ctx.client; | ||
457 | if (!rustEditor || !client) return ''; | ||
458 | |||
459 | const params = { | ||
460 | textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(rustEditor.document), | ||
461 | }; | ||
462 | return client.sendRequest(ra.viewItemTree, params, ct); | ||
463 | } | ||
464 | |||
465 | get onDidChange(): vscode.Event<vscode.Uri> { | ||
466 | return this.eventEmitter.event; | ||
467 | } | ||
468 | }; | ||
469 | |||
470 | ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider('rust-analyzer', tdcp)); | ||
471 | |||
472 | return async () => { | ||
473 | const document = await vscode.workspace.openTextDocument(tdcp.uri); | ||
474 | tdcp.eventEmitter.fire(tdcp.uri); | ||
475 | void await vscode.window.showTextDocument(document, { | ||
476 | viewColumn: vscode.ViewColumn.Two, | ||
477 | preserveFocus: true | ||
478 | }); | ||
479 | }; | ||
480 | } | ||
481 | |||
432 | export function viewCrateGraph(ctx: Ctx): Cmd { | 482 | export function viewCrateGraph(ctx: Ctx): Cmd { |
433 | return async () => { | 483 | return async () => { |
434 | const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two); | 484 | const panel = vscode.window.createWebviewPanel("rust-analyzer.crate-graph", "rust-analyzer crate graph", vscode.ViewColumn.Two); |
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index aa745a65c..6d5c2ea72 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts | |||
@@ -27,6 +27,12 @@ export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>("ru | |||
27 | 27 | ||
28 | export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>("rust-analyzer/viewHir"); | 28 | export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>("rust-analyzer/viewHir"); |
29 | 29 | ||
30 | export interface ViewItemTreeParams { | ||
31 | textDocument: lc.TextDocumentIdentifier; | ||
32 | } | ||
33 | |||
34 | export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>("rust-analyzer/viewItemTree"); | ||
35 | |||
30 | export const viewCrateGraph = new lc.RequestType0<string, void>("rust-analyzer/viewCrateGraph"); | 36 | export const viewCrateGraph = new lc.RequestType0<string, void>("rust-analyzer/viewCrateGraph"); |
31 | 37 | ||
32 | export interface ExpandMacroParams { | 38 | export interface ExpandMacroParams { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 516322d03..92c797d47 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -106,6 +106,7 @@ async function tryActivate(context: vscode.ExtensionContext) { | |||
106 | ctx.registerCommand('parentModule', commands.parentModule); | 106 | ctx.registerCommand('parentModule', commands.parentModule); |
107 | ctx.registerCommand('syntaxTree', commands.syntaxTree); | 107 | ctx.registerCommand('syntaxTree', commands.syntaxTree); |
108 | ctx.registerCommand('viewHir', commands.viewHir); | 108 | ctx.registerCommand('viewHir', commands.viewHir); |
109 | ctx.registerCommand('viewItemTree', commands.viewItemTree); | ||
109 | ctx.registerCommand('viewCrateGraph', commands.viewCrateGraph); | 110 | ctx.registerCommand('viewCrateGraph', commands.viewCrateGraph); |
110 | ctx.registerCommand('expandMacro', commands.expandMacro); | 111 | ctx.registerCommand('expandMacro', commands.expandMacro); |
111 | ctx.registerCommand('run', commands.run); | 112 | ctx.registerCommand('run', commands.run); |