aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/gen_lsp_server/Cargo.toml1
-rw-r--r--crates/gen_lsp_server/src/msg.rs2
-rw-r--r--crates/ra_analysis/src/lib.rs24
-rw-r--r--crates/ra_db/src/input.rs3
-rw-r--r--crates/ra_editor/src/typing.rs58
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/main.rs4
-rw-r--r--crates/ra_lsp_server/src/req.rs2
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs7
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.rs1
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.txt44
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.rs8
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.txt88
13 files changed, 221 insertions, 22 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml
index 6c91e38aa..5f90d39d6 100644
--- a/crates/gen_lsp_server/Cargo.toml
+++ b/crates/gen_lsp_server/Cargo.toml
@@ -13,5 +13,4 @@ log = "0.4.3"
13failure = "0.1.2" 13failure = "0.1.2"
14serde_json = "1.0.24" 14serde_json = "1.0.24"
15serde = "1.0.71" 15serde = "1.0.71"
16serde_derive = "1.0.71"
17crossbeam-channel = "0.2.4" 16crossbeam-channel = "0.2.4"
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index 22d273d55..ef6358cb1 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -1,7 +1,7 @@
1use std::io::{BufRead, Write}; 1use std::io::{BufRead, Write};
2 2
3use languageserver_types::{notification::Notification, request::Request}; 3use languageserver_types::{notification::Notification, request::Request};
4use serde_derive::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5use serde_json::{from_str, from_value, to_string, to_value, Value}; 5use serde_json::{from_str, from_value, to_string, to_value, Value};
6use failure::{bail, format_err}; 6use failure::{bail, format_err};
7 7
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 1c8aa308b..b2f4cd228 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -72,13 +72,23 @@ struct RemoveFile {
72 72
73impl fmt::Debug for AnalysisChange { 73impl fmt::Debug for AnalysisChange {
74 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 74 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
75 fmt.debug_struct("AnalysisChange") 75 let mut d = fmt.debug_struct("AnalysisChange");
76 .field("new_roots", &self.new_roots) 76 if !self.new_roots.is_empty() {
77 .field("roots_changed", &self.roots_changed) 77 d.field("new_roots", &self.new_roots);
78 .field("files_changed", &self.files_changed.len()) 78 }
79 .field("libraries_added", &self.libraries_added.len()) 79 if !self.roots_changed.is_empty() {
80 .field("crate_graph", &self.crate_graph) 80 d.field("roots_changed", &self.roots_changed);
81 .finish() 81 }
82 if !self.files_changed.is_empty() {
83 d.field("files_changed", &self.files_changed.len());
84 }
85 if !self.libraries_added.is_empty() {
86 d.field("libraries_added", &self.libraries_added.len());
87 }
88 if !self.crate_graph.is_some() {
89 d.field("crate_graph", &self.crate_graph);
90 }
91 d.finish()
82 } 92 }
83} 93}
84 94
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index f12dd9345..ead8dfe48 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -98,6 +98,9 @@ impl CrateGraph {
98 pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) { 98 pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) {
99 self.arena.get_mut(&from).unwrap().add_dep(name, to) 99 self.arena.get_mut(&from).unwrap().add_dep(name, to)
100 } 100 }
101 pub fn is_empty(&self) -> bool {
102 self.arena.is_empty()
103 }
101 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 104 pub fn crate_root(&self, crate_id: CrateId) -> FileId {
102 self.arena[&crate_id].file_id 105 self.arena[&crate_id].file_id
103 } 106 }
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 46a6e2d62..5e412bcfa 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -164,6 +164,16 @@ fn remove_newline(
164 if join_single_expr_block(edit, node).is_some() { 164 if join_single_expr_block(edit, node).is_some() {
165 return; 165 return;
166 } 166 }
167 // ditto for
168 //
169 // ```
170 // use foo::{<|>
171 // bar
172 // };
173 // ```
174 if join_single_use_tree(edit, node).is_some() {
175 return;
176 }
167 177
168 // The node is between two other nodes 178 // The node is between two other nodes
169 let prev = node.prev_sibling().unwrap(); 179 let prev = node.prev_sibling().unwrap();
@@ -228,6 +238,36 @@ fn single_expr(block: ast::Block) -> Option<ast::Expr> {
228 res 238 res
229} 239}
230 240
241fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> {
242 let use_tree_list = ast::UseTreeList::cast(node.parent()?)?;
243 let tree = single_use_tree(use_tree_list)?;
244 edit.replace(
245 use_tree_list.syntax().range(),
246 tree.syntax().text().to_string(),
247 );
248 Some(())
249}
250
251fn single_use_tree(tree_list: ast::UseTreeList) -> Option<ast::UseTree> {
252 let mut res = None;
253 for child in tree_list.syntax().children() {
254 if let Some(tree) = ast::UseTree::cast(child) {
255 if tree.syntax().text().contains('\n') {
256 return None;
257 }
258 if mem::replace(&mut res, Some(tree)).is_some() {
259 return None;
260 }
261 } else {
262 match child.kind() {
263 WHITESPACE | L_CURLY | R_CURLY | COMMA => (),
264 _ => return None,
265 }
266 }
267 }
268 res
269}
270
231fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { 271fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str {
232 match left.kind() { 272 match left.kind() {
233 L_PAREN | L_BRACK => return "", 273 L_PAREN | L_BRACK => return "",
@@ -306,6 +346,24 @@ fn foo() {
306 } 346 }
307 347
308 #[test] 348 #[test]
349 fn test_join_lines_use_tree() {
350 check_join_lines(
351 r"
352use ra_syntax::{
353 algo::<|>{
354 find_leaf_at_offset,
355 },
356 ast,
357};",
358 r"
359use ra_syntax::{
360 algo::<|>find_leaf_at_offset,
361 ast,
362};",
363 );
364 }
365
366 #[test]
309 fn test_join_lines_normal_comments() { 367 fn test_join_lines_normal_comments() {
310 check_join_lines( 368 check_join_lines(
311 r" 369 r"
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index fc10096e5..3c8c240cd 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -12,7 +12,6 @@ failure = "0.1.2"
12failure_derive = "0.1.2" 12failure_derive = "0.1.2"
13serde_json = "1.0.24" 13serde_json = "1.0.24"
14serde = "1.0.71" 14serde = "1.0.71"
15serde_derive = "1.0.71"
16drop_bomb = "0.1.0" 15drop_bomb = "0.1.0"
17crossbeam-channel = "0.2.4" 16crossbeam-channel = "0.2.4"
18flexi_logger = "0.10.0" 17flexi_logger = "0.10.0"
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index 4497980e5..eae601f91 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -1,7 +1,7 @@
1use serde_derive::Deserialize; 1use serde::Deserialize;
2use serde::Deserialize as _D;
3use flexi_logger::{Duplicate, Logger}; 2use flexi_logger::{Duplicate, Logger};
4use gen_lsp_server::{run_server, stdio_transport}; 3use gen_lsp_server::{run_server, stdio_transport};
4
5use ra_lsp_server::Result; 5use ra_lsp_server::Result;
6 6
7fn main() -> Result<()> { 7fn main() -> Result<()> {
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index 999792ecb..747ab8a8c 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -1,4 +1,4 @@
1use serde_derive::{Serialize, Deserialize}; 1use serde::{Serialize, Deserialize};
2use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url}; 2use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
3use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
4use url_serde; 4use url_serde;
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs
index 863f8e00c..7db25beba 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/grammar/type_params.rs
@@ -96,6 +96,7 @@ pub(super) fn bounds_without_colon(p: &mut Parser) {
96// 'a: 'b + 'c, 96// 'a: 'b + 'c,
97// T: Clone + Copy + 'static, 97// T: Clone + Copy + 'static,
98// Iterator::Item: 'a, 98// Iterator::Item: 'a,
99// <T as Iterator>::Item: 'a
99// {} 100// {}
100pub(super) fn opt_where_clause(p: &mut Parser) { 101pub(super) fn opt_where_clause(p: &mut Parser) {
101 if !p.at(WHERE_KW) { 102 if !p.at(WHERE_KW) {
@@ -104,7 +105,11 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
104 let m = p.start(); 105 let m = p.start();
105 p.bump(); 106 p.bump();
106 loop { 107 loop {
107 if !(paths::is_path_start(p) || p.current() == LIFETIME || p.current() == FOR_KW) { 108 if !(paths::is_path_start(p)
109 || p.current() == LIFETIME
110 || p.current() == FOR_KW
111 || p.current() == L_ANGLE)
112 {
108 break; 113 break;
109 } 114 }
110 where_predicate(p); 115 where_predicate(p);
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.rs
index 592a005f9..19d7e571b 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.rs
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.rs
@@ -3,4 +3,5 @@ where
3 'a: 'b + 'c, 3 'a: 'b + 'c,
4 T: Clone + Copy + 'static, 4 T: Clone + Copy + 'static,
5 Iterator::Item: 'a, 5 Iterator::Item: 'a,
6 <T as Iterator>::Item: 'a
6{} 7{}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.txt
index 54c3d64f1..68485dc0b 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0056_where_clause.txt
@@ -1,5 +1,5 @@
1SOURCE_FILE@[0; 87) 1SOURCE_FILE@[0; 116)
2 FN_DEF@[0; 86) 2 FN_DEF@[0; 115)
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; 87)
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 WHERE_CLAUSE@[9; 83) 11 WHERE_CLAUSE@[9; 112)
12 WHERE_KW@[9; 14) 12 WHERE_KW@[9; 14)
13 WHITESPACE@[14; 18) 13 WHITESPACE@[14; 18)
14 WHERE_PRED@[18; 29) 14 WHERE_PRED@[18; 29)
@@ -64,8 +64,36 @@ SOURCE_FILE@[0; 87)
64 WHITESPACE@[79; 80) 64 WHITESPACE@[79; 80)
65 LIFETIME@[80; 82) "'a" 65 LIFETIME@[80; 82) "'a"
66 COMMA@[82; 83) 66 COMMA@[82; 83)
67 WHITESPACE@[83; 84) 67 WHITESPACE@[83; 87)
68 BLOCK@[84; 86) 68 WHERE_PRED@[87; 112)
69 L_CURLY@[84; 85) 69 PATH_TYPE@[87; 108)
70 R_CURLY@[85; 86) 70 PATH@[87; 108)
71 WHITESPACE@[86; 87) 71 PATH@[87; 102)
72 PATH_SEGMENT@[87; 102)
73 L_ANGLE@[87; 88)
74 PATH_TYPE@[88; 89)
75 PATH@[88; 89)
76 PATH_SEGMENT@[88; 89)
77 NAME_REF@[88; 89)
78 IDENT@[88; 89) "T"
79 WHITESPACE@[89; 90)
80 AS_KW@[90; 92)
81 WHITESPACE@[92; 93)
82 PATH_TYPE@[93; 101)
83 PATH@[93; 101)
84 PATH_SEGMENT@[93; 101)
85 NAME_REF@[93; 101)
86 IDENT@[93; 101) "Iterator"
87 R_ANGLE@[101; 102)
88 COLONCOLON@[102; 104)
89 PATH_SEGMENT@[104; 108)
90 NAME_REF@[104; 108)
91 IDENT@[104; 108) "Item"
92 COLON@[108; 109)
93 WHITESPACE@[109; 110)
94 LIFETIME@[110; 112) "'a"
95 WHITESPACE@[112; 113)
96 BLOCK@[113; 115)
97 L_CURLY@[113; 114)
98 R_CURLY@[114; 115)
99 WHITESPACE@[115; 116)
diff --git a/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.rs b/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.rs
new file mode 100644
index 000000000..6da27933e
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.rs
@@ -0,0 +1,8 @@
1// https://github.com/rust-analyzer/rust-analyzer/issues/311
2
3pub fn foo<S: Iterator>() -> String
4where
5 <S as Iterator>::Item: Eq,
6{
7 "".to_owned()
8}
diff --git a/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.txt b/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.txt
new file mode 100644
index 000000000..208e5e51c
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0036_fully_qualified.txt
@@ -0,0 +1,88 @@
1SOURCE_FILE@[0; 157)
2 COMMENT@[0; 60)
3 WHITESPACE@[60; 62)
4 FN_DEF@[62; 156)
5 VISIBILITY@[62; 65)
6 PUB_KW@[62; 65)
7 WHITESPACE@[65; 66)
8 FN_KW@[66; 68)
9 WHITESPACE@[68; 69)
10 NAME@[69; 72)
11 IDENT@[69; 72) "foo"
12 TYPE_PARAM_LIST@[72; 85)
13 L_ANGLE@[72; 73)
14 TYPE_PARAM@[73; 84)
15 NAME@[73; 74)
16 IDENT@[73; 74) "S"
17 COLON@[74; 75)
18 WHITESPACE@[75; 76)
19 PATH_TYPE@[76; 84)
20 PATH@[76; 84)
21 PATH_SEGMENT@[76; 84)
22 NAME_REF@[76; 84)
23 IDENT@[76; 84) "Iterator"
24 R_ANGLE@[84; 85)
25 PARAM_LIST@[85; 87)
26 L_PAREN@[85; 86)
27 R_PAREN@[86; 87)
28 WHITESPACE@[87; 88)
29 RET_TYPE@[88; 97)
30 THIN_ARROW@[88; 90)
31 WHITESPACE@[90; 91)
32 PATH_TYPE@[91; 97)
33 PATH@[91; 97)
34 PATH_SEGMENT@[91; 97)
35 NAME_REF@[91; 97)
36 IDENT@[91; 97) "String"
37 WHITESPACE@[97; 98)
38 WHERE_CLAUSE@[98; 134)
39 WHERE_KW@[98; 103)
40 WHITESPACE@[103; 108)
41 WHERE_PRED@[108; 133)
42 PATH_TYPE@[108; 129)
43 PATH@[108; 129)
44 PATH@[108; 123)
45 PATH_SEGMENT@[108; 123)
46 L_ANGLE@[108; 109)
47 PATH_TYPE@[109; 110)
48 PATH@[109; 110)
49 PATH_SEGMENT@[109; 110)
50 NAME_REF@[109; 110)
51 IDENT@[109; 110) "S"
52 WHITESPACE@[110; 111)
53 AS_KW@[111; 113)
54 WHITESPACE@[113; 114)
55 PATH_TYPE@[114; 122)
56 PATH@[114; 122)
57 PATH_SEGMENT@[114; 122)
58 NAME_REF@[114; 122)
59 IDENT@[114; 122) "Iterator"
60 R_ANGLE@[122; 123)
61 COLONCOLON@[123; 125)
62 PATH_SEGMENT@[125; 129)
63 NAME_REF@[125; 129)
64 IDENT@[125; 129) "Item"
65 COLON@[129; 130)
66 WHITESPACE@[130; 131)
67 PATH_TYPE@[131; 133)
68 PATH@[131; 133)
69 PATH_SEGMENT@[131; 133)
70 NAME_REF@[131; 133)
71 IDENT@[131; 133) "Eq"
72 COMMA@[133; 134)
73 WHITESPACE@[134; 135)
74 BLOCK@[135; 156)
75 L_CURLY@[135; 136)
76 WHITESPACE@[136; 141)
77 METHOD_CALL_EXPR@[141; 154)
78 LITERAL@[141; 143)
79 STRING@[141; 143)
80 DOT@[143; 144)
81 NAME_REF@[144; 152)
82 IDENT@[144; 152) "to_owned"
83 ARG_LIST@[152; 154)
84 L_PAREN@[152; 153)
85 R_PAREN@[153; 154)
86 WHITESPACE@[154; 155)
87 R_CURLY@[155; 156)
88 WHITESPACE@[156; 157)