1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use hir::Semantics; use ide_db::{FilePosition, RootDatabase}; use syntax::AstNode; // Feature: View Hir // // | Editor | Action Name | // |---------|--------------| // | VS Code | **rust-analyzer: View Hir** // //  pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String { (|| { let sema = Semantics::new(db); let source_file = sema.parse_guess_edition(position.file_id); sema.debug_hir_at(source_file.syntax().token_at_offset(position.offset).next()?) })() .unwrap_or_else(|| "Not inside a lowerable item".to_owned()) }