diff options
Diffstat (limited to 'crates/libeditor/src/lib.rs')
-rw-r--r-- | crates/libeditor/src/lib.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index 28da457d1..76cb4d028 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs | |||
@@ -21,7 +21,10 @@ pub use self::{ | |||
21 | extend_selection::extend_selection, | 21 | extend_selection::extend_selection, |
22 | symbols::{StructureNode, file_structure, FileSymbol, file_symbols}, | 22 | symbols::{StructureNode, file_structure, FileSymbol, file_symbols}, |
23 | edit::{EditBuilder, Edit, AtomEdit}, | 23 | edit::{EditBuilder, Edit, AtomEdit}, |
24 | code_actions::{flip_comma, add_derive, ActionResult, CursorPosition}, | 24 | code_actions::{ |
25 | ActionResult, CursorPosition, find_node, | ||
26 | flip_comma, add_derive, | ||
27 | }, | ||
25 | }; | 28 | }; |
26 | 29 | ||
27 | #[derive(Debug)] | 30 | #[derive(Debug)] |
@@ -59,9 +62,7 @@ pub fn matching_brace(file: &ast::File, offset: TextUnit) -> Option<TextUnit> { | |||
59 | L_PAREN, R_PAREN, | 62 | L_PAREN, R_PAREN, |
60 | L_ANGLE, R_ANGLE, | 63 | L_ANGLE, R_ANGLE, |
61 | ]; | 64 | ]; |
62 | let syntax = file.syntax(); | 65 | let (brace_node, brace_idx) = find_leaf_at_offset(file.syntax_ref(), offset) |
63 | let syntax = syntax.as_ref(); | ||
64 | let (brace_node, brace_idx) = find_leaf_at_offset(syntax, offset) | ||
65 | .filter_map(|node| { | 66 | .filter_map(|node| { |
66 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; | 67 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; |
67 | Some((node, idx)) | 68 | Some((node, idx)) |
@@ -75,9 +76,8 @@ pub fn matching_brace(file: &ast::File, offset: TextUnit) -> Option<TextUnit> { | |||
75 | } | 76 | } |
76 | 77 | ||
77 | pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { | 78 | pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { |
78 | let syntax = file.syntax(); | ||
79 | let mut res = Vec::new(); | 79 | let mut res = Vec::new(); |
80 | for node in walk::preorder(syntax.as_ref()) { | 80 | for node in walk::preorder(file.syntax_ref()) { |
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", |
@@ -99,10 +99,9 @@ pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { | |||
99 | } | 99 | } |
100 | 100 | ||
101 | pub fn diagnostics(file: &ast::File) -> Vec<Diagnostic> { | 101 | pub fn diagnostics(file: &ast::File) -> Vec<Diagnostic> { |
102 | let syntax = file.syntax(); | ||
103 | let mut res = Vec::new(); | 102 | let mut res = Vec::new(); |
104 | 103 | ||
105 | for node in walk::preorder(syntax.as_ref()) { | 104 | for node in walk::preorder(file.syntax_ref()) { |
106 | if node.kind() == ERROR { | 105 | if node.kind() == ERROR { |
107 | res.push(Diagnostic { | 106 | res.push(Diagnostic { |
108 | range: node.range(), | 107 | range: node.range(), |