diff options
9 files changed, 175 insertions, 3 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a5f4e489f..c103503bd 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -31,9 +31,23 @@ pub struct SourceRootId(pub u32); | |||
31 | 31 | ||
32 | #[derive(Default, Clone, Debug, PartialEq, Eq)] | 32 | #[derive(Default, Clone, Debug, PartialEq, Eq)] |
33 | pub struct SourceRoot { | 33 | pub struct SourceRoot { |
34 | /// Sysroot or crates.io library. | ||
35 | /// | ||
36 | /// Libraries are considered mostly immutable, this assumption is used to | ||
37 | /// optimize salsa's query structure | ||
38 | pub is_library: bool, | ||
34 | pub files: FxHashMap<RelativePathBuf, FileId>, | 39 | pub files: FxHashMap<RelativePathBuf, FileId>, |
35 | } | 40 | } |
36 | 41 | ||
42 | impl SourceRoot { | ||
43 | pub fn new() -> SourceRoot { | ||
44 | Default::default() | ||
45 | } | ||
46 | pub fn new_library() -> SourceRoot { | ||
47 | SourceRoot { is_library: true, ..SourceRoot::new() } | ||
48 | } | ||
49 | } | ||
50 | |||
37 | /// `CrateGraph` is a bit of information which turns a set of text files into a | 51 | /// `CrateGraph` is a bit of information which turns a set of text files into a |
38 | /// number of Rust crates. Each crate is defined by the `FileId` of its root module, | 52 | /// number of Rust crates. Each crate is defined by the `FileId` of its root module, |
39 | /// the set of cfg flags (not yet implemented) and the set of dependencies. Note | 53 | /// the set of cfg flags (not yet implemented) and the set of dependencies. Note |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 895b1e966..8d9918d16 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -163,7 +163,8 @@ impl RootDatabase { | |||
163 | if !change.new_roots.is_empty() { | 163 | if !change.new_roots.is_empty() { |
164 | let mut local_roots = Vec::clone(&self.local_roots()); | 164 | let mut local_roots = Vec::clone(&self.local_roots()); |
165 | for (root_id, is_local) in change.new_roots { | 165 | for (root_id, is_local) in change.new_roots { |
166 | self.set_source_root(root_id, Default::default()); | 166 | let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() }; |
167 | self.set_source_root(root_id, Arc::new(root)); | ||
167 | if is_local { | 168 | if is_local { |
168 | local_roots.push(root_id); | 169 | local_roots.push(root_id); |
169 | } | 170 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index 278b1b797..e20a12e2a 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs | |||
@@ -51,6 +51,8 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
51 | ) | 51 | ) |
52 | .add_to(acc); | 52 | .add_to(acc); |
53 | postfix_snippet(ctx, "dbg", "dbg!(expr)", &format!("dbg!({})", receiver_text)).add_to(acc); | 53 | postfix_snippet(ctx, "dbg", "dbg!(expr)", &format!("dbg!({})", receiver_text)).add_to(acc); |
54 | postfix_snippet(ctx, "box", "Box::new(expr)", &format!("Box::new({})", receiver_text)) | ||
55 | .add_to(acc); | ||
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap index fcb292596..c1a40b7b4 100644 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap | |||
@@ -1,11 +1,18 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-05-23T22:23:35.118738523Z" | 2 | created: "2019-06-23T13:01:08.775536006Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | 5 | expression: kind_completions |
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | CompletionItem { | 8 | CompletionItem { |
9 | label: "box", | ||
10 | source_range: [76; 76), | ||
11 | delete: [72; 76), | ||
12 | insert: "Box::new(bar)", | ||
13 | detail: "Box::new(expr)", | ||
14 | }, | ||
15 | CompletionItem { | ||
9 | label: "dbg", | 16 | label: "dbg", |
10 | source_range: [76; 76), | 17 | source_range: [76; 76), |
11 | delete: [72; 76), | 18 | delete: [72; 76), |
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index e85147e9e..424d0476d 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -103,7 +103,21 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul | |||
103 | p.bump_remap(T![auto]); | 103 | p.bump_remap(T![auto]); |
104 | has_mods = true; | 104 | has_mods = true; |
105 | } | 105 | } |
106 | if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == T![impl] { | 106 | |
107 | if p.at(IDENT) | ||
108 | && p.at_contextual_kw("default") | ||
109 | && (match p.nth(1) { | ||
110 | T![impl] => true, | ||
111 | T![fn] | T![type] => { | ||
112 | if let ItemFlavor::Mod = flavor { | ||
113 | true | ||
114 | } else { | ||
115 | false | ||
116 | } | ||
117 | } | ||
118 | _ => false, | ||
119 | }) | ||
120 | { | ||
107 | p.bump_remap(T![default]); | 121 | p.bump_remap(T![default]); |
108 | has_mods = true; | 122 | has_mods = true; |
109 | } | 123 | } |
@@ -163,12 +177,25 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul | |||
163 | // test default_impl | 177 | // test default_impl |
164 | // default impl Foo {} | 178 | // default impl Foo {} |
165 | 179 | ||
180 | // test_err default_fn_type | ||
181 | // trait T { | ||
182 | // default type T = Bar; | ||
183 | // default fn foo() {} | ||
184 | // } | ||
185 | |||
186 | // test default_fn_type | ||
187 | // impl T for Foo { | ||
188 | // default type T = Bar; | ||
189 | // default fn foo() {} | ||
190 | // } | ||
191 | |||
166 | // test unsafe_default_impl | 192 | // test unsafe_default_impl |
167 | // unsafe default impl Foo {} | 193 | // unsafe default impl Foo {} |
168 | T![impl] => { | 194 | T![impl] => { |
169 | traits::impl_block(p); | 195 | traits::impl_block(p); |
170 | m.complete(p, IMPL_BLOCK); | 196 | m.complete(p, IMPL_BLOCK); |
171 | } | 197 | } |
198 | |||
172 | // test existential_type | 199 | // test existential_type |
173 | // existential type Foo: Fn() -> usize; | 200 | // existential type Foo: Fn() -> usize; |
174 | T![type] => { | 201 | T![type] => { |
diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.rs b/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.rs new file mode 100644 index 000000000..15ba8f4a8 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.rs | |||
@@ -0,0 +1,4 @@ | |||
1 | trait T { | ||
2 | default type T = Bar; | ||
3 | default fn foo() {} | ||
4 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.txt b/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.txt new file mode 100644 index 000000000..7da4e243f --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/err/0014_default_fn_type.txt | |||
@@ -0,0 +1,58 @@ | |||
1 | SOURCE_FILE@[0; 62) | ||
2 | TRAIT_DEF@[0; 61) | ||
3 | TRAIT_KW@[0; 5) "trait" | ||
4 | WHITESPACE@[5; 6) " " | ||
5 | NAME@[6; 7) | ||
6 | IDENT@[6; 7) "T" | ||
7 | WHITESPACE@[7; 8) " " | ||
8 | ITEM_LIST@[8; 61) | ||
9 | L_CURLY@[8; 9) "{" | ||
10 | WHITESPACE@[9; 14) "\n " | ||
11 | MACRO_CALL@[14; 21) | ||
12 | PATH@[14; 21) | ||
13 | PATH_SEGMENT@[14; 21) | ||
14 | NAME_REF@[14; 21) | ||
15 | IDENT@[14; 21) "default" | ||
16 | WHITESPACE@[21; 22) " " | ||
17 | TYPE_ALIAS_DEF@[22; 35) | ||
18 | TYPE_KW@[22; 26) "type" | ||
19 | WHITESPACE@[26; 27) " " | ||
20 | NAME@[27; 28) | ||
21 | IDENT@[27; 28) "T" | ||
22 | WHITESPACE@[28; 29) " " | ||
23 | EQ@[29; 30) "=" | ||
24 | WHITESPACE@[30; 31) " " | ||
25 | PATH_TYPE@[31; 34) | ||
26 | PATH@[31; 34) | ||
27 | PATH_SEGMENT@[31; 34) | ||
28 | NAME_REF@[31; 34) | ||
29 | IDENT@[31; 34) "Bar" | ||
30 | SEMI@[34; 35) ";" | ||
31 | WHITESPACE@[35; 40) "\n " | ||
32 | MACRO_CALL@[40; 47) | ||
33 | PATH@[40; 47) | ||
34 | PATH_SEGMENT@[40; 47) | ||
35 | NAME_REF@[40; 47) | ||
36 | IDENT@[40; 47) "default" | ||
37 | WHITESPACE@[47; 48) " " | ||
38 | FN_DEF@[48; 59) | ||
39 | FN_KW@[48; 50) "fn" | ||
40 | WHITESPACE@[50; 51) " " | ||
41 | NAME@[51; 54) | ||
42 | IDENT@[51; 54) "foo" | ||
43 | PARAM_LIST@[54; 56) | ||
44 | L_PAREN@[54; 55) "(" | ||
45 | R_PAREN@[55; 56) ")" | ||
46 | WHITESPACE@[56; 57) " " | ||
47 | BLOCK@[57; 59) | ||
48 | L_CURLY@[57; 58) "{" | ||
49 | R_CURLY@[58; 59) "}" | ||
50 | WHITESPACE@[59; 60) "\n" | ||
51 | R_CURLY@[60; 61) "}" | ||
52 | WHITESPACE@[61; 62) "\n" | ||
53 | error 21: expected EXCL | ||
54 | error 21: expected `{`, `[`, `(` | ||
55 | error 21: expected SEMI | ||
56 | error 47: expected EXCL | ||
57 | error 47: expected `{`, `[`, `(` | ||
58 | error 47: expected SEMI | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.rs new file mode 100644 index 000000000..8f5d61113 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.rs | |||
@@ -0,0 +1,4 @@ | |||
1 | impl T for Foo { | ||
2 | default type T = Bar; | ||
3 | default fn foo() {} | ||
4 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.txt new file mode 100644 index 000000000..384b203d3 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_default_fn_type.txt | |||
@@ -0,0 +1,55 @@ | |||
1 | SOURCE_FILE@[0; 69) | ||
2 | IMPL_BLOCK@[0; 68) | ||
3 | IMPL_KW@[0; 4) "impl" | ||
4 | WHITESPACE@[4; 5) " " | ||
5 | PATH_TYPE@[5; 6) | ||
6 | PATH@[5; 6) | ||
7 | PATH_SEGMENT@[5; 6) | ||
8 | NAME_REF@[5; 6) | ||
9 | IDENT@[5; 6) "T" | ||
10 | WHITESPACE@[6; 7) " " | ||
11 | FOR_KW@[7; 10) "for" | ||
12 | WHITESPACE@[10; 11) " " | ||
13 | PATH_TYPE@[11; 14) | ||
14 | PATH@[11; 14) | ||
15 | PATH_SEGMENT@[11; 14) | ||
16 | NAME_REF@[11; 14) | ||
17 | IDENT@[11; 14) "Foo" | ||
18 | WHITESPACE@[14; 15) " " | ||
19 | ITEM_LIST@[15; 68) | ||
20 | L_CURLY@[15; 16) "{" | ||
21 | WHITESPACE@[16; 21) "\n " | ||
22 | TYPE_ALIAS_DEF@[21; 42) | ||
23 | DEFAULT_KW@[21; 28) "default" | ||
24 | WHITESPACE@[28; 29) " " | ||
25 | TYPE_KW@[29; 33) "type" | ||
26 | WHITESPACE@[33; 34) " " | ||
27 | NAME@[34; 35) | ||
28 | IDENT@[34; 35) "T" | ||
29 | WHITESPACE@[35; 36) " " | ||
30 | EQ@[36; 37) "=" | ||
31 | WHITESPACE@[37; 38) " " | ||
32 | PATH_TYPE@[38; 41) | ||
33 | PATH@[38; 41) | ||
34 | PATH_SEGMENT@[38; 41) | ||
35 | NAME_REF@[38; 41) | ||
36 | IDENT@[38; 41) "Bar" | ||
37 | SEMI@[41; 42) ";" | ||
38 | WHITESPACE@[42; 47) "\n " | ||
39 | FN_DEF@[47; 66) | ||
40 | DEFAULT_KW@[47; 54) "default" | ||
41 | WHITESPACE@[54; 55) " " | ||
42 | FN_KW@[55; 57) "fn" | ||
43 | WHITESPACE@[57; 58) " " | ||
44 | NAME@[58; 61) | ||
45 | IDENT@[58; 61) "foo" | ||
46 | PARAM_LIST@[61; 63) | ||
47 | L_PAREN@[61; 62) "(" | ||
48 | R_PAREN@[62; 63) ")" | ||
49 | WHITESPACE@[63; 64) " " | ||
50 | BLOCK@[64; 66) | ||
51 | L_CURLY@[64; 65) "{" | ||
52 | R_CURLY@[65; 66) "}" | ||
53 | WHITESPACE@[66; 67) "\n" | ||
54 | R_CURLY@[67; 68) "}" | ||
55 | WHITESPACE@[68; 69) "\n" | ||