diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/docs.rs | 10 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/markdown.rs | 23 |
4 files changed, 13 insertions, 23 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 59d7d589a..861d6aefe 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -12,7 +12,6 @@ use crate::{ | |||
12 | ty::{TraitRef, InferenceResult, primitive::{IntTy, FloatTy, Signedness, IntBitness, FloatBitness}}, | 12 | ty::{TraitRef, InferenceResult, primitive::{IntTy, FloatTy, Signedness, IntBitness, FloatBitness}}, |
13 | adt::{EnumVariantId, StructFieldId, VariantDef}, | 13 | adt::{EnumVariantId, StructFieldId, VariantDef}, |
14 | generics::HasGenericParams, | 14 | generics::HasGenericParams, |
15 | docs::{Documentation, Docs, docs_from_ast}, | ||
16 | ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId, MacroDefId}, | 15 | ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId, MacroDefId}, |
17 | impl_block::ImplBlock, | 16 | impl_block::ImplBlock, |
18 | resolve::Resolver, | 17 | resolve::Resolver, |
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index c2279fe95..38c0922eb 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -1,24 +1,24 @@ | |||
1 | use ra_syntax::ast; | 1 | use ra_syntax::ast; |
2 | 2 | ||
3 | use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union}; | 3 | use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource}; |
4 | 4 | ||
5 | /// Holds documentation | 5 | /// Holds documentation |
6 | #[derive(Debug, Clone)] | 6 | #[derive(Debug, Clone)] |
7 | pub struct Documentation(String); | 7 | pub struct Documentation(String); |
8 | 8 | ||
9 | impl Documentation { | 9 | impl Documentation { |
10 | pub fn new(s: &str) -> Self { | 10 | fn new(s: &str) -> Documentation { |
11 | Self(s.into()) | 11 | Documentation(s.into()) |
12 | } | 12 | } |
13 | 13 | ||
14 | pub fn contents(&self) -> &str { | 14 | pub fn as_str(&self) -> &str { |
15 | &self.0 | 15 | &self.0 |
16 | } | 16 | } |
17 | } | 17 | } |
18 | 18 | ||
19 | impl Into<String> for Documentation { | 19 | impl Into<String> for Documentation { |
20 | fn into(self) -> String { | 20 | fn into(self) -> String { |
21 | self.contents().into() | 21 | self.0.clone() |
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 88d29b256..257492589 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -171,7 +171,7 @@ impl Conv for ra_ide_api::Documentation { | |||
171 | fn conv(self) -> Documentation { | 171 | fn conv(self) -> Documentation { |
172 | Documentation::MarkupContent(MarkupContent { | 172 | Documentation::MarkupContent(MarkupContent { |
173 | kind: MarkupKind::Markdown, | 173 | kind: MarkupKind::Markdown, |
174 | value: crate::markdown::sanitize_markdown(self).into(), | 174 | value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()).into(), |
175 | }) | 175 | }) |
176 | } | 176 | } |
177 | } | 177 | } |
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs index f505755e8..e382eee90 100644 --- a/crates/ra_lsp_server/src/markdown.rs +++ b/crates/ra_lsp_server/src/markdown.rs | |||
@@ -1,26 +1,20 @@ | |||
1 | use ra_ide_api::Documentation; | 1 | pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String { |
2 | |||
3 | pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation { | ||
4 | let docs: String = docs.into(); | ||
5 | |||
6 | // Massage markdown | ||
7 | let mut processed_lines = Vec::new(); | 2 | let mut processed_lines = Vec::new(); |
8 | let mut in_code_block = false; | 3 | let mut in_code_block = false; |
9 | for line in docs.lines() { | 4 | for line in src.lines() { |
10 | if line.starts_with("```") { | 5 | if line.starts_with("```") { |
11 | in_code_block = !in_code_block; | 6 | in_code_block ^= true |
12 | } | 7 | } |
13 | 8 | ||
14 | let line = if in_code_block && line.starts_with("```") && !line.contains("rust") { | 9 | let line = if in_code_block && line.starts_with("```") && !line.contains("rust") { |
15 | "```rust".into() | 10 | "```rust" |
16 | } else { | 11 | } else { |
17 | line.to_string() | 12 | line |
18 | }; | 13 | }; |
19 | 14 | ||
20 | processed_lines.push(line); | 15 | processed_lines.push(line); |
21 | } | 16 | } |
22 | 17 | processed_lines.join("\n") | |
23 | Documentation::new(&processed_lines.join("\n")) | ||
24 | } | 18 | } |
25 | 19 | ||
26 | #[cfg(test)] | 20 | #[cfg(test)] |
@@ -30,9 +24,6 @@ mod tests { | |||
30 | #[test] | 24 | #[test] |
31 | fn test_codeblock_adds_rust() { | 25 | fn test_codeblock_adds_rust() { |
32 | let comment = "```\nfn some_rust() {}\n```"; | 26 | let comment = "```\nfn some_rust() {}\n```"; |
33 | assert_eq!( | 27 | assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```"); |
34 | sanitize_markdown(Documentation::new(comment)).contents(), | ||
35 | "```rust\nfn some_rust() {}\n```" | ||
36 | ); | ||
37 | } | 28 | } |
38 | } | 29 | } |