Compute linked editing ranges for the symbol under the cursor. Returns `Some` only when the cursor is on a variable (not a property declaration) that has at least two occurrences in its definition region. A single occurrence offers nothing to link.
(
&self,
uri: &str,
content: &str,
position: Position,
)
| 44 | /// property declaration) that has at least two occurrences in its |
| 45 | /// definition region. A single occurrence offers nothing to link. |
| 46 | pub fn handle_linked_editing_range( |
| 47 | &self, |
| 48 | uri: &str, |
| 49 | content: &str, |
| 50 | position: Position, |
| 51 | ) -> Option<LinkedEditingRanges> { |
| 52 | let span = self.lookup_symbol_at_position(uri, content, position)?; |
| 53 | |
| 54 | let maps = self.symbol_maps.read(); |
| 55 | let symbol_map = maps.get(uri)?; |
| 56 | |
| 57 | match &span.kind { |
| 58 | SymbolKind::Variable { name } => { |
| 59 | // Property declarations should not trigger linked editing — |
| 60 | // renaming a property requires cross-file awareness. |
| 61 | if let Some(VarDefKind::Property) = symbol_map.var_def_kind_at(name, span.start) { |
| 62 | return None; |
| 63 | } |
| 64 | |
| 65 | let ranges = |
| 66 | collect_variable_ranges_in_region(symbol_map, content, name, span.start); |
| 67 | |
| 68 | // Linked editing with fewer than 2 ranges is pointless. |
| 69 | if ranges.len() < 2 { |
| 70 | return None; |
| 71 | } |
| 72 | |
| 73 | Some(LinkedEditingRanges { |
| 74 | ranges, |
| 75 | word_pattern: None, |
| 76 | }) |
| 77 | } |
| 78 | _ => None, |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /// A definition region identified by its owning [`VarDefSite`]. |
no test coverage detected