Switch to Path::parse and add tests

This commit is contained in:
Zac Pullar-Strecker 2020-06-30 20:23:06 +12:00
parent 48d858f54d
commit 3e22f80f44

View file

@ -17,7 +17,7 @@ use ra_ide_db::{
RootDatabase, RootDatabase,
}; };
use ra_syntax::{ use ra_syntax::{
ast, ast::{Path, MacroCall}, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TokenAtOffset, ast, ast::Path, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset,
}; };
use ra_tt::{Ident, Leaf, Literal, TokenTree}; use ra_tt::{Ident, Leaf, Literal, TokenTree};
use url::Url; use url::Url;
@ -534,10 +534,7 @@ fn try_resolve_intra(
let link_target = strip_prefixes_suffixes(link_target); let link_target = strip_prefixes_suffixes(link_target);
// Parse link as a module path // Parse link as a module path
// This expects a full document, which a single path isn't, but we can just ignore the errors. let path = Path::parse(link_target).ok()?;
let parsed = SyntaxNode::new_root(ra_syntax::parse_text(link_target).0);
// TODO: Proper parsing
let path = parsed.descendants().filter_map(Path::cast).next()?;
let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap();
// Resolve it relative to symbol's location (according to the RFC this should consider small scopes // Resolve it relative to symbol's location (according to the RFC this should consider small scopes
@ -613,7 +610,6 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
let attrs = db.attrs(AttrDef::from(krate.root_module(db)?).into()); let attrs = db.attrs(AttrDef::from(krate.root_module(db)?).into());
let doc_attr_q = attrs.by_key("doc"); let doc_attr_q = attrs.by_key("doc");
// TODO: Tests for this parsing
let doc_url = if doc_attr_q.exists() { let doc_url = if doc_attr_q.exists() {
doc_attr_q.tt_values().map(|tt| { doc_attr_q.tt_values().map(|tt| {
let name = tt.token_trees.iter() let name = tt.token_trees.iter()
@ -1834,7 +1830,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -1878,7 +1874,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -1897,7 +1893,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Arg", mod_path: "test::Arg",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -1941,7 +1937,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -1960,7 +1956,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Arg", mod_path: "test::Arg",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2007,7 +2003,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "A", mod_path: "test::A",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2026,7 +2022,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "B", mod_path: "test::B",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2045,7 +2041,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "M::C", mod_path: "test::M::C",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2090,7 +2086,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2136,7 +2132,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2155,7 +2151,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2201,7 +2197,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2220,7 +2216,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Bar", mod_path: "test::Bar",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2268,7 +2264,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2287,7 +2283,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Bar", mod_path: "test::Bar",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2306,7 +2302,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S1", mod_path: "test::S1",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2325,7 +2321,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S2", mod_path: "test::S2",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2365,7 +2361,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2408,7 +2404,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2427,7 +2423,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Bar", mod_path: "test::Bar",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2446,7 +2442,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2487,7 +2483,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2506,7 +2502,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2555,7 +2551,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "B", mod_path: "test::B",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2574,7 +2570,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2614,7 +2610,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2655,7 +2651,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2674,7 +2670,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2718,7 +2714,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "ImplTrait", mod_path: "test::ImplTrait",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2737,7 +2733,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "B", mod_path: "test::B",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2756,7 +2752,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "DynTrait", mod_path: "test::DynTrait",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2775,7 +2771,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
}, },
}, },
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "S", mod_path: "test::S",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,
@ -2832,7 +2828,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
GoToType( GoToType(
[ [
HoverGotoTypeData { HoverGotoTypeData {
mod_path: "Foo", mod_path: "test::Foo",
nav: NavigationTarget { nav: NavigationTarget {
file_id: FileId( file_id: FileId(
1, 1,