MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / handle_hover

Method handle_hover

src/hover/mod.rs:448–476  ·  view source on GitHub ↗

Handle a `textDocument/hover` request. Returns `Some(Hover)` when the symbol under the cursor can be resolved to a meaningful description, or `None` when resolution fails or the cursor is not on a navigable symbol.

(&self, uri: &str, content: &str, position: Position)

Source from the content-addressed store, hash-verified

446 /// resolved to a meaningful description, or `None` when resolution
447 /// fails or the cursor is not on a navigable symbol.
448 pub fn handle_hover(&self, uri: &str, content: &str, position: Position) -> Option<Hover> {
449 let _body_infer_guard = self.activate_body_return_inferrer();
450 let offset = crate::util::position_to_offset(content, position);
451
452 // Try the exact cursor offset first.
453 if let Some(symbol) = self.lookup_symbol_map(uri, offset)
454 && let Some(Some(mut hover)) =
455 crate::util::catch_panic_unwind_safe("hover", uri, Some(position), || {
456 self.hover_from_symbol(&symbol, uri, content, offset)
457 })
458 {
459 hover.range = Some(symbol_span_to_range(content, &symbol));
460 return Some(hover);
461 }
462
463 // Retry one byte earlier for end-of-token edge cases.
464 if offset > 0
465 && let Some(symbol) = self.lookup_symbol_map(uri, offset - 1)
466 && let Some(Some(mut hover)) =
467 crate::util::catch_panic_unwind_safe("hover", uri, Some(position), || {
468 self.hover_from_symbol(&symbol, uri, content, offset - 1)
469 })
470 {
471 hover.range = Some(symbol_span_to_range(content, &symbol));
472 return Some(hover);
473 }
474
475 None
476 }
477
478 /// Dispatch a symbol-map hit to the appropriate hover path.
479 fn hover_from_symbol(

Calls 6

catch_panic_unwind_safeFunction · 0.85
symbol_span_to_rangeFunction · 0.85
lookup_symbol_mapMethod · 0.80
hover_from_symbolMethod · 0.80
position_to_offsetFunction · 0.50