diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 70 |
2 files changed, 44 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 | ||
226 | impl LensConfig { | 230 | impl 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()); |