aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/algo.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs5
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs16
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs24
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs5
6 files changed, 27 insertions, 29 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
index a8ff2e74f..49696ce75 100644
--- a/crates/ra_syntax/Cargo.toml
+++ b/crates/ra_syntax/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
13[dependencies] 13[dependencies]
14itertools = "0.9.0" 14itertools = "0.9.0"
15rowan = "0.10.0" 15rowan = "0.10.0"
16rustc_lexer = { version = "661.0.0", package = "rustc-ap-rustc_lexer" } 16rustc_lexer = { version = "666.0.0", package = "rustc-ap-rustc_lexer" }
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18arrayvec = "0.5.1" 18arrayvec = "0.5.1"
19once_cell = "1.3.1" 19once_cell = "1.3.1"
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs
index f7a885eb3..26b3c813a 100644
--- a/crates/ra_syntax/src/algo.rs
+++ b/crates/ra_syntax/src/algo.rs
@@ -41,6 +41,10 @@ pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextSize) ->
41 ancestors_at_offset(syntax, offset).find_map(N::cast) 41 ancestors_at_offset(syntax, offset).find_map(N::cast)
42} 42}
43 43
44pub fn find_node_at_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
45 find_covering_element(syntax, range).ancestors().find_map(N::cast)
46}
47
44/// Skip to next non `trivia` token 48/// Skip to next non `trivia` token
45pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> { 49pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> {
46 while token.kind().is_trivia() { 50 while token.kind().is_trivia() {
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 7771d6759..db5438d68 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -399,10 +399,7 @@ impl ast::BlockExpr {
399 Some(it) => it, 399 Some(it) => it,
400 None => return true, 400 None => return true,
401 }; 401 };
402 match parent.kind() { 402 !matches!(parent.kind(), FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR)
403 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false,
404 _ => true,
405 }
406 } 403 }
407} 404}
408 405
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 98c38d009..662c6f73e 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -459,16 +459,16 @@ impl ast::RangePat {
459 459
460impl ast::TokenTree { 460impl ast::TokenTree {
461 pub fn left_delimiter_token(&self) -> Option<SyntaxToken> { 461 pub fn left_delimiter_token(&self) -> Option<SyntaxToken> {
462 self.syntax().first_child_or_token()?.into_token().filter(|it| match it.kind() { 462 self.syntax()
463 T!['{'] | T!['('] | T!['['] => true, 463 .first_child_or_token()?
464 _ => false, 464 .into_token()
465 }) 465 .filter(|it| matches!(it.kind(), T!['{'] | T!['('] | T!['[']))
466 } 466 }
467 467
468 pub fn right_delimiter_token(&self) -> Option<SyntaxToken> { 468 pub fn right_delimiter_token(&self) -> Option<SyntaxToken> {
469 self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { 469 self.syntax()
470 T!['}'] | T![')'] | T![']'] => true, 470 .last_child_or_token()?
471 _ => false, 471 .into_token()
472 }) 472 .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']']))
473 } 473 }
474} 474}
diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs
index 1a5a6dc06..fa3be1016 100644
--- a/crates/ra_syntax/src/parsing/lexer.rs
+++ b/crates/ra_syntax/src/parsing/lexer.rs
@@ -1,6 +1,8 @@
1//! Lexer analyzes raw input string and produces lexemes (tokens). 1//! Lexer analyzes raw input string and produces lexemes (tokens).
2//! It is just a bridge to `rustc_lexer`. 2//! It is just a bridge to `rustc_lexer`.
3 3
4use rustc_lexer::{LiteralKind as LK, RawStrError};
5
4use std::convert::TryInto; 6use std::convert::TryInto;
5 7
6use crate::{ 8use crate::{
@@ -180,8 +182,6 @@ fn rustc_token_kind_to_syntax_kind(
180 return (syntax_kind, None); 182 return (syntax_kind, None);
181 183
182 fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) { 184 fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) {
183 use rustc_lexer::{LexRawStrError, LiteralKind as LK};
184
185 #[rustfmt::skip] 185 #[rustfmt::skip]
186 let syntax_kind = match *kind { 186 let syntax_kind = match *kind {
187 LK::Int { empty_int: false, .. } => INT_NUMBER, 187 LK::Int { empty_int: false, .. } => INT_NUMBER,
@@ -215,27 +215,27 @@ fn rustc_token_kind_to_syntax_kind(
215 return (BYTE_STRING, Some("Missing trailing `\"` symbol to terminate the byte string literal")) 215 return (BYTE_STRING, Some("Missing trailing `\"` symbol to terminate the byte string literal"))
216 } 216 }
217 217
218 LK::RawStr(str) => match str.validate() { 218 LK::RawStr { err, .. } => match err {
219 Ok(_) => RAW_STRING, 219 None => RAW_STRING,
220 Err(LexRawStrError::InvalidStarter) => return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")), 220 Some(RawStrError::InvalidStarter { .. }) => return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")),
221 Err(LexRawStrError::NoTerminator { expected, found, .. }) => if expected == found { 221 Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found {
222 return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal")) 222 return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal"))
223 } else { 223 } else {
224 return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal")) 224 return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal"))
225 225
226 }, 226 },
227 Err(LexRawStrError::TooManyDelimiters { .. }) => return (RAW_STRING, Some("Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols")), 227 Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_STRING, Some("Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols")),
228 }, 228 },
229 LK::RawByteStr(str) => match str.validate() { 229 LK::RawByteStr { err, .. } => match err {
230 Ok(_) => RAW_BYTE_STRING, 230 None => RAW_BYTE_STRING,
231 Err(LexRawStrError::InvalidStarter) => return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")), 231 Some(RawStrError::InvalidStarter { .. }) => return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")),
232 Err(LexRawStrError::NoTerminator { expected, found, .. }) => if expected == found { 232 Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found {
233 return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal")) 233 return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal"))
234 } else { 234 } else {
235 return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal")) 235 return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal"))
236 236
237 }, 237 },
238 Err(LexRawStrError::TooManyDelimiters { .. }) => return (RAW_BYTE_STRING, Some("Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols")), 238 Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_BYTE_STRING, Some("Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols")),
239 }, 239 },
240 }; 240 };
241 241
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index edbc190f8..ed5a42ea3 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -120,10 +120,7 @@ fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String {
120} 120}
121 121
122fn is_contextual_kw(text: &str) -> bool { 122fn is_contextual_kw(text: &str) -> bool {
123 match text { 123 matches!(text, "auto" | "default" | "union")
124 "auto" | "default" | "union" => true,
125 _ => false,
126 }
127} 124}
128 125
129fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> { 126fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> {