mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
Split manual.adoc into markdown files, one for each chapter. For the parts of the manual that are generated from source code doc comments, update the comments to use markdown syntax and update the code generators to write to `generated.md` files. For the weekly release, stop copying the .adoc files to the `rust-analyzer/rust-analyzer.github.io` at release time. Instead, we'll sync the manual hourly from this repository. See https://github.com/rust-analyzer/rust-analyzer.github.io/pull/226 for the sync. This PR should be merged first, and that PR needs to be merged before the next weekly release. This change is based on #15795, but rebased and updated. I've also manually checked each page for markdown syntax issues and fixed any I encountered. Co-authored-by: Lukas Wirth <lukastw97@gmail.com> Co-authored-by: Josh Rotenberg <joshrotenberg@gmail.com>
30 lines
1.1 KiB
Rust
30 lines
1.1 KiB
Rust
use hir::{DefWithBody, Semantics};
|
|
use ide_db::{FilePosition, RootDatabase};
|
|
use syntax::{algo::ancestors_at_offset, ast, AstNode};
|
|
|
|
// Feature: View Hir
|
|
//
|
|
// | Editor | Action Name |
|
|
// |---------|--------------|
|
|
// | VS Code | **rust-analyzer: View Hir**
|
|
//
|
|
// 
|
|
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
|
|
body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_owned())
|
|
}
|
|
|
|
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
|
let sema = Semantics::new(db);
|
|
let source_file = sema.parse_guess_edition(position.file_id);
|
|
|
|
let item = ancestors_at_offset(source_file.syntax(), position.offset)
|
|
.filter(|it| !ast::MacroCall::can_cast(it.kind()))
|
|
.find_map(ast::Item::cast)?;
|
|
let def: DefWithBody = match item {
|
|
ast::Item::Fn(it) => sema.to_def(&it)?.into(),
|
|
ast::Item::Const(it) => sema.to_def(&it)?.into(),
|
|
ast::Item::Static(it) => sema.to_def(&it)?.into(),
|
|
_ => return None,
|
|
};
|
|
Some(def.debug_hir(db))
|
|
}
|