aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-16 10:51:40 +0100
committerAleksey Kladov <[email protected]>2018-08-16 10:51:40 +0100
commit7094291573dc819e3115950ec3b2316bd5e9ea33 (patch)
treebe18ef6c5baab68acac484d00277125484d15820 /crates/libeditor/src
parent1193c5f829dc96683132c12d5395d7805787af2a (diff)
tt-attrs
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r--crates/libeditor/src/code_actions.rs2
-rw-r--r--crates/libeditor/src/lib.rs15
-rw-r--r--crates/libeditor/src/symbols.rs6
3 files changed, 10 insertions, 13 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs
index 88c348436..4987964d2 100644
--- a/crates/libeditor/src/code_actions.rs
+++ b/crates/libeditor/src/code_actions.rs
@@ -66,7 +66,7 @@ fn find_non_trivia_leaf(syntax: SyntaxNodeRef, offset: TextUnit) -> Option<Synta
66 .find(|leaf| !leaf.kind().is_trivia()) 66 .find(|leaf| !leaf.kind().is_trivia())
67} 67}
68 68
69fn find_node<'a, N: AstNode<&'a SyntaxRoot>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> { 69pub fn find_node<'a, N: AstNode<&'a SyntaxRoot>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> {
70 let leaf = find_non_trivia_leaf(syntax, offset)?; 70 let leaf = find_non_trivia_leaf(syntax, offset)?;
71 ancestors(leaf) 71 ancestors(leaf)
72 .filter_map(N::cast) 72 .filter_map(N::cast)
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
77pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { 78pub 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
101pub fn diagnostics(file: &ast::File) -> Vec<Diagnostic> { 101pub 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(),
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs
index 6f8853770..2585d9579 100644
--- a/crates/libeditor/src/symbols.rs
+++ b/crates/libeditor/src/symbols.rs
@@ -26,8 +26,7 @@ pub struct FileSymbol {
26} 26}
27 27
28pub fn file_symbols(file: &ast::File) -> Vec<FileSymbol> { 28pub fn file_symbols(file: &ast::File) -> Vec<FileSymbol> {
29 let syntax = file.syntax(); 29 preorder(file.syntax_ref())
30 preorder(syntax.as_ref())
31 .filter_map(to_symbol) 30 .filter_map(to_symbol)
32 .collect() 31 .collect()
33} 32}
@@ -57,9 +56,8 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
57pub fn file_structure(file: &ast::File) -> Vec<StructureNode> { 56pub fn file_structure(file: &ast::File) -> Vec<StructureNode> {
58 let mut res = Vec::new(); 57 let mut res = Vec::new();
59 let mut stack = Vec::new(); 58 let mut stack = Vec::new();
60 let syntax = file.syntax();
61 59
62 for event in walk(syntax.as_ref()) { 60 for event in walk(file.syntax_ref()) {
63 match event { 61 match event {
64 WalkEvent::Enter(node) => { 62 WalkEvent::Enter(node) => {
65 match structure_node(node) { 63 match structure_node(node) {