aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs7
-rw-r--r--crates/rust-analyzer/src/handlers.rs70
-rw-r--r--docs/user/generated_config.adoc2
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts1
5 files changed, 52 insertions, 33 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3ddb9e19a..247bfe71e 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -147,6 +147,9 @@ config_data! {
147 /// Whether to show `Method References` lens. Only applies when 147 /// Whether to show `Method References` lens. Only applies when
148 /// `#rust-analyzer.lens.enable#` is set. 148 /// `#rust-analyzer.lens.enable#` is set.
149 lens_methodReferences: bool = "false", 149 lens_methodReferences: bool = "false",
150 /// Whether to show `References` lens. Only applies when
151 /// `#rust-analyzer.lens.enable#` is set.
152 lens_references: bool = "false",
150 153
151 /// Disable project auto-discovery in favor of explicitly specified set 154 /// Disable project auto-discovery in favor of explicitly specified set
152 /// of projects.\n\nElements must be paths pointing to `Cargo.toml`, 155 /// of projects.\n\nElements must be paths pointing to `Cargo.toml`,
@@ -221,6 +224,7 @@ pub struct LensConfig {
221 pub debug: bool, 224 pub debug: bool,
222 pub implementations: bool, 225 pub implementations: bool,
223 pub method_refs: bool, 226 pub method_refs: bool,
227 pub refs: bool, // for Struct, Enum, Union and Trait
224} 228}
225 229
226impl LensConfig { 230impl LensConfig {
@@ -237,7 +241,7 @@ impl LensConfig {
237 } 241 }
238 242
239 pub fn references(&self) -> bool { 243 pub fn references(&self) -> bool {
240 self.method_refs 244 self.method_refs || self.refs
241 } 245 }
242} 246}
243 247
@@ -593,6 +597,7 @@ impl Config {
593 debug: self.data.lens_enable && self.data.lens_debug, 597 debug: self.data.lens_enable && self.data.lens_debug,
594 implementations: self.data.lens_enable && self.data.lens_implementations, 598 implementations: self.data.lens_enable && self.data.lens_implementations,
595 method_refs: self.data.lens_enable && self.data.lens_methodReferences, 599 method_refs: self.data.lens_enable && self.data.lens_methodReferences,
600 refs: self.data.lens_enable && self.data.lens_references,
596 } 601 }
597 } 602 }
598 pub fn hover(&self) -> HoverConfig { 603 pub fn hover(&self) -> HoverConfig {
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 809452e6d..07204436c 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1112,42 +1112,48 @@ pub(crate) fn handle_code_lens(
1112 } 1112 }
1113 } 1113 }
1114 1114
1115 if lens_config.implementations { 1115 if lens_config.implementations || lens_config.refs {
1116 // Handle impls 1116 snap.analysis
1117 lenses.extend( 1117 .file_structure(file_id)?
1118 snap.analysis 1118 .into_iter()
1119 .file_structure(file_id)? 1119 .filter(|it| {
1120 .into_iter() 1120 matches!(
1121 .filter(|it| { 1121 it.kind,
1122 matches!( 1122 SymbolKind::Trait | SymbolKind::Struct | SymbolKind::Enum | SymbolKind::Union
1123 it.kind, 1123 )
1124 SymbolKind::Trait 1124 })
1125 | SymbolKind::Struct 1125 .for_each(|it| {
1126 | SymbolKind::Enum 1126 let range = to_proto::range(&line_index, it.node_range);
1127 | SymbolKind::Union 1127 let position = to_proto::position(&line_index, it.navigation_range.start());
1128 ) 1128 let doc_pos = lsp_types::TextDocumentPositionParams::new(
1129 }) 1129 params.text_document.clone(),
1130 .map(|it| { 1130 position,
1131 let range = to_proto::range(&line_index, it.node_range); 1131 );
1132 let pos = range.start; 1132 let goto_params = lsp_types::request::GotoImplementationParams {
1133 let lens_params = lsp_types::request::GotoImplementationParams { 1133 text_document_position_params: doc_pos.clone(),
1134 text_document_position_params: lsp_types::TextDocumentPositionParams::new( 1134 work_done_progress_params: Default::default(),
1135 params.text_document.clone(), 1135 partial_result_params: Default::default(),
1136 pos, 1136 };
1137 ), 1137
1138 work_done_progress_params: Default::default(), 1138 if lens_config.implementations {
1139 partial_result_params: Default::default(), 1139 lenses.push(CodeLens {
1140 };
1141 CodeLens {
1142 range, 1140 range,
1143 command: None, 1141 command: None,
1144 data: Some(to_value(CodeLensResolveData::Impls(lens_params)).unwrap()), 1142 data: Some(to_value(CodeLensResolveData::Impls(goto_params)).unwrap()),
1145 } 1143 })
1146 }), 1144 }
1147 ); 1145
1146 if lens_config.refs {
1147 lenses.push(CodeLens {
1148 range,
1149 command: None,
1150 data: Some(to_value(CodeLensResolveData::References(doc_pos)).unwrap()),
1151 })
1152 }
1153 });
1148 } 1154 }
1149 1155
1150 if lens_config.references() { 1156 if lens_config.method_refs {
1151 lenses.extend(snap.analysis.find_all_methods(file_id)?.into_iter().map(|it| { 1157 lenses.extend(snap.analysis.find_all_methods(file_id)?.into_iter().map(|it| {
1152 let range = to_proto::range(&line_index, it.range); 1158 let range = to_proto::range(&line_index, it.range);
1153 let position = to_proto::position(&line_index, it.range.start()); 1159 let position = to_proto::position(&line_index, it.range.start());
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index a76c99d1e..2f681b01a 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -86,6 +86,8 @@
86 Whether to show `Run` lens. Only applies when `#rust-analyzer.lens.enable#` is set. 86 Whether to show `Run` lens. Only applies when `#rust-analyzer.lens.enable#` is set.
87[[rust-analyzer.lens.methodReferences]]rust-analyzer.lens.methodReferences (default: `false`):: 87[[rust-analyzer.lens.methodReferences]]rust-analyzer.lens.methodReferences (default: `false`)::
88 Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set. 88 Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set.
89[[rust-analyzer.lens.references]]rust-analyzer.lens.references (default: `false`)::
90 Whether to show `References` lens. Only applies when `#rust-analyzer.lens.enable#` is set.
89[[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`):: 91[[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`)::
90 Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format. 92 Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.
91[[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`):: 93[[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`)::
diff --git a/editors/code/package.json b/editors/code/package.json
index 3e6ebd7ed..2225cf1dd 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -633,6 +633,11 @@
633 "default": false, 633 "default": false,
634 "type": "boolean" 634 "type": "boolean"
635 }, 635 },
636 "rust-analyzer.lens.references": {
637 "markdownDescription": "Whether to show `References` lens. Only applies when `#rust-analyzer.lens.enable#` is set.",
638 "default": false,
639 "type": "boolean"
640 },
636 "rust-analyzer.linkedProjects": { 641 "rust-analyzer.linkedProjects": {
637 "markdownDescription": "Disable project auto-discovery in favor of explicitly specified set of projects.\\n\\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.", 642 "markdownDescription": "Disable project auto-discovery in favor of explicitly specified set of projects.\\n\\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.",
638 "default": [], 643 "default": [],
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index ebe4de1ea..ddb5cfbd3 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -144,6 +144,7 @@ export class Config {
144 debug: this.get<boolean>("lens.debug"), 144 debug: this.get<boolean>("lens.debug"),
145 implementations: this.get<boolean>("lens.implementations"), 145 implementations: this.get<boolean>("lens.implementations"),
146 methodReferences: this.get<boolean>("lens.methodReferences"), 146 methodReferences: this.get<boolean>("lens.methodReferences"),
147 references: this.get<boolean>("lens.references"),
147 }; 148 };
148 } 149 }
149 150