mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
More orthogonal API for building paths
This commit is contained in:
parent
7cf710c66f
commit
ca713e462b
3 changed files with 25 additions and 15 deletions
|
@ -12,11 +12,14 @@ pub fn name_ref(text: &str) -> ast::NameRef {
|
|||
ast_from_text(&format!("fn f() {{ {}; }}", text))
|
||||
}
|
||||
|
||||
pub fn path_from_name_ref(name_ref: ast::NameRef) -> ast::Path {
|
||||
path_from_text(&name_ref.syntax().to_string())
|
||||
pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
|
||||
ast_from_text(&format!("use {};", name_ref.syntax()))
|
||||
}
|
||||
pub fn path_qualified(qual: ast::Path, name_ref: ast::NameRef) -> ast::Path {
|
||||
path_from_text(&format!("{}::{}", qual.syntax(), name_ref.syntax()))
|
||||
pub fn path_unqalified(segment: ast::PathSegment) -> ast::Path {
|
||||
path_from_text(&format!("use {}", segment.syntax()))
|
||||
}
|
||||
pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path {
|
||||
path_from_text(&format!("{}::{}", qual.syntax(), segment.syntax()))
|
||||
}
|
||||
fn path_from_text(text: &str) -> ast::Path {
|
||||
ast_from_text(text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue