aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap40
-rw-r--r--crates/ra_syntax/src/grammar/expressions.rs2
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs36
-rw-r--r--crates/ra_syntax/src/ptr.rs8
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.txt89
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.rs15
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.txt123
-rw-r--r--crates/tools/src/lib.rs2
11 files changed, 302 insertions, 33 deletions
diff --git a/.travis.yml b/.travis.yml
index 7ccfe78fb..bddf1bebb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ before_cache:
6 6
7build: &rust_build 7build: &rust_build
8 language: rust 8 language: rust
9 rust: 1.32.0 9 rust: stable
10 script: 10 script:
11 - rustup component add rustfmt 11 - rustup component add rustfmt
12 - rustup component add rust-src 12 - rustup component add rust-src
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index d0fa8146c..6a9358d33 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -47,13 +47,14 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
47 } 47 }
48 } 48 }
49 Ty::Tuple(fields) => { 49 Ty::Tuple(fields) => {
50 for (i, _ty) in fields.iter().enumerate() { 50 for (i, ty) in fields.iter().enumerate() {
51 CompletionItem::new( 51 CompletionItem::new(
52 CompletionKind::Reference, 52 CompletionKind::Reference,
53 ctx.source_range(), 53 ctx.source_range(),
54 i.to_string(), 54 i.to_string(),
55 ) 55 )
56 .kind(CompletionItemKind::Field) 56 .kind(CompletionItemKind::Field)
57 .detail(ty.to_string())
57 .add_to(acc); 58 .add_to(acc);
58 } 59 }
59 } 60 }
@@ -175,4 +176,17 @@ mod tests {
175 ", 176 ",
176 ); 177 );
177 } 178 }
179
180 #[test]
181 fn test_tuple_field_completion() {
182 check_ref_completion(
183 "tuple_field_completion",
184 r"
185 fn foo() {
186 let b = (0, 3.14);
187 b.<|>
188 }
189 ",
190 );
191 }
178} 192}
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap
new file mode 100644
index 000000000..c9764eab3
--- /dev/null
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap
@@ -0,0 +1,40 @@
1---
2created: "2019-01-24T13:22:02.107228200+00:00"
3creator: [email protected]
4expression: kind_completions
5source: crates/ra_ide_api/src/completion/completion_item.rs
6---
7[
8 CompletionItem {
9 completion_kind: Reference,
10 label: "0",
11 kind: Some(
12 Field
13 ),
14 detail: Some(
15 "i32"
16 ),
17 documentation: None,
18 lookup: None,
19 insert_text: None,
20 insert_text_format: PlainText,
21 source_range: [75; 75),
22 text_edit: None
23 },
24 CompletionItem {
25 completion_kind: Reference,
26 label: "1",
27 kind: Some(
28 Field
29 ),
30 detail: Some(
31 "f64"
32 ),
33 documentation: None,
34 lookup: None,
35 insert_text: None,
36 insert_text_format: PlainText,
37 source_range: [75; 75),
38 text_edit: None
39 }
40]
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs
index 2236555e0..7ee32fa7c 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/grammar/expressions.rs
@@ -305,6 +305,8 @@ fn postfix_expr(
305// fn foo() { 305// fn foo() {
306// let _ = f(); 306// let _ = f();
307// let _ = f()(1)(1, 2,); 307// let _ = f()(1)(1, 2,);
308// let _ = f(<Foo>::func());
309// f(<Foo as Trait>::func());
308// } 310// }
309fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 311fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
310 assert!(p.at(L_PAREN)); 312 assert!(p.at(L_PAREN));
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index 167a76551..6d6d89f70 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -36,26 +36,22 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
36} 36}
37 37
38// E.g. for after the break in `if break {}`, this should not match 38// E.g. for after the break in `if break {}`, this should not match
39pub(super) const ATOM_EXPR_FIRST: TokenSet = LITERAL_FIRST.union(token_set![ 39pub(super) const ATOM_EXPR_FIRST: TokenSet =
40 L_PAREN, 40 LITERAL_FIRST.union(paths::PATH_FIRST).union(token_set![
41 L_CURLY, 41 L_PAREN,
42 L_BRACK, 42 L_CURLY,
43 PIPE, 43 L_BRACK,
44 MOVE_KW, 44 PIPE,
45 IF_KW, 45 MOVE_KW,
46 WHILE_KW, 46 IF_KW,
47 MATCH_KW, 47 WHILE_KW,
48 UNSAFE_KW, 48 MATCH_KW,
49 RETURN_KW, 49 UNSAFE_KW,
50 IDENT, 50 RETURN_KW,
51 SELF_KW, 51 BREAK_KW,
52 SUPER_KW, 52 CONTINUE_KW,
53 CRATE_KW, 53 LIFETIME,
54 COLONCOLON, 54 ]);
55 BREAK_KW,
56 CONTINUE_KW,
57 LIFETIME,
58]);
59 55
60const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; 56const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
61 57
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index b50cd8a52..13ee1305f 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -42,7 +42,7 @@ impl SyntaxNodePtr {
42/// Like `SyntaxNodePtr`, but remembers the type of node 42/// Like `SyntaxNodePtr`, but remembers the type of node
43#[derive(Debug, PartialEq, Eq, Hash)] 43#[derive(Debug, PartialEq, Eq, Hash)]
44pub struct AstPtr<N: AstNode> { 44pub struct AstPtr<N: AstNode> {
45 ptr: SyntaxNodePtr, 45 raw: SyntaxNodePtr,
46 _ty: PhantomData<N>, 46 _ty: PhantomData<N>,
47} 47}
48 48
@@ -56,18 +56,18 @@ impl<N: AstNode> Clone for AstPtr<N> {
56impl<N: AstNode> AstPtr<N> { 56impl<N: AstNode> AstPtr<N> {
57 pub fn new(node: &N) -> AstPtr<N> { 57 pub fn new(node: &N) -> AstPtr<N> {
58 AstPtr { 58 AstPtr {
59 ptr: SyntaxNodePtr::new(node.syntax()), 59 raw: SyntaxNodePtr::new(node.syntax()),
60 _ty: PhantomData, 60 _ty: PhantomData,
61 } 61 }
62 } 62 }
63 63
64 pub fn to_node(self, source_file: &SourceFile) -> &N { 64 pub fn to_node(self, source_file: &SourceFile) -> &N {
65 let syntax_node = self.ptr.to_node(source_file); 65 let syntax_node = self.raw.to_node(source_file);
66 N::cast(syntax_node).unwrap() 66 N::cast(syntax_node).unwrap()
67 } 67 }
68 68
69 pub fn syntax_node_ptr(self) -> SyntaxNodePtr { 69 pub fn syntax_node_ptr(self) -> SyntaxNodePtr {
70 self.ptr 70 self.raw
71 } 71 }
72} 72}
73 73
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.rs
index 0c9a20718..ffbf46d6d 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.rs
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.rs
@@ -1,4 +1,6 @@
1fn foo() { 1fn foo() {
2 let _ = f(); 2 let _ = f();
3 let _ = f()(1)(1, 2,); 3 let _ = f()(1)(1, 2,);
4 let _ = f(<Foo>::func());
5 f(<Foo as Trait>::func());
4} 6}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.txt
index 6364dc73c..0ddf393f2 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0042_call_expr.txt
@@ -1,5 +1,5 @@
1SOURCE_FILE@[0; 57) 1SOURCE_FILE@[0; 118)
2 FN_DEF@[0; 56) 2 FN_DEF@[0; 117)
3 FN_KW@[0; 2) 3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3) 4 WHITESPACE@[2; 3)
5 NAME@[3; 6) 5 NAME@[3; 6)
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 57)
8 L_PAREN@[6; 7) 8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8) 9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9) 10 WHITESPACE@[8; 9)
11 BLOCK@[9; 56) 11 BLOCK@[9; 117)
12 L_CURLY@[9; 10) 12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 15) 13 WHITESPACE@[10; 15)
14 LET_STMT@[15; 27) 14 LET_STMT@[15; 27)
@@ -65,6 +65,83 @@ SOURCE_FILE@[0; 57)
65 COMMA@[51; 52) 65 COMMA@[51; 52)
66 R_PAREN@[52; 53) 66 R_PAREN@[52; 53)
67 SEMI@[53; 54) 67 SEMI@[53; 54)
68 WHITESPACE@[54; 55) 68 WHITESPACE@[54; 59)
69 R_CURLY@[55; 56) 69 LET_STMT@[59; 84)
70 WHITESPACE@[56; 57) 70 LET_KW@[59; 62)
71 WHITESPACE@[62; 63)
72 PLACEHOLDER_PAT@[63; 64)
73 UNDERSCORE@[63; 64)
74 WHITESPACE@[64; 65)
75 EQ@[65; 66)
76 WHITESPACE@[66; 67)
77 CALL_EXPR@[67; 83)
78 PATH_EXPR@[67; 68)
79 PATH@[67; 68)
80 PATH_SEGMENT@[67; 68)
81 NAME_REF@[67; 68)
82 IDENT@[67; 68) "f"
83 ARG_LIST@[68; 83)
84 L_PAREN@[68; 69)
85 CALL_EXPR@[69; 82)
86 PATH_EXPR@[69; 80)
87 PATH@[69; 80)
88 PATH@[69; 74)
89 PATH_SEGMENT@[69; 74)
90 L_ANGLE@[69; 70)
91 PATH_TYPE@[70; 73)
92 PATH@[70; 73)
93 PATH_SEGMENT@[70; 73)
94 NAME_REF@[70; 73)
95 IDENT@[70; 73) "Foo"
96 R_ANGLE@[73; 74)
97 COLONCOLON@[74; 76)
98 PATH_SEGMENT@[76; 80)
99 NAME_REF@[76; 80)
100 IDENT@[76; 80) "func"
101 ARG_LIST@[80; 82)
102 L_PAREN@[80; 81)
103 R_PAREN@[81; 82)
104 R_PAREN@[82; 83)
105 SEMI@[83; 84)
106 WHITESPACE@[84; 89)
107 EXPR_STMT@[89; 115)
108 CALL_EXPR@[89; 114)
109 PATH_EXPR@[89; 90)
110 PATH@[89; 90)
111 PATH_SEGMENT@[89; 90)
112 NAME_REF@[89; 90)
113 IDENT@[89; 90) "f"
114 ARG_LIST@[90; 114)
115 L_PAREN@[90; 91)
116 CALL_EXPR@[91; 113)
117 PATH_EXPR@[91; 111)
118 PATH@[91; 111)
119 PATH@[91; 105)
120 PATH_SEGMENT@[91; 105)
121 L_ANGLE@[91; 92)
122 PATH_TYPE@[92; 95)
123 PATH@[92; 95)
124 PATH_SEGMENT@[92; 95)
125 NAME_REF@[92; 95)
126 IDENT@[92; 95) "Foo"
127 WHITESPACE@[95; 96)
128 AS_KW@[96; 98)
129 WHITESPACE@[98; 99)
130 PATH_TYPE@[99; 104)
131 PATH@[99; 104)
132 PATH_SEGMENT@[99; 104)
133 NAME_REF@[99; 104)
134 IDENT@[99; 104) "Trait"
135 R_ANGLE@[104; 105)
136 COLONCOLON@[105; 107)
137 PATH_SEGMENT@[107; 111)
138 NAME_REF@[107; 111)
139 IDENT@[107; 111) "func"
140 ARG_LIST@[111; 113)
141 L_PAREN@[111; 112)
142 R_PAREN@[112; 113)
143 R_PAREN@[113; 114)
144 SEMI@[114; 115)
145 WHITESPACE@[115; 116)
146 R_CURLY@[116; 117)
147 WHITESPACE@[117; 118)
diff --git a/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.rs b/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.rs
new file mode 100644
index 000000000..6c02e65ed
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.rs
@@ -0,0 +1,15 @@
1// https://github.com/rust-analyzer/rust-analyzer/issues/596
2
3struct Foo;
4
5impl Foo {
6 fn bar() -> bool {
7 unimplemented!()
8 }
9}
10
11fn baz(_: bool) {}
12
13fn main() {
14 baz(<Foo>::bar())
15}
diff --git a/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.txt b/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.txt
new file mode 100644
index 000000000..d1d890e50
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0042_ufcs_call_list.txt
@@ -0,0 +1,123 @@
1SOURCE_FILE@[0; 199)
2 COMMENT@[0; 60)
3 WHITESPACE@[60; 62)
4 STRUCT_DEF@[62; 73)
5 STRUCT_KW@[62; 68)
6 WHITESPACE@[68; 69)
7 NAME@[69; 72)
8 IDENT@[69; 72) "Foo"
9 SEMI@[72; 73)
10 WHITESPACE@[73; 75)
11 IMPL_BLOCK@[75; 141)
12 IMPL_KW@[75; 79)
13 WHITESPACE@[79; 80)
14 PATH_TYPE@[80; 83)
15 PATH@[80; 83)
16 PATH_SEGMENT@[80; 83)
17 NAME_REF@[80; 83)
18 IDENT@[80; 83) "Foo"
19 WHITESPACE@[83; 84)
20 ITEM_LIST@[84; 141)
21 L_CURLY@[84; 85)
22 WHITESPACE@[85; 90)
23 FN_DEF@[90; 139)
24 FN_KW@[90; 92)
25 WHITESPACE@[92; 93)
26 NAME@[93; 96)
27 IDENT@[93; 96) "bar"
28 PARAM_LIST@[96; 98)
29 L_PAREN@[96; 97)
30 R_PAREN@[97; 98)
31 WHITESPACE@[98; 99)
32 RET_TYPE@[99; 106)
33 THIN_ARROW@[99; 101)
34 WHITESPACE@[101; 102)
35 PATH_TYPE@[102; 106)
36 PATH@[102; 106)
37 PATH_SEGMENT@[102; 106)
38 NAME_REF@[102; 106)
39 IDENT@[102; 106) "bool"
40 WHITESPACE@[106; 107)
41 BLOCK@[107; 139)
42 L_CURLY@[107; 108)
43 WHITESPACE@[108; 117)
44 MACRO_CALL@[117; 133)
45 PATH@[117; 130)
46 PATH_SEGMENT@[117; 130)
47 NAME_REF@[117; 130)
48 IDENT@[117; 130) "unimplemented"
49 EXCL@[130; 131)
50 TOKEN_TREE@[131; 133)
51 L_PAREN@[131; 132)
52 R_PAREN@[132; 133)
53 WHITESPACE@[133; 138)
54 R_CURLY@[138; 139)
55 WHITESPACE@[139; 140)
56 R_CURLY@[140; 141)
57 WHITESPACE@[141; 143)
58 FN_DEF@[143; 161)
59 FN_KW@[143; 145)
60 WHITESPACE@[145; 146)
61 NAME@[146; 149)
62 IDENT@[146; 149) "baz"
63 PARAM_LIST@[149; 158)
64 L_PAREN@[149; 150)
65 PARAM@[150; 157)
66 PLACEHOLDER_PAT@[150; 151)
67 UNDERSCORE@[150; 151)
68 COLON@[151; 152)
69 WHITESPACE@[152; 153)
70 PATH_TYPE@[153; 157)
71 PATH@[153; 157)
72 PATH_SEGMENT@[153; 157)
73 NAME_REF@[153; 157)
74 IDENT@[153; 157) "bool"
75 R_PAREN@[157; 158)
76 WHITESPACE@[158; 159)
77 BLOCK@[159; 161)
78 L_CURLY@[159; 160)
79 R_CURLY@[160; 161)
80 WHITESPACE@[161; 163)
81 FN_DEF@[163; 198)
82 FN_KW@[163; 165)
83 WHITESPACE@[165; 166)
84 NAME@[166; 170)
85 IDENT@[166; 170) "main"
86 PARAM_LIST@[170; 172)
87 L_PAREN@[170; 171)
88 R_PAREN@[171; 172)
89 WHITESPACE@[172; 173)
90 BLOCK@[173; 198)
91 L_CURLY@[173; 174)
92 WHITESPACE@[174; 179)
93 CALL_EXPR@[179; 196)
94 PATH_EXPR@[179; 182)
95 PATH@[179; 182)
96 PATH_SEGMENT@[179; 182)
97 NAME_REF@[179; 182)
98 IDENT@[179; 182) "baz"
99 ARG_LIST@[182; 196)
100 L_PAREN@[182; 183)
101 CALL_EXPR@[183; 195)
102 PATH_EXPR@[183; 193)
103 PATH@[183; 193)
104 PATH@[183; 188)
105 PATH_SEGMENT@[183; 188)
106 L_ANGLE@[183; 184)
107 PATH_TYPE@[184; 187)
108 PATH@[184; 187)
109 PATH_SEGMENT@[184; 187)
110 NAME_REF@[184; 187)
111 IDENT@[184; 187) "Foo"
112 R_ANGLE@[187; 188)
113 COLONCOLON@[188; 190)
114 PATH_SEGMENT@[190; 193)
115 NAME_REF@[190; 193)
116 IDENT@[190; 193) "bar"
117 ARG_LIST@[193; 195)
118 L_PAREN@[193; 194)
119 R_PAREN@[194; 195)
120 R_PAREN@[195; 196)
121 WHITESPACE@[196; 197)
122 R_CURLY@[197; 198)
123 WHITESPACE@[198; 199)
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 39f181432..d404db214 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -15,7 +15,7 @@ pub type Result<T> = std::result::Result<T, failure::Error>;
15pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; 15pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
16pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera"; 16pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera";
17pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; 17pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera";
18const TOOLCHAIN: &str = "1.32.0"; 18const TOOLCHAIN: &str = "stable";
19 19
20#[derive(Debug)] 20#[derive(Debug)]
21pub struct Test { 21pub struct Test {