-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7068: Add VSCode command to view the hir of a function body r=theotherphil a=theotherphil Will fix #7061. Very rough initial version just to work out where I needed to wire everything up. @matklad would you be happy merging a hir visualiser of some kind? If so, do you have any thoughts on what you'd like it show, and how? I've spent very little time on this thus far, so I'm fine with throwing away the contents of this PR, but I want to avoid taking the time to make this more polished/interactive/useful only to discover that no-one else has any interest in this functionality. ![image](https://user-images.githubusercontent.com/1974256/103236081-bb58f700-493b-11eb-9d12-55ae1b870f8f.png) Co-authored-by: Phil Ellison <phil.j.ellison@gmail.com>
- Loading branch information
Showing
12 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use hir::{Function, Semantics}; | ||
use ide_db::base_db::FilePosition; | ||
use ide_db::RootDatabase; | ||
use syntax::{algo::find_node_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("Not inside a function body".to_string()) | ||
} | ||
|
||
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> { | ||
let sema = Semantics::new(db); | ||
let source_file = sema.parse(position.file_id); | ||
|
||
let function = find_node_at_offset::<ast::Fn>(source_file.syntax(), position.offset)?; | ||
|
||
let function: Function = sema.to_def(&function)?; | ||
Some(function.debug_hir(db)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters