aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-17 20:00:13 +0100
committerAleksey Kladov <[email protected]>2018-08-17 20:00:13 +0100
commitd3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 (patch)
tree6d2388eb68605331a0dd090269372bc98dd038cd /crates/libeditor/src/lib.rs
parent70097504f78c4c41368a0b864a94df95fb9c27f7 (diff)
Borrowed AST
Diffstat (limited to 'crates/libeditor/src/lib.rs')
-rw-r--r--crates/libeditor/src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs
index 76cb4d028..d9d0369f6 100644
--- a/crates/libeditor/src/lib.rs
+++ b/crates/libeditor/src/lib.rs
@@ -15,7 +15,7 @@ use libsyntax2::{
15 algo::{walk, find_leaf_at_offset}, 15 algo::{walk, find_leaf_at_offset},
16 SyntaxKind::{self, *}, 16 SyntaxKind::{self, *},
17}; 17};
18pub use libsyntax2::{File, TextRange, TextUnit}; 18pub use libsyntax2::{ParsedFile, TextRange, TextUnit};
19pub use self::{ 19pub use self::{
20 line_index::{LineIndex, LineCol}, 20 line_index::{LineIndex, LineCol},
21 extend_selection::extend_selection, 21 extend_selection::extend_selection,
@@ -51,18 +51,18 @@ pub enum RunnableKind {
51 Bin, 51 Bin,
52} 52}
53 53
54pub fn parse(text: &str) -> ast::File { 54pub fn parse(text: &str) -> ast::ParsedFile {
55 ast::File::parse(text) 55 ast::ParsedFile::parse(text)
56} 56}
57 57
58pub fn matching_brace(file: &ast::File, offset: TextUnit) -> Option<TextUnit> { 58pub fn matching_brace(file: &ast::ParsedFile, offset: TextUnit) -> Option<TextUnit> {
59 const BRACES: &[SyntaxKind] = &[ 59 const BRACES: &[SyntaxKind] = &[
60 L_CURLY, R_CURLY, 60 L_CURLY, R_CURLY,
61 L_BRACK, R_BRACK, 61 L_BRACK, R_BRACK,
62 L_PAREN, R_PAREN, 62 L_PAREN, R_PAREN,
63 L_ANGLE, R_ANGLE, 63 L_ANGLE, R_ANGLE,
64 ]; 64 ];
65 let (brace_node, brace_idx) = find_leaf_at_offset(file.syntax_ref(), offset) 65 let (brace_node, brace_idx) = find_leaf_at_offset(file.syntax(), offset)
66 .filter_map(|node| { 66 .filter_map(|node| {
67 let idx = BRACES.iter().position(|&brace| brace == node.kind())?; 67 let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
68 Some((node, idx)) 68 Some((node, idx))
@@ -75,9 +75,9 @@ pub fn matching_brace(file: &ast::File, offset: TextUnit) -> Option<TextUnit> {
75 Some(matching_node.range().start()) 75 Some(matching_node.range().start())
76} 76}
77 77
78pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { 78pub fn highlight(file: &ast::ParsedFile) -> Vec<HighlightedRange> {
79 let mut res = Vec::new(); 79 let mut res = Vec::new();
80 for node in walk::preorder(file.syntax_ref()) { 80 for node in walk::preorder(file.syntax()) {
81 let tag = match node.kind() { 81 let tag = match node.kind() {
82 ERROR => "error", 82 ERROR => "error",
83 COMMENT | DOC_COMMENT => "comment", 83 COMMENT | DOC_COMMENT => "comment",
@@ -98,10 +98,10 @@ pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> {
98 res 98 res
99} 99}
100 100
101pub fn diagnostics(file: &ast::File) -> Vec<Diagnostic> { 101pub fn diagnostics(file: &ast::ParsedFile) -> Vec<Diagnostic> {
102 let mut res = Vec::new(); 102 let mut res = Vec::new();
103 103
104 for node in walk::preorder(file.syntax_ref()) { 104 for node in walk::preorder(file.syntax()) {
105 if node.kind() == ERROR { 105 if node.kind() == ERROR {
106 res.push(Diagnostic { 106 res.push(Diagnostic {
107 range: node.range(), 107 range: node.range(),
@@ -116,12 +116,12 @@ pub fn diagnostics(file: &ast::File) -> Vec<Diagnostic> {
116 res 116 res
117} 117}
118 118
119pub fn syntax_tree(file: &ast::File) -> String { 119pub fn syntax_tree(file: &ast::ParsedFile) -> String {
120 ::libsyntax2::utils::dump_tree(&file.syntax()) 120 ::libsyntax2::utils::dump_tree(file.syntax())
121} 121}
122 122
123pub fn runnables(file: &ast::File) -> Vec<Runnable> { 123pub fn runnables(file: &ast::ParsedFile) -> Vec<Runnable> {
124 file 124 file.ast()
125 .functions() 125 .functions()
126 .filter_map(|f| { 126 .filter_map(|f| {
127 let name = f.name()?.text(); 127 let name = f.name()?.text();