diff options
author | Aleksey Kladov <[email protected]> | 2018-08-25 09:40:17 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-25 09:40:17 +0100 |
commit | 9fae494a8da347a32cdcd3dcd714ba00aaff9664 (patch) | |
tree | 9fe4fb51c374d036e22d5a60ce50b63dbe287142 /crates | |
parent | f104458d45e30024f8a4a02c1ad4101ed74b08f9 (diff) |
Move ParsedFile to top
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/libanalysis/src/module_map.rs | 3 | ||||
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 3 | ||||
-rw-r--r-- | crates/libeditor/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/libeditor/src/typing.rs | 4 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 25 | ||||
-rw-r--r-- | crates/libsyntax2/src/lib.rs | 23 |
7 files changed, 39 insertions, 39 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index fee0d10d6..a0f17a689 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -27,8 +27,9 @@ use std::{ | |||
27 | }; | 27 | }; |
28 | 28 | ||
29 | use libsyntax2::{ | 29 | use libsyntax2::{ |
30 | ParsedFile, | ||
30 | TextUnit, TextRange, SmolStr, | 31 | TextUnit, TextRange, SmolStr, |
31 | ast::{self, AstNode, NameOwner, ParsedFile}, | 32 | ast::{self, AstNode, NameOwner}, |
32 | SyntaxKind::*, | 33 | SyntaxKind::*, |
33 | }; | 34 | }; |
34 | use libeditor::{LineIndex, FileSymbol, find_node}; | 35 | use libeditor::{LineIndex, FileSymbol, find_node}; |
diff --git a/crates/libanalysis/src/module_map.rs b/crates/libanalysis/src/module_map.rs index 83e6e57f7..e8d32928a 100644 --- a/crates/libanalysis/src/module_map.rs +++ b/crates/libanalysis/src/module_map.rs | |||
@@ -4,7 +4,8 @@ use std::{ | |||
4 | 4 | ||
5 | use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; | 5 | use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; |
6 | use libsyntax2::{ | 6 | use libsyntax2::{ |
7 | ast::{self, AstNode, NameOwner, ParsedFile}, | 7 | ParsedFile, |
8 | ast::{self, AstNode, NameOwner}, | ||
8 | SyntaxNode, SmolStr, | 9 | SyntaxNode, SmolStr, |
9 | }; | 10 | }; |
10 | use {FileId, FileResolver}; | 11 | use {FileId, FileResolver}; |
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index c25ee973c..c7c043b39 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -3,7 +3,8 @@ use std::{ | |||
3 | }; | 3 | }; |
4 | 4 | ||
5 | use libsyntax2::{ | 5 | use libsyntax2::{ |
6 | ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner, ParsedFile}, | 6 | ParsedFile, |
7 | ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, | ||
7 | SyntaxKind::COMMA, | 8 | SyntaxKind::COMMA, |
8 | SyntaxNodeRef, | 9 | SyntaxNodeRef, |
9 | algo::{ | 10 | algo::{ |
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index b29603da3..b2d1dab58 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs | |||
@@ -10,8 +10,7 @@ mod code_actions; | |||
10 | mod typing; | 10 | mod typing; |
11 | 11 | ||
12 | use libsyntax2::{ | 12 | use libsyntax2::{ |
13 | ast::{self, NameOwner}, | 13 | ast::{self, AstNode, NameOwner}, |
14 | AstNode, | ||
15 | algo::{walk, find_leaf_at_offset}, | 14 | algo::{walk, find_leaf_at_offset}, |
16 | SyntaxKind::{self, *}, | 15 | SyntaxKind::{self, *}, |
17 | }; | 16 | }; |
@@ -52,11 +51,11 @@ pub enum RunnableKind { | |||
52 | Bin, | 51 | Bin, |
53 | } | 52 | } |
54 | 53 | ||
55 | pub fn parse(text: &str) -> ast::ParsedFile { | 54 | pub fn parse(text: &str) -> ParsedFile { |
56 | ast::ParsedFile::parse(text) | 55 | ParsedFile::parse(text) |
57 | } | 56 | } |
58 | 57 | ||
59 | pub fn matching_brace(file: &ast::ParsedFile, offset: TextUnit) -> Option<TextUnit> { | 58 | pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> { |
60 | const BRACES: &[SyntaxKind] = &[ | 59 | const BRACES: &[SyntaxKind] = &[ |
61 | L_CURLY, R_CURLY, | 60 | L_CURLY, R_CURLY, |
62 | L_BRACK, R_BRACK, | 61 | L_BRACK, R_BRACK, |
@@ -76,7 +75,7 @@ pub fn matching_brace(file: &ast::ParsedFile, offset: TextUnit) -> Option<TextUn | |||
76 | Some(matching_node.range().start()) | 75 | Some(matching_node.range().start()) |
77 | } | 76 | } |
78 | 77 | ||
79 | pub fn highlight(file: &ast::ParsedFile) -> Vec<HighlightedRange> { | 78 | pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> { |
80 | let mut res = Vec::new(); | 79 | let mut res = Vec::new(); |
81 | for node in walk::preorder(file.syntax()) { | 80 | for node in walk::preorder(file.syntax()) { |
82 | let tag = match node.kind() { | 81 | let tag = match node.kind() { |
@@ -99,7 +98,7 @@ pub fn highlight(file: &ast::ParsedFile) -> Vec<HighlightedRange> { | |||
99 | res | 98 | res |
100 | } | 99 | } |
101 | 100 | ||
102 | pub fn diagnostics(file: &ast::ParsedFile) -> Vec<Diagnostic> { | 101 | pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> { |
103 | let mut res = Vec::new(); | 102 | let mut res = Vec::new(); |
104 | 103 | ||
105 | for node in walk::preorder(file.syntax()) { | 104 | for node in walk::preorder(file.syntax()) { |
@@ -117,11 +116,11 @@ pub fn diagnostics(file: &ast::ParsedFile) -> Vec<Diagnostic> { | |||
117 | res | 116 | res |
118 | } | 117 | } |
119 | 118 | ||
120 | pub fn syntax_tree(file: &ast::ParsedFile) -> String { | 119 | pub fn syntax_tree(file: &ParsedFile) -> String { |
121 | ::libsyntax2::utils::dump_tree(file.syntax()) | 120 | ::libsyntax2::utils::dump_tree(file.syntax()) |
122 | } | 121 | } |
123 | 122 | ||
124 | pub fn runnables(file: &ast::ParsedFile) -> Vec<Runnable> { | 123 | pub fn runnables(file: &ParsedFile) -> Vec<Runnable> { |
125 | file.ast() | 124 | file.ast() |
126 | .functions() | 125 | .functions() |
127 | .filter_map(|f| { | 126 | .filter_map(|f| { |
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index cc0d3d272..8903af177 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use libsyntax2::{ | 1 | use libsyntax2::{ |
2 | TextUnit, TextRange, SyntaxNodeRef, | 2 | TextUnit, TextRange, SyntaxNodeRef, ParsedFile, |
3 | ast, | 3 | ast, |
4 | algo::{ | 4 | algo::{ |
5 | walk::preorder, | 5 | walk::preorder, |
@@ -11,7 +11,7 @@ use libsyntax2::{ | |||
11 | 11 | ||
12 | use {ActionResult, EditBuilder}; | 12 | use {ActionResult, EditBuilder}; |
13 | 13 | ||
14 | pub fn join_lines(file: &ast::ParsedFile, range: TextRange) -> ActionResult { | 14 | pub fn join_lines(file: &ParsedFile, range: TextRange) -> ActionResult { |
15 | let range = if range.is_empty() { | 15 | let range = if range.is_empty() { |
16 | let text = file.syntax().text(); | 16 | let text = file.syntax().text(); |
17 | let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; | 17 | let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; |
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index ba80fc64e..6217c5b74 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -4,8 +4,7 @@ use itertools::Itertools; | |||
4 | use smol_str::SmolStr; | 4 | use smol_str::SmolStr; |
5 | 5 | ||
6 | use { | 6 | use { |
7 | SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError, | 7 | SyntaxNodeRef, SyntaxKind::*, |
8 | SyntaxKind::*, | ||
9 | }; | 8 | }; |
10 | pub use self::generated::*; | 9 | pub use self::generated::*; |
11 | 10 | ||
@@ -37,28 +36,6 @@ pub trait AttrsOwner<'a>: AstNode<'a> { | |||
37 | } | 36 | } |
38 | } | 37 | } |
39 | 38 | ||
40 | #[derive(Clone, Debug)] | ||
41 | pub struct ParsedFile { | ||
42 | root: SyntaxNode | ||
43 | } | ||
44 | |||
45 | impl ParsedFile { | ||
46 | pub fn parse(text: &str) -> Self { | ||
47 | let root = ::parse(text); | ||
48 | ParsedFile { root } | ||
49 | } | ||
50 | pub fn ast(&self) -> File { | ||
51 | File::cast(self.syntax()).unwrap() | ||
52 | } | ||
53 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
54 | self.root.borrowed() | ||
55 | } | ||
56 | pub fn errors(&self) -> Vec<SyntaxError> { | ||
57 | self.syntax().root.syntax_root().errors.clone() | ||
58 | } | ||
59 | |||
60 | } | ||
61 | |||
62 | impl<'a> FnDef<'a> { | 39 | impl<'a> FnDef<'a> { |
63 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 40 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
64 | self.attrs() | 41 | self.attrs() |
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index 9f9f3ab3a..b3efe2a18 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs | |||
@@ -44,12 +44,33 @@ pub mod text_utils; | |||
44 | pub use { | 44 | pub use { |
45 | text_unit::{TextRange, TextUnit}, | 45 | text_unit::{TextRange, TextUnit}, |
46 | smol_str::SmolStr, | 46 | smol_str::SmolStr, |
47 | ast::{AstNode, ParsedFile}, | 47 | ast::AstNode, |
48 | lexer::{tokenize, Token}, | 48 | lexer::{tokenize, Token}, |
49 | syntax_kinds::SyntaxKind, | 49 | syntax_kinds::SyntaxKind, |
50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, | 50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #[derive(Clone, Debug)] | ||
54 | pub struct ParsedFile { | ||
55 | root: SyntaxNode | ||
56 | } | ||
57 | |||
58 | impl ParsedFile { | ||
59 | pub fn parse(text: &str) -> Self { | ||
60 | let root = ::parse(text); | ||
61 | ParsedFile { root } | ||
62 | } | ||
63 | pub fn ast(&self) -> ast::File { | ||
64 | ast::File::cast(self.syntax()).unwrap() | ||
65 | } | ||
66 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
67 | self.root.borrowed() | ||
68 | } | ||
69 | pub fn errors(&self) -> Vec<SyntaxError> { | ||
70 | self.syntax().root.syntax_root().errors.clone() | ||
71 | } | ||
72 | |||
73 | } | ||
53 | 74 | ||
54 | pub fn parse(text: &str) -> SyntaxNode { | 75 | pub fn parse(text: &str) -> SyntaxNode { |
55 | let tokens = tokenize(&text); | 76 | let tokens = tokenize(&text); |