diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-27 09:23:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-27 09:23:55 +0000 |
commit | 5a3d2332f8d5e382fc06210c260ff6db857ac716 (patch) | |
tree | 0e12aa5d4bcdfb609faa76e01e49854ac95ccadd /crates/ra_assists/src/assists/raw_string.rs | |
parent | a455635b48b9b43904488bb33454c67e513bccf7 (diff) | |
parent | da5528824a836a4f36f44f90adc9fadcc98ca75b (diff) |
Merge #2086
2086: document almost all assists r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assists/raw_string.rs')
-rw-r--r-- | crates/ra_assists/src/assists/raw_string.rs | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs index ea756d1ca..2df48a838 100644 --- a/crates/ra_assists/src/assists/raw_string.rs +++ b/crates/ra_assists/src/assists/raw_string.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | SyntaxKind::{RAW_STRING, STRING}, | 3 | SyntaxKind::{RAW_STRING, STRING}, |
@@ -9,6 +7,21 @@ use rustc_lexer; | |||
9 | 7 | ||
10 | use crate::{Assist, AssistCtx, AssistId}; | 8 | use crate::{Assist, AssistCtx, AssistId}; |
11 | 9 | ||
10 | // Assist: make_raw_string | ||
11 | // | ||
12 | // Adds `r#` to a plain string literal. | ||
13 | // | ||
14 | // ``` | ||
15 | // fn main() { | ||
16 | // "Hello,<|> World!"; | ||
17 | // } | ||
18 | // ``` | ||
19 | // -> | ||
20 | // ``` | ||
21 | // fn main() { | ||
22 | // r#"Hello, World!"#; | ||
23 | // } | ||
24 | // ``` | ||
12 | pub(crate) fn make_raw_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 25 | pub(crate) fn make_raw_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
13 | let token = ctx.find_token_at_offset(STRING)?; | 26 | let token = ctx.find_token_at_offset(STRING)?; |
14 | let text = token.text().as_str(); | 27 | let text = token.text().as_str(); |
@@ -40,6 +53,21 @@ pub(crate) fn make_raw_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As | |||
40 | ctx.build() | 53 | ctx.build() |
41 | } | 54 | } |
42 | 55 | ||
56 | // Assist: make_usual_string | ||
57 | // | ||
58 | // Turns a raw string into a plain string. | ||
59 | // | ||
60 | // ``` | ||
61 | // fn main() { | ||
62 | // r#"Hello,<|> "World!""#; | ||
63 | // } | ||
64 | // ``` | ||
65 | // -> | ||
66 | // ``` | ||
67 | // fn main() { | ||
68 | // "Hello, \"World!\""; | ||
69 | // } | ||
70 | // ``` | ||
43 | pub(crate) fn make_usual_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 71 | pub(crate) fn make_usual_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
44 | let token = ctx.find_token_at_offset(RAW_STRING)?; | 72 | let token = ctx.find_token_at_offset(RAW_STRING)?; |
45 | let text = token.text().as_str(); | 73 | let text = token.text().as_str(); |
@@ -56,6 +84,21 @@ pub(crate) fn make_usual_string(mut ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
56 | ctx.build() | 84 | ctx.build() |
57 | } | 85 | } |
58 | 86 | ||
87 | // Assist: add_hash | ||
88 | // | ||
89 | // Adds a hash to a raw string literal. | ||
90 | // | ||
91 | // ``` | ||
92 | // fn main() { | ||
93 | // r#"Hello,<|> World!"#; | ||
94 | // } | ||
95 | // ``` | ||
96 | // -> | ||
97 | // ``` | ||
98 | // fn main() { | ||
99 | // r##"Hello, World!"##; | ||
100 | // } | ||
101 | // ``` | ||
59 | pub(crate) fn add_hash(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 102 | pub(crate) fn add_hash(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
60 | let token = ctx.find_token_at_offset(RAW_STRING)?; | 103 | let token = ctx.find_token_at_offset(RAW_STRING)?; |
61 | ctx.add_action(AssistId("add_hash"), "add hash to raw string", |edit| { | 104 | ctx.add_action(AssistId("add_hash"), "add hash to raw string", |edit| { |
@@ -66,6 +109,21 @@ pub(crate) fn add_hash(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
66 | ctx.build() | 109 | ctx.build() |
67 | } | 110 | } |
68 | 111 | ||
112 | // Assist: remove_hash | ||
113 | // | ||
114 | // Removes a hash from a raw string literal. | ||
115 | // | ||
116 | // ``` | ||
117 | // fn main() { | ||
118 | // r#"Hello,<|> World!"#; | ||
119 | // } | ||
120 | // ``` | ||
121 | // -> | ||
122 | // ``` | ||
123 | // fn main() { | ||
124 | // r"Hello, World!"; | ||
125 | // } | ||
126 | // ``` | ||
69 | pub(crate) fn remove_hash(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 127 | pub(crate) fn remove_hash(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
70 | let token = ctx.find_token_at_offset(RAW_STRING)?; | 128 | let token = ctx.find_token_at_offset(RAW_STRING)?; |
71 | let text = token.text().as_str(); | 129 | let text = token.text().as_str(); |