mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-31 20:09:01 +00:00
19 lines
693 B
Rust
19 lines
693 B
Rust
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())
|
|
}
|