| @@ -171,173 +171,170 @@ pub fn update_inlay_link_and_hover_points( · 170 unmodified lines |
| 171 | 171 | shift_held: bool, |
| 172 | 172 | cx: &mut ViewContext<'_, Editor>, |
| 173 | 173 | ) { |
| 174 | | − todo!("old implementation below") |
| 175 | | −} |
| 176 | | −// ) { |
| 177 | | −// let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 { |
| 178 | | −// Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left)) |
| 179 | | −// } else { |
| 180 | | −// None |
| 181 | | −// }; |
| 182 | | −// let mut go_to_definition_updated = false; |
| 183 | | −// let mut hover_updated = false; |
| 184 | | −// if let Some(hovered_offset) = hovered_offset { |
| 185 | | −// let buffer_snapshot = editor.buffer().read(cx).snapshot(cx); |
| 186 | | −// let previous_valid_anchor = buffer_snapshot.anchor_at( |
| 187 | | −// point_for_position.previous_valid.to_point(snapshot), |
| 188 | | −// Bias::Left, |
| 189 | | −// ); |
| 190 | | −// let next_valid_anchor = buffer_snapshot.anchor_at( |
| 191 | | −// point_for_position.next_valid.to_point(snapshot), |
| 192 | | −// Bias::Right, |
| 193 | | −// ); |
| 194 | | −// if let Some(hovered_hint) = editor |
| 195 | | −// .visible_inlay_hints(cx) |
| 196 | | −// .into_iter() |
| 197 | | −// .skip_while(|hint| { |
| 198 | | −// hint.position |
| 199 | | −// .cmp(&previous_valid_anchor, &buffer_snapshot) |
| 200 | | −// .is_lt() |
| 201 | | −// }) |
| 202 | | −// .take_while(|hint| { |
| 203 | | −// hint.position |
| 204 | | −// .cmp(&next_valid_anchor, &buffer_snapshot) |
| 205 | | −// .is_le() |
| 206 | | −// }) |
| 207 | | −// .max_by_key(|hint| hint.id) |
| 208 | | −// { |
| 209 | | −// let inlay_hint_cache = editor.inlay_hint_cache(); |
| 210 | | −// let excerpt_id = previous_valid_anchor.excerpt_id; |
| 211 | | −// if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) { |
| 212 | | −// match cached_hint.resolve_state { |
| 213 | | −// ResolveState::CanResolve(_, _) => { |
| 214 | | −// if let Some(buffer_id) = previous_valid_anchor.buffer_id { |
| 215 | | −// inlay_hint_cache.spawn_hint_resolve( |
| 216 | | −// buffer_id, |
| 217 | | −// excerpt_id, |
| 218 | | −// hovered_hint.id, |
| 219 | | −// cx, |
| 220 | | −// ); |
| 221 | | −// } |
| 222 | | −// } |
| 223 | | −// ResolveState::Resolved => { |
| 224 | | −// let mut extra_shift_left = 0; |
| 225 | | −// let mut extra_shift_right = 0; |
| 226 | | −// if cached_hint.padding_left { |
| 227 | | −// extra_shift_left += 1; |
| 228 | | −// extra_shift_right += 1; |
| 229 | | −// } |
| 230 | | −// if cached_hint.padding_right { |
| 231 | | −// extra_shift_right += 1; |
| 232 | | −// } |
| 233 | | −// match cached_hint.label { |
| 234 | | −// project::InlayHintLabel::String(_) => { |
| 235 | | −// if let Some(tooltip) = cached_hint.tooltip { |
| 236 | | −// hover_popover::hover_at_inlay( |
| 237 | | −// editor, |
| 238 | | −// InlayHover { |
| 239 | | −// excerpt: excerpt_id, |
| 240 | | −// tooltip: match tooltip { |
| 241 | | −// InlayHintTooltip::String(text) => HoverBlock { |
| 242 | | −// text, |
| 243 | | −// kind: HoverBlockKind::PlainText, |
| 244 | | −// }, |
| 245 | | −// InlayHintTooltip::MarkupContent(content) => { |
| 246 | | −// HoverBlock { |
| 247 | | −// text: content.value, |
| 248 | | −// kind: content.kind, |
| 249 | | −// } |
| 250 | | −// } |
| 251 | | −// }, |
| 252 | | −// range: InlayHighlight { |
| 253 | | −// inlay: hovered_hint.id, |
| 254 | | −// inlay_position: hovered_hint.position, |
| 255 | | −// range: extra_shift_left |
| 256 | | −// ..hovered_hint.text.len() + extra_shift_right, |
| 257 | | −// }, |
| 258 | | −// }, |
| 259 | | −// cx, |
| 260 | | −// ); |
| 261 | | −// hover_updated = true; |
| 262 | | −// } |
| 263 | | −// } |
| 264 | | −// project::InlayHintLabel::LabelParts(label_parts) => { |
| 265 | | −// let hint_start = |
| 266 | | −// snapshot.anchor_to_inlay_offset(hovered_hint.position); |
| 267 | | −// if let Some((hovered_hint_part, part_range)) = |
| 268 | | −// hover_popover::find_hovered_hint_part( |
| 269 | | −// label_parts, |
| 270 | | −// hint_start, |
| 271 | | −// hovered_offset, |
| 272 | | −// ) |
| 273 | | −// { |
| 274 | | −// let highlight_start = |
| 275 | | −// (part_range.start - hint_start).0 + extra_shift_left; |
| 276 | | −// let highlight_end = |
| 277 | | −// (part_range.end - hint_start).0 + extra_shift_right; |
| 278 | | −// let highlight = InlayHighlight { |
| 279 | | −// inlay: hovered_hint.id, |
| 280 | | −// inlay_position: hovered_hint.position, |
| 281 | | −// range: highlight_start..highlight_end, |
| 282 | | −// }; |
| 283 | | −// if let Some(tooltip) = hovered_hint_part.tooltip { |
| 284 | | −// hover_popover::hover_at_inlay( |
| 285 | | −// editor, |
| 286 | | −// InlayHover { |
| 287 | | −// excerpt: excerpt_id, |
| 288 | | −// tooltip: match tooltip { |
| 289 | | −// InlayHintLabelPartTooltip::String(text) => { |
| 290 | | −// HoverBlock { |
| 291 | | −// text, |
| 292 | | −// kind: HoverBlockKind::PlainText, |
| 293 | | −// } |
| 294 | | −// } |
| 295 | | −// InlayHintLabelPartTooltip::MarkupContent( |
| 296 | | −// content, |
| 297 | | −// ) => HoverBlock { |
| 298 | | −// text: content.value, |
| 299 | | −// kind: content.kind, |
| 300 | | −// }, |
| 301 | | −// }, |
| 302 | | −// range: highlight.clone(), |
| 303 | | −// }, |
| 304 | | −// cx, |
| 305 | | −// ); |
| 306 | | −// hover_updated = true; |
| 307 | | −// } |
| 308 | | −// if let Some((language_server_id, location)) = |
| 309 | | −// hovered_hint_part.location |
| 310 | | −// { |
| 311 | | −// go_to_definition_updated = true; |
| 312 | | −// update_go_to_definition_link( |
| 313 | | −// editor, |
| 314 | | −// Some(GoToDefinitionTrigger::InlayHint( |
| 315 | | −// highlight, |
| 316 | | −// location, |
| 317 | | −// language_server_id, |
| 318 | | −// )), |
| 319 | | −// cmd_held, |
| 320 | | −// shift_held, |
| 321 | | −// cx, |
| 322 | | −// ); |
| 323 | | −// } |
| 324 | | −// } |
| 325 | | −// } |
| 326 | | −// }; |
| 327 | | −// } |
| 328 | | −// ResolveState::Resolving => {} |
| 329 | | −// } |
| 330 | | −// } |
| 331 | | −// } |
| 332 | | −// } |
| 174 | + let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 { |
| 175 | + Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left)) |
| 176 | + } else { |
| 177 | + None |
| 178 | + }; |
| 179 | + let mut go_to_definition_updated = false; |
| 180 | + let mut hover_updated = false; |
| 181 | + if let Some(hovered_offset) = hovered_offset { |
| 182 | + let buffer_snapshot = editor.buffer().read(cx).snapshot(cx); |
| 183 | + let previous_valid_anchor = buffer_snapshot.anchor_at( |
| 184 | + point_for_position.previous_valid.to_point(snapshot), |
| 185 | + Bias::Left, |
| 186 | + ); |
| 187 | + let next_valid_anchor = buffer_snapshot.anchor_at( |
| 188 | + point_for_position.next_valid.to_point(snapshot), |
| 189 | + Bias::Right, |
| 190 | + ); |
| 191 | + if let Some(hovered_hint) = editor |
| 192 | + .visible_inlay_hints(cx) |
| 193 | + .into_iter() |
| 194 | + .skip_while(|hint| { |
| 195 | + hint.position |
| 196 | + .cmp(&previous_valid_anchor, &buffer_snapshot) |
| 197 | + .is_lt() |
| 198 | + }) |
| 199 | + .take_while(|hint| { |
| 200 | + hint.position |
| 201 | + .cmp(&next_valid_anchor, &buffer_snapshot) |
| 202 | + .is_le() |
| 203 | + }) |
| 204 | + .max_by_key(|hint| hint.id) |
| 205 | + { |
| 206 | + let inlay_hint_cache = editor.inlay_hint_cache(); |
| 207 | + let excerpt_id = previous_valid_anchor.excerpt_id; |
| 208 | + if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) { |
| 209 | + match cached_hint.resolve_state { |
| 210 | + ResolveState::CanResolve(_, _) => { |
| 211 | + if let Some(buffer_id) = previous_valid_anchor.buffer_id { |
| 212 | + inlay_hint_cache.spawn_hint_resolve( |
| 213 | + buffer_id, |
| 214 | + excerpt_id, |
| 215 | + hovered_hint.id, |
| 216 | + cx, |
| 217 | + ); |
| 218 | + } |
| 219 | + } |
| 220 | + ResolveState::Resolved => { |
| 221 | + let mut extra_shift_left = 0; |
| 222 | + let mut extra_shift_right = 0; |
| 223 | + if cached_hint.padding_left { |
| 224 | + extra_shift_left += 1; |
| 225 | + extra_shift_right += 1; |
| 226 | + } |
| 227 | + if cached_hint.padding_right { |
| 228 | + extra_shift_right += 1; |
| 229 | + } |
| 230 | + match cached_hint.label { |
| 231 | + project::InlayHintLabel::String(_) => { |
| 232 | + if let Some(tooltip) = cached_hint.tooltip { |
| 233 | + hover_popover::hover_at_inlay( |
| 234 | + editor, |
| 235 | + InlayHover { |
| 236 | + excerpt: excerpt_id, |
| 237 | + tooltip: match tooltip { |
| 238 | + InlayHintTooltip::String(text) => HoverBlock { |
| 239 | + text, |
| 240 | + kind: HoverBlockKind::PlainText, |
| 241 | + }, |
| 242 | + InlayHintTooltip::MarkupContent(content) => { |
| 243 | + HoverBlock { |
| 244 | + text: content.value, |
| 245 | + kind: content.kind, |
| 246 | + } |
| 247 | + } |
| 248 | + }, |
| 249 | + range: InlayHighlight { |
| 250 | + inlay: hovered_hint.id, |
| 251 | + inlay_position: hovered_hint.position, |
| 252 | + range: extra_shift_left |
| 253 | + ..hovered_hint.text.len() + extra_shift_right, |
| 254 | + }, |
| 255 | + }, |
| 256 | + cx, |
| 257 | + ); |
| 258 | + hover_updated = true; |
| 259 | + } |
| 260 | + } |
| 261 | + project::InlayHintLabel::LabelParts(label_parts) => { |
| 262 | + let hint_start = |
| 263 | + snapshot.anchor_to_inlay_offset(hovered_hint.position); |
| 264 | + if let Some((hovered_hint_part, part_range)) = |
| 265 | + hover_popover::find_hovered_hint_part( |
| 266 | + label_parts, |
| 267 | + hint_start, |
| 268 | + hovered_offset, |
| 269 | + ) |
| 270 | + { |
| 271 | + let highlight_start = |
| 272 | + (part_range.start - hint_start).0 + extra_shift_left; |
| 273 | + let highlight_end = |
| 274 | + (part_range.end - hint_start).0 + extra_shift_right; |
| 275 | + let highlight = InlayHighlight { |
| 276 | + inlay: hovered_hint.id, |
| 277 | + inlay_position: hovered_hint.position, |
| 278 | + range: highlight_start..highlight_end, |
| 279 | + }; |
| 280 | + if let Some(tooltip) = hovered_hint_part.tooltip { |
| 281 | + hover_popover::hover_at_inlay( |
| 282 | + editor, |
| 283 | + InlayHover { |
| 284 | + excerpt: excerpt_id, |
| 285 | + tooltip: match tooltip { |
| 286 | + InlayHintLabelPartTooltip::String(text) => { |
| 287 | + HoverBlock { |
| 288 | + text, |
| 289 | + kind: HoverBlockKind::PlainText, |
| 290 | + } |
| 291 | + } |
| 292 | + InlayHintLabelPartTooltip::MarkupContent( |
| 293 | + content, |
| 294 | + ) => HoverBlock { |
| 295 | + text: content.value, |
| 296 | + kind: content.kind, |
| 297 | + }, |
| 298 | + }, |
| 299 | + range: highlight.clone(), |
| 300 | + }, |
| 301 | + cx, |
| 302 | + ); |
| 303 | + hover_updated = true; |
| 304 | + } |
| 305 | + if let Some((language_server_id, location)) = |
| 306 | + hovered_hint_part.location |
| 307 | + { |
| 308 | + go_to_definition_updated = true; |
| 309 | + update_go_to_definition_link( |
| 310 | + editor, |
| 311 | + Some(GoToDefinitionTrigger::InlayHint( |
| 312 | + highlight, |
| 313 | + location, |
| 314 | + language_server_id, |
| 315 | + )), |
| 316 | + cmd_held, |
| 317 | + shift_held, |
| 318 | + cx, |
| 319 | + ); |
| 320 | + } |
| 321 | + } |
| 322 | + } |
| 323 | + }; |
| 324 | + } |
| 325 | + ResolveState::Resolving => {} |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | + } |
| 333 | 330 | |
| 334 | | −// if !go_to_definition_updated { |
| 335 | | −// update_go_to_definition_link(editor, None, cmd_held, shift_held, cx); |
| 336 | | −// } |
| 337 | | −// if !hover_updated { |
| 338 | | −// hover_popover::hover_at(editor, None, cx); |
| 339 | | −// } |
| 340 | | −// } |
| 331 | + if !go_to_definition_updated { |
| 332 | + update_go_to_definition_link(editor, None, cmd_held, shift_held, cx); |
| 333 | + } |
| 334 | + if !hover_updated { |
| 335 | + hover_popover::hover_at(editor, None, cx); |
| 336 | + } |
| 337 | +} |
| 341 | 338 | |
| 342 | 339 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 343 | 340 | pub enum LinkDefinitionKind { |