4175: Introduce HirDisplay method for rendering source code & use it in add_function assist r=flodiebold a=TimoFreiberg

Next feature for #3639.

So far the only change in the new `HirDisplay` method is that paths are qualified, but more changes will be necessary (omitting the function name from function types, returning an error instead of printing `"{unknown}"`, probably more).

Is that approach okay?

Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
This commit is contained in:
bors[bot]
2020-05-09 09:29:11 +00:00
committed by GitHub
5 changed files with 300 additions and 99 deletions

View File

@@ -0,0 +1,23 @@
use super::displayed_source_at_pos;
use crate::test_db::TestDB;
use ra_db::fixture::WithFixture;
#[test]
fn qualify_path_to_submodule() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs
mod foo {
pub struct Foo;
}
fn bar() {
let foo: foo::Foo = foo::Foo;
foo<|>
}
"#,
);
assert_eq!("foo::Foo", displayed_source_at_pos(&db, pos));
}