aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/gen_lsp_server/src/msg.rs18
-rw-r--r--crates/ra_cli/Cargo.toml2
-rw-r--r--crates/ra_hir/Cargo.toml4
-rw-r--r--crates/ra_hir/src/ty/infer.rs73
-rw-r--r--crates/ra_ide_api/Cargo.toml2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs29
-rw-r--r--crates/ra_ide_api/src/hover.rs22
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs16
-rw-r--r--crates/ra_ide_api/src/symbol_index.rs9
-rw-r--r--crates/ra_ide_api_light/Cargo.toml2
-rw-r--r--crates/ra_lsp_server/Cargo.toml2
-rw-r--r--crates/ra_lsp_server/src/init.rs39
-rw-r--r--crates/ra_lsp_server/src/lib.rs3
-rw-r--r--crates/ra_lsp_server/src/main.rs20
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs57
-rw-r--r--crates/ra_lsp_server/src/req.rs10
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs10
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs21
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs14
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs16
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.rs6
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.txt159
22 files changed, 440 insertions, 94 deletions
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index 02c7a1858..1d39ba4bc 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -15,6 +15,24 @@ pub enum RawMessage {
15 Response(RawResponse), 15 Response(RawResponse),
16} 16}
17 17
18impl From<RawRequest> for RawMessage {
19 fn from(raw: RawRequest) -> RawMessage {
20 RawMessage::Request(raw)
21 }
22}
23
24impl From<RawNotification> for RawMessage {
25 fn from(raw: RawNotification) -> RawMessage {
26 RawMessage::Notification(raw)
27 }
28}
29
30impl From<RawResponse> for RawMessage {
31 fn from(raw: RawResponse) -> RawMessage {
32 RawMessage::Response(raw)
33 }
34}
35
18#[derive(Debug, Serialize, Deserialize, Clone)] 36#[derive(Debug, Serialize, Deserialize, Clone)]
19pub struct RawRequest { 37pub struct RawRequest {
20 pub id: u64, 38 pub id: u64,
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index 042e42067..ff30bf0b3 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -9,7 +9,7 @@ publish = false
9clap = "2.32.0" 9clap = "2.32.0"
10failure = "0.1.4" 10failure = "0.1.4"
11join_to_string = "0.1.1" 11join_to_string = "0.1.1"
12flexi_logger = "0.10.0" 12flexi_logger = "0.11.0"
13indicatif = "0.11.0" 13indicatif = "0.11.0"
14 14
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index f2242fe1f..501308acc 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -21,5 +21,5 @@ tt = { path = "../ra_tt", package = "ra_tt" }
21test_utils = { path = "../test_utils" } 21test_utils = { path = "../test_utils" }
22 22
23[dev-dependencies] 23[dev-dependencies]
24flexi_logger = "0.10.0" 24flexi_logger = "0.11.0"
25insta = "0.6.1" 25insta = "0.7.0"
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 5e4d49ffb..268d2c110 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -29,6 +29,7 @@ use crate::{
29 Function, StructField, Path, Name, 29 Function, StructField, Path, Name,
30 FnSignature, AdtDef, 30 FnSignature, AdtDef,
31 HirDatabase, 31 HirDatabase,
32 ImplItem,
32 type_ref::{TypeRef, Mutability}, 33 type_ref::{TypeRef, Mutability},
33 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat, self}, 34 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat, self},
34 generics::GenericParams, 35 generics::GenericParams,
@@ -54,6 +55,14 @@ pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> {
54 Arc::new(ctx.resolve_all()) 55 Arc::new(ctx.resolve_all())
55} 56}
56 57
58#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
59enum ExprOrPatId {
60 ExprId(ExprId),
61 PatId(PatId),
62}
63
64impl_froms!(ExprOrPatId: ExprId, PatId);
65
57/// The result of type inference: A mapping from expressions and patterns to types. 66/// The result of type inference: A mapping from expressions and patterns to types.
58#[derive(Clone, PartialEq, Eq, Debug)] 67#[derive(Clone, PartialEq, Eq, Debug)]
59pub struct InferenceResult { 68pub struct InferenceResult {
@@ -61,6 +70,8 @@ pub struct InferenceResult {
61 method_resolutions: FxHashMap<ExprId, Function>, 70 method_resolutions: FxHashMap<ExprId, Function>,
62 /// For each field access expr, records the field it resolves to. 71 /// For each field access expr, records the field it resolves to.
63 field_resolutions: FxHashMap<ExprId, StructField>, 72 field_resolutions: FxHashMap<ExprId, StructField>,
73 /// For each associated item record what it resolves to
74 assoc_resolutions: FxHashMap<ExprOrPatId, ImplItem>,
64 pub(super) type_of_expr: ArenaMap<ExprId, Ty>, 75 pub(super) type_of_expr: ArenaMap<ExprId, Ty>,
65 pub(super) type_of_pat: ArenaMap<PatId, Ty>, 76 pub(super) type_of_pat: ArenaMap<PatId, Ty>,
66} 77}
@@ -72,6 +83,12 @@ impl InferenceResult {
72 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> { 83 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> {
73 self.field_resolutions.get(&expr).map(|it| *it) 84 self.field_resolutions.get(&expr).map(|it| *it)
74 } 85 }
86 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> {
87 self.assoc_resolutions.get(&id.into()).map(|it| *it)
88 }
89 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<ImplItem> {
90 self.assoc_resolutions.get(&id.into()).map(|it| *it)
91 }
75} 92}
76 93
77impl Index<ExprId> for InferenceResult { 94impl Index<ExprId> for InferenceResult {
@@ -99,6 +116,7 @@ struct InferenceContext<'a, D: HirDatabase> {
99 var_unification_table: InPlaceUnificationTable<TypeVarId>, 116 var_unification_table: InPlaceUnificationTable<TypeVarId>,
100 method_resolutions: FxHashMap<ExprId, Function>, 117 method_resolutions: FxHashMap<ExprId, Function>,
101 field_resolutions: FxHashMap<ExprId, StructField>, 118 field_resolutions: FxHashMap<ExprId, StructField>,
119 assoc_resolutions: FxHashMap<ExprOrPatId, ImplItem>,
102 type_of_expr: ArenaMap<ExprId, Ty>, 120 type_of_expr: ArenaMap<ExprId, Ty>,
103 type_of_pat: ArenaMap<PatId, Ty>, 121 type_of_pat: ArenaMap<PatId, Ty>,
104 /// The return type of the function being inferred. 122 /// The return type of the function being inferred.
@@ -110,6 +128,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
110 InferenceContext { 128 InferenceContext {
111 method_resolutions: FxHashMap::default(), 129 method_resolutions: FxHashMap::default(),
112 field_resolutions: FxHashMap::default(), 130 field_resolutions: FxHashMap::default(),
131 assoc_resolutions: FxHashMap::default(),
113 type_of_expr: ArenaMap::default(), 132 type_of_expr: ArenaMap::default(),
114 type_of_pat: ArenaMap::default(), 133 type_of_pat: ArenaMap::default(),
115 var_unification_table: InPlaceUnificationTable::new(), 134 var_unification_table: InPlaceUnificationTable::new(),
@@ -135,6 +154,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
135 InferenceResult { 154 InferenceResult {
136 method_resolutions: self.method_resolutions, 155 method_resolutions: self.method_resolutions,
137 field_resolutions: self.field_resolutions, 156 field_resolutions: self.field_resolutions,
157 assoc_resolutions: self.assoc_resolutions,
138 type_of_expr: expr_types, 158 type_of_expr: expr_types,
139 type_of_pat: pat_types, 159 type_of_pat: pat_types,
140 } 160 }
@@ -152,6 +172,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
152 self.field_resolutions.insert(expr, field); 172 self.field_resolutions.insert(expr, field);
153 } 173 }
154 174
175 fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: ImplItem) {
176 self.assoc_resolutions.insert(id, item);
177 }
178
155 fn write_pat_ty(&mut self, pat: PatId, ty: Ty) { 179 fn write_pat_ty(&mut self, pat: PatId, ty: Ty) {
156 self.type_of_pat.insert(pat, ty); 180 self.type_of_pat.insert(pat, ty);
157 } 181 }
@@ -341,7 +365,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
341 }) 365 })
342 } 366 }
343 367
344 fn infer_path_expr(&mut self, resolver: &Resolver, path: &Path) -> Option<Ty> { 368 fn infer_path_expr(&mut self, resolver: &Resolver, path: &Path, id: ExprOrPatId) -> Option<Ty> {
345 let resolved = resolver.resolve_path_segments(self.db, &path); 369 let resolved = resolver.resolve_path_segments(self.db, &path);
346 370
347 let (def, remaining_index) = resolved.into_inner(); 371 let (def, remaining_index) = resolved.into_inner();
@@ -393,26 +417,38 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
393 // Attempt to find an impl_item for the type which has a name matching 417 // Attempt to find an impl_item for the type which has a name matching
394 // the current segment 418 // the current segment
395 log::debug!("looking for path segment: {:?}", segment); 419 log::debug!("looking for path segment: {:?}", segment);
396 let item: crate::ModuleDef = ty.iterate_impl_items(self.db, |item| match item { 420 let item: crate::ModuleDef = ty.iterate_impl_items(self.db, |item| {
397 crate::ImplItem::Method(func) => { 421 let matching_def: Option<crate::ModuleDef> = match item {
398 let sig = func.signature(self.db); 422 crate::ImplItem::Method(func) => {
399 if segment.name == *sig.name() { 423 let sig = func.signature(self.db);
400 return Some(func.into()); 424 if segment.name == *sig.name() {
425 Some(func.into())
426 } else {
427 None
428 }
401 } 429 }
402 None
403 }
404 430
405 crate::ImplItem::Const(konst) => { 431 crate::ImplItem::Const(konst) => {
406 let sig = konst.signature(self.db); 432 let sig = konst.signature(self.db);
407 if segment.name == *sig.name() { 433 if segment.name == *sig.name() {
408 return Some(konst.into()); 434 Some(konst.into())
435 } else {
436 None
437 }
409 } 438 }
410 None
411 }
412 439
413 // TODO: Resolve associated types 440 // TODO: Resolve associated types
414 crate::ImplItem::TypeAlias(_) => None, 441 crate::ImplItem::TypeAlias(_) => None,
442 };
443 match matching_def {
444 Some(_) => {
445 self.write_assoc_resolution(id, item);
446 return matching_def;
447 }
448 None => None,
449 }
415 })?; 450 })?;
451
416 resolved = Resolution::Def(item.into()); 452 resolved = Resolution::Def(item.into());
417 } 453 }
418 454
@@ -420,7 +456,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
420 Resolution::Def(def) => { 456 Resolution::Def(def) => {
421 let typable: Option<TypableDef> = def.into(); 457 let typable: Option<TypableDef> = def.into();
422 let typable = typable?; 458 let typable = typable?;
423
424 let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); 459 let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable);
425 let ty = self.db.type_for_def(typable, Namespace::Values).apply_substs(substs); 460 let ty = self.db.type_for_def(typable, Namespace::Values).apply_substs(substs);
426 let ty = self.insert_type_vars(ty); 461 let ty = self.insert_type_vars(ty);
@@ -572,7 +607,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
572 Pat::Path(path) => { 607 Pat::Path(path) => {
573 // TODO use correct resolver for the surrounding expression 608 // TODO use correct resolver for the surrounding expression
574 let resolver = self.resolver.clone(); 609 let resolver = self.resolver.clone();
575 self.infer_path_expr(&resolver, &path).unwrap_or(Ty::Unknown) 610 self.infer_path_expr(&resolver, &path, pat.into()).unwrap_or(Ty::Unknown)
576 } 611 }
577 Pat::Bind { mode, name: _name, subpat } => { 612 Pat::Bind { mode, name: _name, subpat } => {
578 let inner_ty = if let Some(subpat) = subpat { 613 let inner_ty = if let Some(subpat) = subpat {
@@ -782,7 +817,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
782 Expr::Path(p) => { 817 Expr::Path(p) => {
783 // TODO this could be more efficient... 818 // TODO this could be more efficient...
784 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); 819 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr);
785 self.infer_path_expr(&resolver, p).unwrap_or(Ty::Unknown) 820 self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
786 } 821 }
787 Expr::Continue => Ty::Never, 822 Expr::Continue => Ty::Never,
788 Expr::Break { expr } => { 823 Expr::Break { expr } => {
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index 1d907bda2..40b7a8d0a 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -27,7 +27,7 @@ test_utils = { path = "../test_utils" }
27ra_assists = { path = "../ra_assists" } 27ra_assists = { path = "../ra_assists" }
28 28
29[dev-dependencies] 29[dev-dependencies]
30insta = "0.6.1" 30insta = "0.7.0"
31 31
32[features] 32[features]
33jemalloc = [ "jemallocator", "jemalloc-ctl" ] 33jemalloc = [ "jemallocator", "jemalloc-ctl" ]
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 9ec179593..364263d9b 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -47,9 +47,10 @@ pub(crate) fn reference_definition(
47 name_ref: &ast::NameRef, 47 name_ref: &ast::NameRef,
48) -> ReferenceResult { 48) -> ReferenceResult {
49 use self::ReferenceResult::*; 49 use self::ReferenceResult::*;
50 if let Some(function) = 50
51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) 51 let function = hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax());
52 { 52
53 if let Some(function) = function {
53 // Check if it is a method 54 // Check if it is a method
54 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { 55 if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
55 tested_by!(goto_definition_works_for_methods); 56 tested_by!(goto_definition_works_for_methods);
@@ -122,9 +123,29 @@ pub(crate) fn reference_definition(
122 Some(Resolution::SelfType(_impl_block)) => { 123 Some(Resolution::SelfType(_impl_block)) => {
123 // TODO: go to the implemented type 124 // TODO: go to the implemented type
124 } 125 }
125 None => {} 126 None => {
127 // If we failed to resolve then check associated items
128 if let Some(function) = function {
129 // Should we do this above and then grab path from the PathExpr?
130 if let Some(path_expr) =
131 name_ref.syntax().ancestors().find_map(ast::PathExpr::cast)
132 {
133 let infer_result = function.infer(db);
134 let source_map = function.body_source_map(db);
135 let expr = ast::Expr::cast(path_expr.syntax()).unwrap();
136
137 if let Some(res) = source_map
138 .node_expr(expr)
139 .and_then(|it| infer_result.assoc_resolutions_for_expr(it.into()))
140 {
141 return Exact(NavigationTarget::from_impl_item(db, res));
142 }
143 }
144 }
145 }
126 } 146 }
127 } 147 }
148
128 // If that fails try the index based approach. 149 // If that fails try the index based approach.
129 let navs = crate::symbol_index::index_resolve(db, name_ref) 150 let navs = crate::symbol_index::index_resolve(db, name_ref)
130 .into_iter() 151 .into_iter()
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 8ec60090d..bcd052c8b 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -512,4 +512,26 @@ mod tests {
512 let hover = analysis.hover(position).unwrap().unwrap(); 512 let hover = analysis.hover(position).unwrap().unwrap();
513 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); 513 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
514 } 514 }
515
516 #[test]
517 fn test_hover_infer_associated_method_exact() {
518 let (analysis, position) = single_file_with_position(
519 "
520 struct Thing { x: u32 }
521
522 impl Thing {
523 fn new() -> Thing {
524 Thing { x: 0 }
525 }
526 }
527
528 fn main() {
529 let foo_test = Thing::new<|>();
530 }
531 ",
532 );
533 let hover = analysis.hover(position).unwrap().unwrap();
534 assert_eq!(trim_markup_opt(hover.info.first()), Some("fn new() -> Thing"));
535 assert_eq!(hover.info.is_exact(), true);
536 }
515} 537}
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 6538081ac..d806cb368 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
5}; 5};
6use hir::{ModuleSource, FieldSource, Name}; 6use hir::{ModuleSource, FieldSource, Name, ImplItem};
7 7
8use crate::{FileSymbol, db::RootDatabase}; 8use crate::{FileSymbol, db::RootDatabase};
9 9
@@ -174,6 +174,20 @@ impl NavigationTarget {
174 ) 174 )
175 } 175 }
176 176
177 pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget {
178 match impl_item {
179 ImplItem::Method(f) => NavigationTarget::from_function(db, f),
180 ImplItem::Const(c) => {
181 let (file_id, node) = c.source(db);
182 NavigationTarget::from_named(file_id.original_file(db), &*node)
183 }
184 ImplItem::TypeAlias(a) => {
185 let (file_id, node) = a.source(db);
186 NavigationTarget::from_named(file_id.original_file(db), &*node)
187 }
188 }
189 }
190
177 #[cfg(test)] 191 #[cfg(test)]
178 pub(crate) fn assert_match(&self, expected: &str) { 192 pub(crate) fn assert_match(&self, expected: &str) {
179 let actual = self.debug_render(); 193 let actual = self.debug_render();
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs
index 414327ac2..94fe1d6d7 100644
--- a/crates/ra_ide_api/src/symbol_index.rs
+++ b/crates/ra_ide_api/src/symbol_index.rs
@@ -24,6 +24,7 @@ use std::{
24 hash::{Hash, Hasher}, 24 hash::{Hash, Hasher},
25 sync::Arc, 25 sync::Arc,
26 mem, 26 mem,
27 fmt,
27}; 28};
28 29
29use fst::{self, Streamer}; 30use fst::{self, Streamer};
@@ -113,12 +114,18 @@ pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<F
113 crate::symbol_index::world_symbols(db, query) 114 crate::symbol_index::world_symbols(db, query)
114} 115}
115 116
116#[derive(Default, Debug)] 117#[derive(Default)]
117pub(crate) struct SymbolIndex { 118pub(crate) struct SymbolIndex {
118 symbols: Vec<FileSymbol>, 119 symbols: Vec<FileSymbol>,
119 map: fst::Map, 120 map: fst::Map,
120} 121}
121 122
123impl fmt::Debug for SymbolIndex {
124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125 f.debug_struct("SymbolIndex").field("n_symbols", &self.symbols.len()).finish()
126 }
127}
128
122impl PartialEq for SymbolIndex { 129impl PartialEq for SymbolIndex {
123 fn eq(&self, other: &SymbolIndex) -> bool { 130 fn eq(&self, other: &SymbolIndex) -> bool {
124 self.symbols == other.symbols 131 self.symbols == other.symbols
diff --git a/crates/ra_ide_api_light/Cargo.toml b/crates/ra_ide_api_light/Cargo.toml
index 29c1f4639..a30833dc3 100644
--- a/crates/ra_ide_api_light/Cargo.toml
+++ b/crates/ra_ide_api_light/Cargo.toml
@@ -18,4 +18,4 @@ ra_fmt = { path = "../ra_fmt" }
18[dev-dependencies] 18[dev-dependencies]
19test_utils = { path = "../test_utils" } 19test_utils = { path = "../test_utils" }
20proptest = "0.9.0" 20proptest = "0.9.0"
21insta = "0.6.1" 21insta = "0.7.0"
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index ef6dea393..a36e6b5ae 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -12,7 +12,7 @@ failure_derive = "0.1.4"
12serde_json = "1.0.34" 12serde_json = "1.0.34"
13serde = "1.0.83" 13serde = "1.0.83"
14crossbeam-channel = "0.3.5" 14crossbeam-channel = "0.3.5"
15flexi_logger = "0.10.0" 15flexi_logger = "0.11.0"
16log = "0.4.3" 16log = "0.4.3"
17url_serde = "0.2.0" 17url_serde = "0.2.0"
18lsp-types = "0.56.0" 18lsp-types = "0.56.0"
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/init.rs
new file mode 100644
index 000000000..0b7a47a0b
--- /dev/null
+++ b/crates/ra_lsp_server/src/init.rs
@@ -0,0 +1,39 @@
1use serde::{Deserialize, Deserializer};
2
3/// Client provided initialization options
4#[derive(Deserialize, Clone, Copy, Debug)]
5#[serde(rename_all = "camelCase")]
6pub struct InitializationOptions {
7 /// Whether the client supports our custom highlighting publishing decorations.
8 /// This is different to the highlightingOn setting, which is whether the user
9 /// wants our custom highlighting to be used.
10 ///
11 /// Defaults to `true`
12 #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")]
13 pub publish_decorations: bool,
14
15 /// Whether or not the workspace loaded notification should be sent
16 ///
17 /// Defaults to `true`
18 #[serde(default = "bool_true", deserialize_with = "nullable_bool_true")]
19 pub show_workspace_loaded: bool,
20}
21
22impl Default for InitializationOptions {
23 fn default() -> InitializationOptions {
24 InitializationOptions { publish_decorations: true, show_workspace_loaded: true }
25 }
26}
27
28fn bool_true() -> bool {
29 true
30}
31
32/// Deserializes a null value to a bool true by default
33fn nullable_bool_true<'de, D>(deserializer: D) -> Result<bool, D::Error>
34where
35 D: Deserializer<'de>,
36{
37 let opt = Option::deserialize(deserializer)?;
38 Ok(opt.unwrap_or(true))
39}
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index 5b5f3b948..59e16a47c 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -5,7 +5,8 @@ mod main_loop;
5mod markdown; 5mod markdown;
6mod project_model; 6mod project_model;
7pub mod req; 7pub mod req;
8pub mod init;
8mod server_world; 9mod server_world;
9 10
10pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 11pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
11pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; 12pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions};
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index 03f83c7be..5a2905207 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -2,7 +2,7 @@ use serde::Deserialize;
2use flexi_logger::{Duplicate, Logger}; 2use flexi_logger::{Duplicate, Logger};
3use gen_lsp_server::{run_server, stdio_transport}; 3use gen_lsp_server::{run_server, stdio_transport};
4 4
5use ra_lsp_server::Result; 5use ra_lsp_server::{Result, InitializationOptions};
6 6
7fn main() -> Result<()> { 7fn main() -> Result<()> {
8 ::std::env::set_var("RUST_BACKTRACE", "short"); 8 ::std::env::set_var("RUST_BACKTRACE", "short");
@@ -24,26 +24,18 @@ fn main() -> Result<()> {
24 } 24 }
25} 25}
26 26
27#[derive(Deserialize)]
28#[serde(rename_all = "camelCase")]
29struct InitializationOptions {
30 // Whether the client supports our custom highlighting publishing decorations.
31 // This is different to the highlightingOn setting, which is whether the user
32 // wants our custom highlighting to be used.
33 publish_decorations: Option<bool>,
34}
35
36fn main_inner() -> Result<()> { 27fn main_inner() -> Result<()> {
37 let (receiver, sender, threads) = stdio_transport(); 28 let (receiver, sender, threads) = stdio_transport();
38 let cwd = ::std::env::current_dir()?; 29 let cwd = ::std::env::current_dir()?;
39 run_server(ra_lsp_server::server_capabilities(), receiver, sender, |params, r, s| { 30 run_server(ra_lsp_server::server_capabilities(), receiver, sender, |params, r, s| {
40 let root = params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd); 31 let root = params.root_uri.and_then(|it| it.to_file_path().ok()).unwrap_or(cwd);
41 let supports_decorations = params 32
33 let opts = params
42 .initialization_options 34 .initialization_options
43 .and_then(|v| InitializationOptions::deserialize(v).ok()) 35 .and_then(|v| InitializationOptions::deserialize(v).ok())
44 .and_then(|it| it.publish_decorations) 36 .unwrap_or(InitializationOptions::default());
45 == Some(true); 37
46 ra_lsp_server::main_loop(false, root, supports_decorations, r, s) 38 ra_lsp_server::main_loop(root, opts, r, s)
47 })?; 39 })?;
48 log::info!("shutting down IO..."); 40 log::info!("shutting down IO...");
49 threads.join()?; 41 threads.join()?;
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index ce50fb301..d0c2a95ef 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -22,6 +22,7 @@ use crate::{
22 req, 22 req,
23 server_world::{ServerWorld, ServerWorldState}, 23 server_world::{ServerWorld, ServerWorldState},
24 Result, 24 Result,
25 InitializationOptions,
25}; 26};
26 27
27#[derive(Debug, Fail)] 28#[derive(Debug, Fail)]
@@ -46,9 +47,8 @@ enum Task {
46const THREADPOOL_SIZE: usize = 8; 47const THREADPOOL_SIZE: usize = 8;
47 48
48pub fn main_loop( 49pub fn main_loop(
49 internal_mode: bool,
50 ws_root: PathBuf, 50 ws_root: PathBuf,
51 supports_decorations: bool, 51 options: InitializationOptions,
52 msg_receiver: &Receiver<RawMessage>, 52 msg_receiver: &Receiver<RawMessage>,
53 msg_sender: &Sender<RawMessage>, 53 msg_sender: &Sender<RawMessage>,
54) -> Result<()> { 54) -> Result<()> {
@@ -63,6 +63,12 @@ pub fn main_loop(
63 Ok(ws) => vec![ws], 63 Ok(ws) => vec![ws],
64 Err(e) => { 64 Err(e) => {
65 log::error!("loading workspace failed: {}", e); 65 log::error!("loading workspace failed: {}", e);
66
67 show_message(
68 req::MessageType::Error,
69 format!("rust-analyzer failed to load workspace: {}", e),
70 msg_sender,
71 );
66 Vec::new() 72 Vec::new()
67 } 73 }
68 } 74 }
@@ -75,8 +81,7 @@ pub fn main_loop(
75 let mut pending_requests = FxHashSet::default(); 81 let mut pending_requests = FxHashSet::default();
76 let mut subs = Subscriptions::new(); 82 let mut subs = Subscriptions::new();
77 let main_res = main_loop_inner( 83 let main_res = main_loop_inner(
78 internal_mode, 84 options,
79 supports_decorations,
80 &pool, 85 &pool,
81 msg_sender, 86 msg_sender,
82 msg_receiver, 87 msg_receiver,
@@ -143,8 +148,7 @@ impl fmt::Debug for Event {
143} 148}
144 149
145fn main_loop_inner( 150fn main_loop_inner(
146 internal_mode: bool, 151 options: InitializationOptions,
147 supports_decorations: bool,
148 pool: &ThreadPool, 152 pool: &ThreadPool,
149 msg_sender: &Sender<RawMessage>, 153 msg_sender: &Sender<RawMessage>,
150 msg_receiver: &Receiver<RawMessage>, 154 msg_receiver: &Receiver<RawMessage>,
@@ -158,6 +162,7 @@ fn main_loop_inner(
158 // time to always have a thread ready to react to input. 162 // time to always have a thread ready to react to input.
159 let mut in_flight_libraries = 0; 163 let mut in_flight_libraries = 0;
160 let mut pending_libraries = Vec::new(); 164 let mut pending_libraries = Vec::new();
165 let mut send_workspace_notification = true;
161 166
162 let (libdata_sender, libdata_receiver) = unbounded(); 167 let (libdata_sender, libdata_receiver) = unbounded();
163 loop { 168 loop {
@@ -185,7 +190,6 @@ fn main_loop_inner(
185 state_changed = true; 190 state_changed = true;
186 } 191 }
187 Event::Lib(lib) => { 192 Event::Lib(lib) => {
188 feedback(internal_mode, "library loaded", msg_sender);
189 state.add_lib(lib); 193 state.add_lib(lib);
190 in_flight_libraries -= 1; 194 in_flight_libraries -= 1;
191 } 195 }
@@ -199,7 +203,7 @@ fn main_loop_inner(
199 Ok((id, ())) => { 203 Ok((id, ())) => {
200 state.collect_garbage(); 204 state.collect_garbage();
201 let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); 205 let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
202 msg_sender.send(RawMessage::Response(resp)).unwrap() 206 msg_sender.send(resp.into()).unwrap()
203 } 207 }
204 Err(req) => { 208 Err(req) => {
205 match on_request(state, pending_requests, pool, &task_sender, req)? { 209 match on_request(state, pending_requests, pool, &task_sender, req)? {
@@ -211,7 +215,7 @@ fn main_loop_inner(
211 ErrorCode::MethodNotFound as i32, 215 ErrorCode::MethodNotFound as i32,
212 "unknown request".to_string(), 216 "unknown request".to_string(),
213 ); 217 );
214 msg_sender.send(RawMessage::Response(resp)).unwrap() 218 msg_sender.send(resp.into()).unwrap()
215 } 219 }
216 } 220 }
217 } 221 }
@@ -239,15 +243,23 @@ fn main_loop_inner(
239 }); 243 });
240 } 244 }
241 245
242 if state.roots_to_scan == 0 && pending_libraries.is_empty() && in_flight_libraries == 0 { 246 if send_workspace_notification
243 feedback(internal_mode, "workspace loaded", msg_sender); 247 && state.roots_to_scan == 0
248 && pending_libraries.is_empty()
249 && in_flight_libraries == 0
250 {
251 if options.show_workspace_loaded {
252 show_message(req::MessageType::Info, "workspace loaded", msg_sender);
253 }
254 // Only send the notification first time
255 send_workspace_notification = false;
244 } 256 }
245 257
246 if state_changed { 258 if state_changed {
247 update_file_notifications_on_threadpool( 259 update_file_notifications_on_threadpool(
248 pool, 260 pool,
249 state.snapshot(), 261 state.snapshot(),
250 supports_decorations, 262 options.publish_decorations,
251 task_sender.clone(), 263 task_sender.clone(),
252 subs.subscriptions(), 264 subs.subscriptions(),
253 ) 265 )
@@ -260,11 +272,11 @@ fn on_task(task: Task, msg_sender: &Sender<RawMessage>, pending_requests: &mut F
260 match task { 272 match task {
261 Task::Respond(response) => { 273 Task::Respond(response) => {
262 if pending_requests.remove(&response.id) { 274 if pending_requests.remove(&response.id) {
263 msg_sender.send(RawMessage::Response(response)).unwrap(); 275 msg_sender.send(response.into()).unwrap();
264 } 276 }
265 } 277 }
266 Task::Notify(n) => { 278 Task::Notify(n) => {
267 msg_sender.send(RawMessage::Notification(n)).unwrap(); 279 msg_sender.send(n.into()).unwrap();
268 } 280 }
269 } 281 }
270} 282}
@@ -336,7 +348,7 @@ fn on_notification(
336 ErrorCode::RequestCanceled as i32, 348 ErrorCode::RequestCanceled as i32,
337 "canceled by client".to_string(), 349 "canceled by client".to_string(),
338 ); 350 );
339 msg_sender.send(RawMessage::Response(response)).unwrap() 351 msg_sender.send(response.into()).unwrap()
340 } 352 }
341 return Ok(()); 353 return Ok(());
342 } 354 }
@@ -375,7 +387,7 @@ fn on_notification(
375 } 387 }
376 let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; 388 let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() };
377 let not = RawNotification::new::<req::PublishDiagnostics>(&params); 389 let not = RawNotification::new::<req::PublishDiagnostics>(&params);
378 msg_sender.send(RawMessage::Notification(not)).unwrap(); 390 msg_sender.send(not.into()).unwrap();
379 return Ok(()); 391 return Ok(());
380 } 392 }
381 Err(not) => not, 393 Err(not) => not,
@@ -496,12 +508,13 @@ fn update_file_notifications_on_threadpool(
496 }); 508 });
497} 509}
498 510
499fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) { 511fn show_message<M: Into<String>>(typ: req::MessageType, msg: M, sender: &Sender<RawMessage>) {
500 if !intrnal_mode { 512 let not = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams {
501 return; 513 typ,
502 } 514 message: msg.into(),
503 let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string()); 515 });
504 sender.send(RawMessage::Notification(not)).unwrap(); 516
517 sender.send(not.into()).unwrap();
505} 518}
506 519
507fn is_canceled(e: &failure::Error) -> bool { 520fn is_canceled(e: &failure::Error) -> bool {
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index 5c589f969..e0571fd78 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -8,7 +8,8 @@ pub use lsp_types::{
8 CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, 8 CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
9 DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, 9 DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
10 PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, 10 PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
11 TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams 11 TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams,
12 MessageType, ShowMessageParams,
12}; 13};
13 14
14pub enum AnalyzerStatus {} 15pub enum AnalyzerStatus {}
@@ -171,10 +172,3 @@ pub struct SourceChange {
171 pub workspace_edit: WorkspaceEdit, 172 pub workspace_edit: WorkspaceEdit,
172 pub cursor_position: Option<TextDocumentPositionParams>, 173 pub cursor_position: Option<TextDocumentPositionParams>,
173} 174}
174
175pub enum InternalFeedback {}
176
177impl Notification for InternalFeedback {
178 const METHOD: &'static str = "internalFeedback";
179 type Params = String;
180}
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 996bf8e01..1c099a78f 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -31,7 +31,7 @@ version = "0.0.0"
31use std::collections::Spam; 31use std::collections::Spam;
32"#, 32"#,
33 ); 33 );
34 server.wait_for_feedback("workspace loaded"); 34 server.wait_for_message("workspace loaded");
35 eprintln!("loading took {:?}", project_start.elapsed()); 35 eprintln!("loading took {:?}", project_start.elapsed());
36 let completion_start = Instant::now(); 36 let completion_start = Instant::now();
37 let res = server.send_request::<Completion>(CompletionParams { 37 let res = server.send_request::<Completion>(CompletionParams {
@@ -53,7 +53,7 @@ fn foo() {
53} 53}
54", 54",
55 ); 55 );
56 server.wait_for_feedback("workspace loaded"); 56 server.wait_for_message("workspace loaded");
57 server.request::<Runnables>( 57 server.request::<Runnables>(
58 RunnablesParams { text_document: server.doc_id("lib.rs"), position: None }, 58 RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
59 json!([ 59 json!([
@@ -107,7 +107,7 @@ pub fn foo() {}
107fn test_eggs() {} 107fn test_eggs() {}
108"#, 108"#,
109 ); 109 );
110 server.wait_for_feedback("workspace loaded"); 110 server.wait_for_message("workspace loaded");
111 server.request::<Runnables>( 111 server.request::<Runnables>(
112 RunnablesParams { 112 RunnablesParams {
113 text_document: server.doc_id("tests/spam.rs"), 113 text_document: server.doc_id("tests/spam.rs"),
@@ -167,7 +167,7 @@ fn main() {
167pub use std::collections::HashMap; 167pub use std::collections::HashMap;
168"#, 168"#,
169 ); 169 );
170 server.wait_for_feedback("workspace loaded"); 170 server.wait_for_message("workspace loaded");
171 171
172 server.request::<Formatting>( 172 server.request::<Formatting>(
173 DocumentFormattingParams { 173 DocumentFormattingParams {
@@ -216,7 +216,7 @@ mod bar;
216fn main() {} 216fn main() {}
217"#, 217"#,
218 ); 218 );
219 server.wait_for_feedback("workspace loaded"); 219 server.wait_for_message("workspace loaded");
220 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; 220 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
221 server.request::<CodeActionRequest>( 221 server.request::<CodeActionRequest>(
222 CodeActionParams { 222 CodeActionParams {
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index f4e7eaf75..8bfc8d622 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -13,6 +13,7 @@ use lsp_types::{
13 notification::DidOpenTextDocument, 13 notification::DidOpenTextDocument,
14 request::{Request, Shutdown}, 14 request::{Request, Shutdown},
15 DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, 15 DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url,
16 notification::{Notification, ShowMessage},
16}; 17};
17use serde::Serialize; 18use serde::Serialize;
18use serde_json::{to_string_pretty, Value}; 19use serde_json::{to_string_pretty, Value};
@@ -22,6 +23,7 @@ use test_utils::{parse_fixture, find_mismatch};
22 23
23use ra_lsp_server::{ 24use ra_lsp_server::{
24 main_loop, req, 25 main_loop, req,
26 InitializationOptions,
25}; 27};
26 28
27pub fn project(fixture: &str) -> Server { 29pub fn project(fixture: &str) -> Server {
@@ -56,7 +58,13 @@ impl Server {
56 "test server", 58 "test server",
57 128, 59 128,
58 move |mut msg_receiver, mut msg_sender| { 60 move |mut msg_receiver, mut msg_sender| {
59 main_loop(true, path, true, &mut msg_receiver, &mut msg_sender).unwrap() 61 main_loop(
62 path,
63 InitializationOptions::default(),
64 &mut msg_receiver,
65 &mut msg_sender,
66 )
67 .unwrap()
60 }, 68 },
61 ); 69 );
62 let res = Server { 70 let res = Server {
@@ -133,13 +141,14 @@ impl Server {
133 } 141 }
134 panic!("no response"); 142 panic!("no response");
135 } 143 }
136 pub fn wait_for_feedback(&self, feedback: &str) { 144 pub fn wait_for_message(&self, message: &str) {
137 self.wait_for_feedback_n(feedback, 1) 145 self.wait_for_message_n(message, 1)
138 } 146 }
139 pub fn wait_for_feedback_n(&self, feedback: &str, n: usize) { 147 pub fn wait_for_message_n(&self, message: &str, n: usize) {
140 let f = |msg: &RawMessage| match msg { 148 let f = |msg: &RawMessage| match msg {
141 RawMessage::Notification(n) if n.method == "internalFeedback" => { 149 RawMessage::Notification(n) if n.method == ShowMessage::METHOD => {
142 return n.clone().cast::<req::InternalFeedback>().unwrap() == feedback; 150 let msg = n.clone().cast::<req::ShowMessage>().unwrap();
151 msg.message == message
143 } 152 }
144 _ => false, 153 _ => false,
145 }; 154 };
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index e74305b6a..9f282c74d 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -281,10 +281,16 @@ fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
281 281
282// test cond 282// test cond
283// fn foo() { if let Some(_) = None {} } 283// fn foo() { if let Some(_) = None {} }
284// fn bar() {
285// if let Some(_) | Some(_) = None {}
286// if let | Some(_) = None {}
287// while let Some(_) | Some(_) = None {}
288// while let | Some(_) = None {}
289// }
284fn cond(p: &mut Parser) { 290fn cond(p: &mut Parser) {
285 let m = p.start(); 291 let m = p.start();
286 if p.eat(LET_KW) { 292 if p.eat(LET_KW) {
287 patterns::pattern(p); 293 patterns::pattern_list(p);
288 p.expect(EQ); 294 p.expect(EQ);
289 } 295 }
290 expr_no_struct(p); 296 expr_no_struct(p);
@@ -376,11 +382,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
376// } 382// }
377fn match_arm(p: &mut Parser) -> BlockLike { 383fn match_arm(p: &mut Parser) -> BlockLike {
378 let m = p.start(); 384 let m = p.start();
379 p.eat(PIPE); 385 patterns::pattern_list_r(p, TokenSet::empty());
380 patterns::pattern_r(p, TokenSet::empty());
381 while p.eat(PIPE) {
382 patterns::pattern(p);
383 }
384 if p.at(IF_KW) { 386 if p.at(IF_KW) {
385 match_guard(p); 387 match_guard(p);
386 } 388 }
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index 9d7da639d..befe6687d 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -8,6 +8,22 @@ pub(super) fn pattern(p: &mut Parser) {
8 pattern_r(p, PAT_RECOVERY_SET) 8 pattern_r(p, PAT_RECOVERY_SET)
9} 9}
10 10
11/// Parses a pattern list separated by pipes `|`
12pub(super) fn pattern_list(p: &mut Parser) {
13 pattern_list_r(p, PAT_RECOVERY_SET)
14}
15
16/// Parses a pattern list separated by pipes `|`
17/// using the given `recovery_set`
18pub(super) fn pattern_list_r(p: &mut Parser, recovery_set: TokenSet) {
19 p.eat(PIPE);
20 pattern_r(p, recovery_set);
21
22 while p.eat(PIPE) {
23 pattern_r(p, recovery_set);
24 }
25}
26
11pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { 27pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
12 if let Some(lhs) = atom_pat(p, recovery_set) { 28 if let Some(lhs) = atom_pat(p, recovery_set) {
13 // test range_pat 29 // test range_pat
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.rs
index fdb37ee6f..2552a2621 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.rs
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.rs
@@ -1 +1,7 @@
1fn foo() { if let Some(_) = None {} } 1fn foo() { if let Some(_) = None {} }
2fn bar() {
3 if let Some(_) | Some(_) = None {}
4 if let | Some(_) = None {}
5 while let Some(_) | Some(_) = None {}
6 while let | Some(_) = None {}
7}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.txt
index 641a09fff..6dea1848b 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0030_cond.txt
@@ -1,4 +1,4 @@
1SOURCE_FILE@[0; 38) 1SOURCE_FILE@[0; 197)
2 FN_DEF@[0; 37) 2 FN_DEF@[0; 37)
3 FN_KW@[0; 2) 3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3) 4 WHITESPACE@[2; 3)
@@ -41,3 +41,160 @@ SOURCE_FILE@[0; 38)
41 WHITESPACE@[35; 36) 41 WHITESPACE@[35; 36)
42 R_CURLY@[36; 37) 42 R_CURLY@[36; 37)
43 WHITESPACE@[37; 38) 43 WHITESPACE@[37; 38)
44 FN_DEF@[38; 196)
45 FN_KW@[38; 40)
46 WHITESPACE@[40; 41)
47 NAME@[41; 44)
48 IDENT@[41; 44) "bar"
49 PARAM_LIST@[44; 46)
50 L_PAREN@[44; 45)
51 R_PAREN@[45; 46)
52 WHITESPACE@[46; 47)
53 BLOCK@[47; 196)
54 L_CURLY@[47; 48)
55 WHITESPACE@[48; 53)
56 EXPR_STMT@[53; 87)
57 IF_EXPR@[53; 87)
58 IF_KW@[53; 55)
59 WHITESPACE@[55; 56)
60 CONDITION@[56; 84)
61 LET_KW@[56; 59)
62 WHITESPACE@[59; 60)
63 TUPLE_STRUCT_PAT@[60; 67)
64 PATH@[60; 64)
65 PATH_SEGMENT@[60; 64)
66 NAME_REF@[60; 64)
67 IDENT@[60; 64) "Some"
68 L_PAREN@[64; 65)
69 PLACEHOLDER_PAT@[65; 66)
70 UNDERSCORE@[65; 66)
71 R_PAREN@[66; 67)
72 WHITESPACE@[67; 68)
73 PIPE@[68; 69)
74 WHITESPACE@[69; 70)
75 TUPLE_STRUCT_PAT@[70; 77)
76 PATH@[70; 74)
77 PATH_SEGMENT@[70; 74)
78 NAME_REF@[70; 74)
79 IDENT@[70; 74) "Some"
80 L_PAREN@[74; 75)
81 PLACEHOLDER_PAT@[75; 76)
82 UNDERSCORE@[75; 76)
83 R_PAREN@[76; 77)
84 WHITESPACE@[77; 78)
85 EQ@[78; 79)
86 WHITESPACE@[79; 80)
87 PATH_EXPR@[80; 84)
88 PATH@[80; 84)
89 PATH_SEGMENT@[80; 84)
90 NAME_REF@[80; 84)
91 IDENT@[80; 84) "None"
92 WHITESPACE@[84; 85)
93 BLOCK@[85; 87)
94 L_CURLY@[85; 86)
95 R_CURLY@[86; 87)
96 WHITESPACE@[87; 92)
97 EXPR_STMT@[92; 118)
98 IF_EXPR@[92; 118)
99 IF_KW@[92; 94)
100 WHITESPACE@[94; 95)
101 CONDITION@[95; 115)
102 LET_KW@[95; 98)
103 WHITESPACE@[98; 99)
104 PIPE@[99; 100)
105 WHITESPACE@[100; 101)
106 TUPLE_STRUCT_PAT@[101; 108)
107 PATH@[101; 105)
108 PATH_SEGMENT@[101; 105)
109 NAME_REF@[101; 105)
110 IDENT@[101; 105) "Some"
111 L_PAREN@[105; 106)
112 PLACEHOLDER_PAT@[106; 107)
113 UNDERSCORE@[106; 107)
114 R_PAREN@[107; 108)
115 WHITESPACE@[108; 109)
116 EQ@[109; 110)
117 WHITESPACE@[110; 111)
118 PATH_EXPR@[111; 115)
119 PATH@[111; 115)
120 PATH_SEGMENT@[111; 115)
121 NAME_REF@[111; 115)
122 IDENT@[111; 115) "None"
123 WHITESPACE@[115; 116)
124 BLOCK@[116; 118)
125 L_CURLY@[116; 117)
126 R_CURLY@[117; 118)
127 WHITESPACE@[118; 123)
128 EXPR_STMT@[123; 160)
129 WHILE_EXPR@[123; 160)
130 WHILE_KW@[123; 128)
131 WHITESPACE@[128; 129)
132 CONDITION@[129; 157)
133 LET_KW@[129; 132)
134 WHITESPACE@[132; 133)
135 TUPLE_STRUCT_PAT@[133; 140)
136 PATH@[133; 137)
137 PATH_SEGMENT@[133; 137)
138 NAME_REF@[133; 137)
139 IDENT@[133; 137) "Some"
140 L_PAREN@[137; 138)
141 PLACEHOLDER_PAT@[138; 139)
142 UNDERSCORE@[138; 139)
143 R_PAREN@[139; 140)
144 WHITESPACE@[140; 141)
145 PIPE@[141; 142)
146 WHITESPACE@[142; 143)
147 TUPLE_STRUCT_PAT@[143; 150)
148 PATH@[143; 147)
149 PATH_SEGMENT@[143; 147)
150 NAME_REF@[143; 147)
151 IDENT@[143; 147) "Some"
152 L_PAREN@[147; 148)
153 PLACEHOLDER_PAT@[148; 149)
154 UNDERSCORE@[148; 149)
155 R_PAREN@[149; 150)
156 WHITESPACE@[150; 151)
157 EQ@[151; 152)
158 WHITESPACE@[152; 153)
159 PATH_EXPR@[153; 157)
160 PATH@[153; 157)
161 PATH_SEGMENT@[153; 157)
162 NAME_REF@[153; 157)
163 IDENT@[153; 157) "None"
164 WHITESPACE@[157; 158)
165 BLOCK@[158; 160)
166 L_CURLY@[158; 159)
167 R_CURLY@[159; 160)
168 WHITESPACE@[160; 165)
169 WHILE_EXPR@[165; 194)
170 WHILE_KW@[165; 170)
171 WHITESPACE@[170; 171)
172 CONDITION@[171; 191)
173 LET_KW@[171; 174)
174 WHITESPACE@[174; 175)
175 PIPE@[175; 176)
176 WHITESPACE@[176; 177)
177 TUPLE_STRUCT_PAT@[177; 184)
178 PATH@[177; 181)
179 PATH_SEGMENT@[177; 181)
180 NAME_REF@[177; 181)
181 IDENT@[177; 181) "Some"
182 L_PAREN@[181; 182)
183 PLACEHOLDER_PAT@[182; 183)
184 UNDERSCORE@[182; 183)
185 R_PAREN@[183; 184)
186 WHITESPACE@[184; 185)
187 EQ@[185; 186)
188 WHITESPACE@[186; 187)
189 PATH_EXPR@[187; 191)
190 PATH@[187; 191)
191 PATH_SEGMENT@[187; 191)
192 NAME_REF@[187; 191)
193 IDENT@[187; 191) "None"
194 WHITESPACE@[191; 192)
195 BLOCK@[192; 194)
196 L_CURLY@[192; 193)
197 R_CURLY@[193; 194)
198 WHITESPACE@[194; 195)
199 R_CURLY@[195; 196)
200 WHITESPACE@[196; 197)