aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json26
-rw-r--r--editors/code/src/commands.ts50
-rw-r--r--editors/code/src/lsp_ext.ts6
-rw-r--r--editors/code/src/main.ts1
4 files changed, 76 insertions, 7 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 99223c4e8..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"
@@ -385,21 +390,28 @@
385 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" 390 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
386 }, 391 },
387 "$generated-start": false, 392 "$generated-start": false,
388 "rust-analyzer.assist.importMergeBehavior": { 393 "rust-analyzer.assist.importGranularity": {
389 "markdownDescription": "The strategy to use when inserting new imports or merging imports.", 394 "markdownDescription": "How imports should be grouped into use statements.",
390 "default": "crate", 395 "default": "crate",
391 "type": "string", 396 "type": "string",
392 "enum": [ 397 "enum": [
393 "none", 398 "preserve",
394 "crate", 399 "crate",
395 "module" 400 "module",
401 "item"
396 ], 402 ],
397 "enumDescriptions": [ 403 "enumDescriptions": [
398 "Do not merge imports at all.", 404 "Do not change the granularity of any imports and preserve the original structure written by the developer.",
399 "Merge imports from the same crate into a single `use` statement.", 405 "Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
400 "Merge imports from the same module into a single `use` statement." 406 "Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
407 "Flatten imports so that each has its own use statement."
401 ] 408 ]
402 }, 409 },
410 "rust-analyzer.assist.importEnforceGranularity": {
411 "markdownDescription": "Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.",
412 "default": false,
413 "type": "boolean"
414 },
403 "rust-analyzer.assist.importPrefix": { 415 "rust-analyzer.assist.importPrefix": {
404 "markdownDescription": "The path structure for newly inserted paths to use.", 416 "markdownDescription": "The path structure for newly inserted paths to use.",
405 "default": "plain", 417 "default": "plain",
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 8ab259af2..0fdb9fe05 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
432export function viewItemTree(ctx: Ctx): Cmd {
433 const tdcp = new class implements vscode.TextDocumentContentProvider {
434 readonly uri = vscode.Uri.parse('rust-analyzer://viewItemTree/itemtree.rs');
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
432export function viewCrateGraph(ctx: Ctx): Cmd { 482export 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
28export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>("rust-analyzer/viewHir"); 28export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>("rust-analyzer/viewHir");
29 29
30export interface ViewItemTreeParams {
31 textDocument: lc.TextDocumentIdentifier;
32}
33
34export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>("rust-analyzer/viewItemTree");
35
30export const viewCrateGraph = new lc.RequestType0<string, void>("rust-analyzer/viewCrateGraph"); 36export const viewCrateGraph = new lc.RequestType0<string, void>("rust-analyzer/viewCrateGraph");
31 37
32export interface ExpandMacroParams { 38export 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);