From b6560e3ebb80a7a96b3c3598ecba232f799fe93f Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 28 Apr 2020 10:23:45 +0200 Subject: Treat comments beginning with four slashes as regular line comments --- crates/ra_syntax/src/ast/tokens.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 3865729b8..481813e38 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -48,6 +48,7 @@ pub enum CommentPlacement { const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = { use {CommentPlacement::*, CommentShape::*}; &[ + ("////", CommentKind { shape: Line, doc: None }), ("///", CommentKind { shape: Line, doc: Some(Outer) }), ("//!", CommentKind { shape: Line, doc: Some(Inner) }), ("/**", CommentKind { shape: Block, doc: Some(Outer) }), -- cgit v1.2.3 From 0bd7d81805df16c8d1f200b13e485f6dda22f104 Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 28 Apr 2020 21:13:37 +0200 Subject: Fix comment prefix method for four slash comments --- crates/ra_syntax/src/ast/tokens.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 481813e38..74906d8a6 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -13,7 +13,12 @@ impl Comment { } pub fn prefix(&self) -> &'static str { - prefix_by_kind(self.kind()) + for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { + if *k == self.kind() && self.text().starts_with(prefix) { + return prefix; + } + } + unreachable!() } } @@ -70,15 +75,6 @@ fn kind_by_prefix(text: &str) -> CommentKind { panic!("bad comment text: {:?}", text) } -fn prefix_by_kind(kind: CommentKind) -> &'static str { - for (prefix, k) in COMMENT_PREFIX_TO_KIND.iter() { - if *k == kind { - return prefix; - } - } - unreachable!() -} - impl Whitespace { pub fn spans_multiple_lines(&self) -> bool { let text = self.text(); -- cgit v1.2.3 From b4dd4752570d5f1ba24f7ffda69be4b1c935cd04 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 Apr 2020 14:49:54 +0200 Subject: More principled approach for finding From trait --- crates/ra_syntax/src/ast/make.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index ee0f5cc40..492088353 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -22,8 +22,7 @@ pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { path_from_text(&format!("{}::{}", qual, segment)) } - -pub fn path_from_text(text: &str) -> ast::Path { +fn path_from_text(text: &str) -> ast::Path { ast_from_text(text) } -- cgit v1.2.3 From 0af727da91e7ff3c8ed5518cb7e005e8d4f939b0 Mon Sep 17 00:00:00 2001 From: John Renner Date: Mon, 27 Apr 2020 10:02:47 -0700 Subject: Validate the location of `crate` in paths --- crates/ra_syntax/src/ast/generated/nodes.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 2cb3ad011..3b5e05af9 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1249,6 +1249,7 @@ pub struct PathSegment { } impl PathSegment { pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } + pub fn crate_token(&self) -> Option { support::token(&self.syntax, T![crate]) } pub fn l_angle_token(&self) -> Option { support::token(&self.syntax, T![<]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn type_arg_list(&self) -> Option { support::child(&self.syntax) } -- cgit v1.2.3 From 15cfa9a808be820ceafc2e957ea8532e8ec68f00 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 21:36:31 +0200 Subject: Fix a bunch of false-positives in join-lines --- crates/ra_syntax/src/ast/expr_extensions.rs | 5 ++++- crates/ra_syntax/src/ast/generated/nodes.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 93aa3d45f..ecf74fd36 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -368,12 +368,15 @@ impl ast::BlockExpr { /// const FOO: () = { stand_alone }; /// ``` pub fn is_standalone(&self) -> bool { + if self.unsafe_token().is_some() || self.async_token().is_some() { + return false; + } let kind = match self.syntax().parent() { None => return true, Some(it) => it.kind(), }; match kind { - FN_DEF | MATCH_ARM | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, + FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, _ => true, } } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3b5e05af9..d2253d4af 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -554,6 +554,7 @@ impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { pub fn label(&self) -> Option