diff options
| -rw-r--r-- | crates/ide/src/doc_links.rs | 28 | ||||
| -rw-r--r-- | editors/code/rust.tmGrammar.json | 53 |
2 files changed, 58 insertions, 23 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index b9d8b8a2b5b..250f10f9fd6 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { let import_map = db.import_map(krate.into()); let base = once(krate.display_name(db)?.to_string()) .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) - .join("/"); + .join("/") + + "/"; let filename = get_symbol_filename(db, &target_def); let fragment = match definition { @@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { _ => None, }; - get_doc_url(db, &krate) - .and_then(|url| url.join(&base).ok()) - .and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok())) + get_doc_url(db, &krate)? + .join(&base) + .ok() + .and_then(|mut url| { + if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) { + url.path_segments_mut().ok()?.pop(); + }; + Some(url) + }) + .and_then(|url| url.join(filename.as_deref()?).ok()) .and_then( |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, ) @@ -522,6 +530,18 @@ pub struct Foo { ); } + #[test] + fn test_module() { + check( + r#" +pub mod foo { + pub mod ba<|>r {} +} + "#, + expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]], + ) + } + // FIXME: ImportMap will return re-export paths instead of public module // paths. The correct path to documentation will never be a re-export. // This problem stops us from resolving stdlib items included in the prelude diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json index 3be56519511..f0c5c3cf314 100644 --- a/editors/code/rust.tmGrammar.json +++ b/editors/code/rust.tmGrammar.json @@ -25,6 +25,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -185,6 +188,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -212,6 +218,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -232,6 +241,9 @@ ] }, { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -277,31 +289,30 @@ { "comment": "documentation comments", "name": "comment.line.documentation.rust", - "match": "^\\s*///.*", - "patterns": [ - { - "include": "#comments" - } - ] + "match": "^\\s*///.*" }, { "comment": "line comments", "name": "comment.line.double-slash.rust", - "match": "\\s*//.*", - "patterns": [ - { - "include": "#comments" - } - ] + "match": "\\s*//.*" }, { + "comment": "inferred types, wildcard patterns, ignored params", + "name": "comment.char.underscore.rust", + "match": "\\b_\\w*\\b[^!(]" + } + ] + }, + "block-comments": { + "patterns": [ + { "comment": "block comments", "name": "comment.block.rust", "begin": "/\\*(?!\\*)", "end": "\\*/", "patterns": [ { - "include": "#comments" + "include": "#block-comments" } ] }, @@ -312,14 +323,9 @@ "end": "\\*/", "patterns": [ { - "include": "#comments" + "include": "#block-comments" } ] - }, - { - "comment": "inferred types, wildcard patterns, ignored params", - "name": "comment.char.underscore.rust", - "match": "\\b_\\w*\\b" } ] }, @@ -451,6 +457,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -517,6 +526,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { @@ -798,6 +810,9 @@ }, "patterns": [ { + "include": "#block-comments" + }, + { "include": "#comments" }, { |
