diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/validation.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/source_id.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind.rs | 1 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 95 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs.tera | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 2 |
18 files changed, 144 insertions, 26 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 61cd9d6b1..d41525779 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::{fmt, any::Any}; | 1 | use std::{fmt, any::Any}; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode}; | 3 | use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode, AstNode}; |
4 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
5 | 5 | ||
6 | use crate::{HirFileId, HirDatabase, Name}; | 6 | use crate::{HirFileId, HirDatabase, Name}; |
@@ -30,7 +30,7 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | |||
30 | impl dyn Diagnostic { | 30 | impl dyn Diagnostic { |
31 | pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { | 31 | pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> { |
32 | let source_file = db.hir_parse(self.file()); | 32 | let source_file = db.hir_parse(self.file()); |
33 | self.syntax_node_ptr().to_node(&source_file).to_owned() | 33 | self.syntax_node_ptr().to_node(source_file.syntax()).to_owned() |
34 | } | 34 | } |
35 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | 35 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { |
36 | self.as_any().downcast_ref() | 36 | self.as_any().downcast_ref() |
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index fd4907313..aebed6788 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -76,7 +76,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
76 | let source_file = db.parse(file_id.original_file(db)); | 76 | let source_file = db.parse(file_id.original_file(db)); |
77 | if let Some(field_list_node) = source_map | 77 | if let Some(field_list_node) = source_map |
78 | .expr_syntax(id) | 78 | .expr_syntax(id) |
79 | .map(|ptr| ptr.to_node(&source_file)) | 79 | .map(|ptr| ptr.to_node(source_file.syntax())) |
80 | .and_then(StructLit::cast) | 80 | .and_then(StructLit::cast) |
81 | .and_then(|lit| lit.named_field_list()) | 81 | .and_then(|lit| lit.named_field_list()) |
82 | { | 82 | { |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index b7dd775f1..51fa491c3 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -34,7 +34,7 @@ impl ImplSourceMap { | |||
34 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | 34 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), |
35 | }; | 35 | }; |
36 | 36 | ||
37 | self.map[impl_id].to_node(file).to_owned() | 37 | self.map[impl_id].to_node(file.syntax()).to_owned() |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 43c97a0bf..211e02068 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -39,7 +39,10 @@ type ImportSource = Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> | |||
39 | 39 | ||
40 | impl ImportSourcePtr { | 40 | impl ImportSourcePtr { |
41 | fn to_node(self, file: &SourceFile) -> ImportSource { | 41 | fn to_node(self, file: &SourceFile) -> ImportSource { |
42 | self.map(|ptr| ptr.to_node(file).to_owned(), |ptr| ptr.to_node(file).to_owned()) | 42 | self.map( |
43 | |ptr| ptr.to_node(file.syntax()).to_owned(), | ||
44 | |ptr| ptr.to_node(file.syntax()).to_owned(), | ||
45 | ) | ||
43 | } | 46 | } |
44 | } | 47 | } |
45 | 48 | ||
diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs index 0a8fb6d32..7a39be779 100644 --- a/crates/ra_hir/src/source_id.rs +++ b/crates/ra_hir/src/source_id.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; | 1 | use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; |
2 | 2 | ||
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, SourceFile, AstNode, ast}; | 4 | use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast}; |
5 | 5 | ||
6 | use crate::{HirFileId, DefDatabase}; | 6 | use crate::{HirFileId, DefDatabase}; |
7 | 7 | ||
@@ -89,7 +89,7 @@ pub struct AstIdMap { | |||
89 | impl AstIdMap { | 89 | impl AstIdMap { |
90 | pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> { | 90 | pub(crate) fn ast_id_map_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc<AstIdMap> { |
91 | let source_file = db.hir_parse(file_id); | 91 | let source_file = db.hir_parse(file_id); |
92 | Arc::new(AstIdMap::from_source_file(&source_file)) | 92 | Arc::new(AstIdMap::from_source(source_file.syntax())) |
93 | } | 93 | } |
94 | 94 | ||
95 | pub(crate) fn file_item_query( | 95 | pub(crate) fn file_item_query( |
@@ -98,7 +98,7 @@ impl AstIdMap { | |||
98 | ast_id: ErasedFileAstId, | 98 | ast_id: ErasedFileAstId, |
99 | ) -> TreeArc<SyntaxNode> { | 99 | ) -> TreeArc<SyntaxNode> { |
100 | let source_file = db.hir_parse(file_id); | 100 | let source_file = db.hir_parse(file_id); |
101 | db.ast_id_map(file_id).arena[ast_id].to_node(&source_file).to_owned() | 101 | db.ast_id_map(file_id).arena[ast_id].to_node(source_file.syntax()).to_owned() |
102 | } | 102 | } |
103 | 103 | ||
104 | pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { | 104 | pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> { |
@@ -115,13 +115,14 @@ impl AstIdMap { | |||
115 | FileAstId { raw, _ty: PhantomData } | 115 | FileAstId { raw, _ty: PhantomData } |
116 | } | 116 | } |
117 | 117 | ||
118 | fn from_source_file(source_file: &SourceFile) -> AstIdMap { | 118 | fn from_source(node: &SyntaxNode) -> AstIdMap { |
119 | assert!(node.parent().is_none()); | ||
119 | let mut res = AstIdMap { arena: Arena::default() }; | 120 | let mut res = AstIdMap { arena: Arena::default() }; |
120 | // By walking the tree in bread-first order we make sure that parents | 121 | // By walking the tree in bread-first order we make sure that parents |
121 | // get lower ids then children. That is, adding a new child does not | 122 | // get lower ids then children. That is, adding a new child does not |
122 | // change parent's id. This means that, say, adding a new function to a | 123 | // change parent's id. This means that, say, adding a new function to a |
123 | // trait does not change ids of top-level items, which helps caching. | 124 | // trait does not change ids of top-level items, which helps caching. |
124 | bfs(source_file.syntax(), |it| { | 125 | bfs(node, |it| { |
125 | if let Some(module_item) = ast::ModuleItem::cast(it) { | 126 | if let Some(module_item) = ast::ModuleItem::cast(it) { |
126 | res.alloc(module_item.syntax()); | 127 | res.alloc(module_item.syntax()); |
127 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { | 128 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 978cc2587..f8364203d 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2715,7 +2715,7 @@ fn infer(content: &str) -> String { | |||
2715 | // sort ranges for consistency | 2715 | // sort ranges for consistency |
2716 | types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); | 2716 | types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); |
2717 | for (syntax_ptr, ty) in &types { | 2717 | for (syntax_ptr, ty) in &types { |
2718 | let node = syntax_ptr.to_node(&source_file); | 2718 | let node = syntax_ptr.to_node(source_file.syntax()); |
2719 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) { | 2719 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) { |
2720 | (self_param.self_kw_token().range(), "self".to_string()) | 2720 | (self_param.self_kw_token().range(), "self".to_string()) |
2721 | } else { | 2721 | } else { |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 4260f7ef7..7de04c044 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -17,7 +17,7 @@ pub(crate) type Solver = chalk_solve::Solver; | |||
17 | /// This controls the maximum size of types Chalk considers. If we set this too | 17 | /// This controls the maximum size of types Chalk considers. If we set this too |
18 | /// high, we can run into slow edge cases; if we set it too low, Chalk won't | 18 | /// high, we can run into slow edge cases; if we set it too low, Chalk won't |
19 | /// find some solutions. | 19 | /// find some solutions. |
20 | const CHALK_SOLVER_MAX_SIZE: usize = 2; | 20 | const CHALK_SOLVER_MAX_SIZE: usize = 4; |
21 | 21 | ||
22 | #[derive(Debug, Copy, Clone)] | 22 | #[derive(Debug, Copy, Clone)] |
23 | struct ChalkContext<'a, DB> { | 23 | struct ChalkContext<'a, DB> { |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 855a3ff0f..e23d178b0 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -54,7 +54,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
54 | let file_id = d.file().original_file(db); | 54 | let file_id = d.file().original_file(db); |
55 | let source_file = db.parse(file_id); | 55 | let source_file = db.parse(file_id); |
56 | let syntax_node = d.syntax_node_ptr(); | 56 | let syntax_node = d.syntax_node_ptr(); |
57 | let node = NamedFieldList::cast(syntax_node.to_node(&source_file)).unwrap(); | 57 | let node = NamedFieldList::cast(syntax_node.to_node(source_file.syntax())).unwrap(); |
58 | let mut ast_editor = AstEditor::new(node); | 58 | let mut ast_editor = AstEditor::new(node); |
59 | for f in d.missed_fields.iter() { | 59 | for f in d.missed_fields.iter() { |
60 | ast_editor.append_field(&AstBuilder::<NamedField>::from_name(f)); | 60 | ast_editor.append_field(&AstBuilder::<NamedField>::from_name(f)); |
@@ -281,7 +281,7 @@ mod tests { | |||
281 | one: i32, | 281 | one: i32, |
282 | two: i64, | 282 | two: i64, |
283 | } | 283 | } |
284 | 284 | ||
285 | fn test_fn() { | 285 | fn test_fn() { |
286 | let one = 1; | 286 | let one = 1; |
287 | let s = TestStruct{ one, two: 2 }; | 287 | let s = TestStruct{ one, two: 2 }; |
@@ -298,7 +298,7 @@ mod tests { | |||
298 | one: i32, | 298 | one: i32, |
299 | two: i64, | 299 | two: i64, |
300 | } | 300 | } |
301 | 301 | ||
302 | fn test_fn() { | 302 | fn test_fn() { |
303 | let one = 1; | 303 | let one = 1; |
304 | let s = TestStruct{ ..a }; | 304 | let s = TestStruct{ ..a }; |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 765cf883b..7ea336c50 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -81,7 +81,7 @@ impl NavigationTarget { | |||
81 | ) -> NavigationTarget { | 81 | ) -> NavigationTarget { |
82 | let file = db.parse(file_id); | 82 | let file = db.parse(file_id); |
83 | let (name, full_range) = match pat { | 83 | let (name, full_range) = match pat { |
84 | Either::A(pat) => match pat.to_node(&file).kind() { | 84 | Either::A(pat) => match pat.to_node(file.syntax()).kind() { |
85 | ast::PatKind::BindPat(pat) => { | 85 | ast::PatKind::BindPat(pat) => { |
86 | return NavigationTarget::from_bind_pat(file_id, &pat) | 86 | return NavigationTarget::from_bind_pat(file_id, &pat) |
87 | } | 87 | } |
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 7293ba359..163fa8c3c 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -4,6 +4,7 @@ use ra_syntax::{ | |||
4 | algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, | 4 | algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, |
5 | SyntaxKind::*, SyntaxToken, | 5 | SyntaxKind::*, SyntaxToken, |
6 | ast::{self, AstNode, AstToken}, | 6 | ast::{self, AstNode, AstToken}, |
7 | T | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | use crate::{FileRange, db::RootDatabase}; | 10 | use crate::{FileRange, db::RootDatabase}; |
@@ -135,7 +136,7 @@ fn pick_best<'a>(l: SyntaxToken<'a>, r: SyntaxToken<'a>) -> SyntaxToken<'a> { | |||
135 | fn priority(n: SyntaxToken) -> usize { | 136 | fn priority(n: SyntaxToken) -> usize { |
136 | match n.kind() { | 137 | match n.kind() { |
137 | WHITESPACE => 0, | 138 | WHITESPACE => 0, |
138 | IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2, | 139 | IDENT | T![self] | T![super] | T![crate] | LIFETIME => 2, |
139 | _ => 1, | 140 | _ => 1, |
140 | } | 141 | } |
141 | } | 142 | } |
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 9f655d83c..d5c2b08ca 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -86,7 +86,7 @@ pub(crate) fn find_all_refs( | |||
86 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); | 86 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); |
87 | let resolved = analyzer.resolve_local_name(name_ref)?; | 87 | let resolved = analyzer.resolve_local_name(name_ref)?; |
88 | if let Either::A(ptr) = resolved.ptr() { | 88 | if let Either::A(ptr) = resolved.ptr() { |
89 | if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file).kind() { | 89 | if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file.syntax()).kind() { |
90 | return Some((binding, analyzer)); | 90 | return Some((binding, analyzer)); |
91 | } | 91 | } |
92 | } | 92 | } |
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 970d699c0..697d1b794 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | #[macro_use] | 15 | #[macro_use] |
16 | mod token_set; | 16 | mod token_set; |
17 | #[macro_use] | ||
17 | mod syntax_kind; | 18 | mod syntax_kind; |
18 | mod event; | 19 | mod event; |
19 | mod parser; | 20 | mod parser; |
diff --git a/crates/ra_parser/src/syntax_kind.rs b/crates/ra_parser/src/syntax_kind.rs index a2353317f..00faa7799 100644 --- a/crates/ra_parser/src/syntax_kind.rs +++ b/crates/ra_parser/src/syntax_kind.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | #[macro_use] | ||
1 | mod generated; | 2 | mod generated; |
2 | 3 | ||
3 | use std::fmt; | 4 | use std::fmt; |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 6f984aea1..1a08cc6eb 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -241,6 +241,101 @@ pub enum SyntaxKind { | |||
241 | } | 241 | } |
242 | use self::SyntaxKind::*; | 242 | use self::SyntaxKind::*; |
243 | 243 | ||
244 | #[macro_export] | ||
245 | macro_rules! T { | ||
246 | (;) => { $crate::SyntaxKind::SEMI }; | ||
247 | (,) => { $crate::SyntaxKind::COMMA }; | ||
248 | (() => { $crate::SyntaxKind::L_PAREN }; | ||
249 | ()) => { $crate::SyntaxKind::R_PAREN }; | ||
250 | ('{') => { $crate::SyntaxKind::L_CURLY }; | ||
251 | ('}') => { $crate::SyntaxKind::R_CURLY }; | ||
252 | ('[') => { $crate::SyntaxKind::L_BRACK }; | ||
253 | (']') => { $crate::SyntaxKind::R_BRACK }; | ||
254 | (<) => { $crate::SyntaxKind::L_ANGLE }; | ||
255 | (>) => { $crate::SyntaxKind::R_ANGLE }; | ||
256 | (@) => { $crate::SyntaxKind::AT }; | ||
257 | (#) => { $crate::SyntaxKind::POUND }; | ||
258 | (~) => { $crate::SyntaxKind::TILDE }; | ||
259 | (?) => { $crate::SyntaxKind::QUESTION }; | ||
260 | ($) => { $crate::SyntaxKind::DOLLAR }; | ||
261 | (&) => { $crate::SyntaxKind::AMP }; | ||
262 | (|) => { $crate::SyntaxKind::PIPE }; | ||
263 | (+) => { $crate::SyntaxKind::PLUS }; | ||
264 | (*) => { $crate::SyntaxKind::STAR }; | ||
265 | (/) => { $crate::SyntaxKind::SLASH }; | ||
266 | (^) => { $crate::SyntaxKind::CARET }; | ||
267 | (%) => { $crate::SyntaxKind::PERCENT }; | ||
268 | (_) => { $crate::SyntaxKind::UNDERSCORE }; | ||
269 | (.) => { $crate::SyntaxKind::DOT }; | ||
270 | (..) => { $crate::SyntaxKind::DOTDOT }; | ||
271 | (...) => { $crate::SyntaxKind::DOTDOTDOT }; | ||
272 | (..=) => { $crate::SyntaxKind::DOTDOTEQ }; | ||
273 | (:) => { $crate::SyntaxKind::COLON }; | ||
274 | (::) => { $crate::SyntaxKind::COLONCOLON }; | ||
275 | (=) => { $crate::SyntaxKind::EQ }; | ||
276 | (==) => { $crate::SyntaxKind::EQEQ }; | ||
277 | (=>) => { $crate::SyntaxKind::FAT_ARROW }; | ||
278 | (!) => { $crate::SyntaxKind::EXCL }; | ||
279 | (!=) => { $crate::SyntaxKind::NEQ }; | ||
280 | (-) => { $crate::SyntaxKind::MINUS }; | ||
281 | (->) => { $crate::SyntaxKind::THIN_ARROW }; | ||
282 | (<=) => { $crate::SyntaxKind::LTEQ }; | ||
283 | (>=) => { $crate::SyntaxKind::GTEQ }; | ||
284 | (+=) => { $crate::SyntaxKind::PLUSEQ }; | ||
285 | (-=) => { $crate::SyntaxKind::MINUSEQ }; | ||
286 | (|=) => { $crate::SyntaxKind::PIPEEQ }; | ||
287 | (&=) => { $crate::SyntaxKind::AMPEQ }; | ||
288 | (^=) => { $crate::SyntaxKind::CARETEQ }; | ||
289 | (/=) => { $crate::SyntaxKind::SLASHEQ }; | ||
290 | (*=) => { $crate::SyntaxKind::STAREQ }; | ||
291 | (%=) => { $crate::SyntaxKind::PERCENTEQ }; | ||
292 | (&&) => { $crate::SyntaxKind::AMPAMP }; | ||
293 | (||) => { $crate::SyntaxKind::PIPEPIPE }; | ||
294 | (<<) => { $crate::SyntaxKind::SHL }; | ||
295 | (>>) => { $crate::SyntaxKind::SHR }; | ||
296 | (<<=) => { $crate::SyntaxKind::SHLEQ }; | ||
297 | (>>=) => { $crate::SyntaxKind::SHREQ }; | ||
298 | (async) => { $crate::SyntaxKind::ASYNC_KW }; | ||
299 | (use) => { $crate::SyntaxKind::USE_KW }; | ||
300 | (fn) => { $crate::SyntaxKind::FN_KW }; | ||
301 | (struct) => { $crate::SyntaxKind::STRUCT_KW }; | ||
302 | (enum) => { $crate::SyntaxKind::ENUM_KW }; | ||
303 | (trait) => { $crate::SyntaxKind::TRAIT_KW }; | ||
304 | (impl) => { $crate::SyntaxKind::IMPL_KW }; | ||
305 | (dyn) => { $crate::SyntaxKind::DYN_KW }; | ||
306 | (true) => { $crate::SyntaxKind::TRUE_KW }; | ||
307 | (false) => { $crate::SyntaxKind::FALSE_KW }; | ||
308 | (as) => { $crate::SyntaxKind::AS_KW }; | ||
309 | (extern) => { $crate::SyntaxKind::EXTERN_KW }; | ||
310 | (crate) => { $crate::SyntaxKind::CRATE_KW }; | ||
311 | (mod) => { $crate::SyntaxKind::MOD_KW }; | ||
312 | (pub) => { $crate::SyntaxKind::PUB_KW }; | ||
313 | (self) => { $crate::SyntaxKind::SELF_KW }; | ||
314 | (super) => { $crate::SyntaxKind::SUPER_KW }; | ||
315 | (in) => { $crate::SyntaxKind::IN_KW }; | ||
316 | (where) => { $crate::SyntaxKind::WHERE_KW }; | ||
317 | (for) => { $crate::SyntaxKind::FOR_KW }; | ||
318 | (loop) => { $crate::SyntaxKind::LOOP_KW }; | ||
319 | (while) => { $crate::SyntaxKind::WHILE_KW }; | ||
320 | (continue) => { $crate::SyntaxKind::CONTINUE_KW }; | ||
321 | (break) => { $crate::SyntaxKind::BREAK_KW }; | ||
322 | (if) => { $crate::SyntaxKind::IF_KW }; | ||
323 | (else) => { $crate::SyntaxKind::ELSE_KW }; | ||
324 | (match) => { $crate::SyntaxKind::MATCH_KW }; | ||
325 | (const) => { $crate::SyntaxKind::CONST_KW }; | ||
326 | (static) => { $crate::SyntaxKind::STATIC_KW }; | ||
327 | (mut) => { $crate::SyntaxKind::MUT_KW }; | ||
328 | (unsafe) => { $crate::SyntaxKind::UNSAFE_KW }; | ||
329 | (type) => { $crate::SyntaxKind::TYPE_KW }; | ||
330 | (ref) => { $crate::SyntaxKind::REF_KW }; | ||
331 | (let) => { $crate::SyntaxKind::LET_KW }; | ||
332 | (move) => { $crate::SyntaxKind::MOVE_KW }; | ||
333 | (return) => { $crate::SyntaxKind::RETURN_KW }; | ||
334 | (auto) => { $crate::SyntaxKind::AUTO_KW }; | ||
335 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; | ||
336 | (union) => { $crate::SyntaxKind::UNION_KW }; | ||
337 | } | ||
338 | |||
244 | impl From<u16> for SyntaxKind { | 339 | impl From<u16> for SyntaxKind { |
245 | fn from(d: u16) -> SyntaxKind { | 340 | fn from(d: u16) -> SyntaxKind { |
246 | assert!(d <= (__LAST as u16)); | 341 | assert!(d <= (__LAST as u16)); |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs.tera b/crates/ra_parser/src/syntax_kind/generated.rs.tera index 5b9ff21af..ccb8ca4ba 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs.tera +++ b/crates/ra_parser/src/syntax_kind/generated.rs.tera | |||
@@ -33,6 +33,20 @@ pub enum SyntaxKind { | |||
33 | } | 33 | } |
34 | use self::SyntaxKind::*; | 34 | use self::SyntaxKind::*; |
35 | 35 | ||
36 | #[macro_export] | ||
37 | macro_rules! T { | ||
38 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
39 | {%- if t.0 == '{' or t.0 == '}' or t.0 == '[' or t.0 == ']' %} | ||
40 | ('{{t.0}}') => { $crate::SyntaxKind::{{t.1}} }; | ||
41 | {%- else %} | ||
42 | ({{t.0}}) => { $crate::SyntaxKind::{{t.1}} }; | ||
43 | {%- endif %} | ||
44 | {%- endfor -%} | ||
45 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
46 | ({{kw}}) => { $crate::SyntaxKind::{{kw | upper}}_KW }; | ||
47 | {%- endfor %} | ||
48 | } | ||
49 | |||
36 | impl From<u16> for SyntaxKind { | 50 | impl From<u16> for SyntaxKind { |
37 | fn from(d: u16) -> SyntaxKind { | 51 | fn from(d: u16) -> SyntaxKind { |
38 | assert!(d <= (__LAST as u16)); | 52 | assert!(d <= (__LAST as u16)); |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 39c25dbdc..65c65d6aa 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -33,6 +33,7 @@ pub mod fuzz; | |||
33 | 33 | ||
34 | pub use rowan::{SmolStr, TextRange, TextUnit}; | 34 | pub use rowan::{SmolStr, TextRange, TextUnit}; |
35 | pub use ra_parser::SyntaxKind; | 35 | pub use ra_parser::SyntaxKind; |
36 | pub use ra_parser::T; | ||
36 | pub use crate::{ | 37 | pub use crate::{ |
37 | ast::AstNode, | 38 | ast::AstNode, |
38 | syntax_error::{SyntaxError, SyntaxErrorKind, Location}, | 39 | syntax_error::{SyntaxError, SyntaxErrorKind, Location}, |
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index b0816b135..cee9503ca 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -3,7 +3,7 @@ use std::{ | |||
3 | iter::successors, | 3 | iter::successors, |
4 | }; | 4 | }; |
5 | use crate::{ | 5 | use crate::{ |
6 | AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, | 6 | AstNode, SyntaxKind, SyntaxNode, TextRange, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | /// A pointer to a syntax node inside a file. It can be used to remember a | 9 | /// A pointer to a syntax node inside a file. It can be used to remember a |
@@ -19,8 +19,9 @@ impl SyntaxNodePtr { | |||
19 | SyntaxNodePtr { range: node.range(), kind: node.kind() } | 19 | SyntaxNodePtr { range: node.range(), kind: node.kind() } |
20 | } | 20 | } |
21 | 21 | ||
22 | pub fn to_node(self, source_file: &SourceFile) -> &SyntaxNode { | 22 | pub fn to_node(self, root: &SyntaxNode) -> &SyntaxNode { |
23 | successors(Some(source_file.syntax()), |&node| { | 23 | assert!(root.parent().is_none()); |
24 | successors(Some(root), |&node| { | ||
24 | node.children().find(|it| self.range.is_subrange(&it.range())) | 25 | node.children().find(|it| self.range.is_subrange(&it.range())) |
25 | }) | 26 | }) |
26 | .find(|it| it.range() == self.range && it.kind() == self.kind) | 27 | .find(|it| it.range() == self.range && it.kind() == self.kind) |
@@ -55,8 +56,8 @@ impl<N: AstNode> AstPtr<N> { | |||
55 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } | 56 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } |
56 | } | 57 | } |
57 | 58 | ||
58 | pub fn to_node(self, source_file: &SourceFile) -> &N { | 59 | pub fn to_node(self, root: &SyntaxNode) -> &N { |
59 | let syntax_node = self.raw.to_node(source_file); | 60 | let syntax_node = self.raw.to_node(root); |
60 | N::cast(syntax_node).unwrap() | 61 | N::cast(syntax_node).unwrap() |
61 | } | 62 | } |
62 | 63 | ||
@@ -73,11 +74,11 @@ impl<N: AstNode> From<AstPtr<N>> for SyntaxNodePtr { | |||
73 | 74 | ||
74 | #[test] | 75 | #[test] |
75 | fn test_local_syntax_ptr() { | 76 | fn test_local_syntax_ptr() { |
76 | use crate::{ast, AstNode}; | 77 | use crate::{ast, AstNode, SourceFile}; |
77 | 78 | ||
78 | let file = SourceFile::parse("struct Foo { f: u32, }"); | 79 | let file = SourceFile::parse("struct Foo { f: u32, }"); |
79 | let field = file.syntax().descendants().find_map(ast::NamedFieldDef::cast).unwrap(); | 80 | let field = file.syntax().descendants().find_map(ast::NamedFieldDef::cast).unwrap(); |
80 | let ptr = SyntaxNodePtr::new(field.syntax()); | 81 | let ptr = SyntaxNodePtr::new(field.syntax()); |
81 | let field_syntax = ptr.to_node(&file); | 82 | let field_syntax = ptr.to_node(file.syntax()); |
82 | assert_eq!(field.syntax(), &*field_syntax); | 83 | assert_eq!(field.syntax(), &*field_syntax); |
83 | } | 84 | } |
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 92c15234e..80054f529 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs | |||
@@ -392,7 +392,7 @@ impl SyntaxNode { | |||
392 | // `range` private afterwards | 392 | // `range` private afterwards |
393 | let mut ptr = SyntaxNodePtr::new(self); | 393 | let mut ptr = SyntaxNodePtr::new(self); |
394 | ptr.range = TextRange::offset_len(ptr.range().start(), len); | 394 | ptr.range = TextRange::offset_len(ptr.range().start(), len); |
395 | return ptr.to_node(&file).to_owned(); | 395 | return ptr.to_node(file.syntax()).to_owned(); |
396 | } | 396 | } |
397 | 397 | ||
398 | fn position_of_child(&self, child: SyntaxElement) -> usize { | 398 | fn position_of_child(&self, child: SyntaxElement) -> usize { |