From a450142aca947b9364e498897f522f854f19781d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 26 Aug 2018 09:12:18 +0300 Subject: fix stray curly --- crates/libeditor/src/lib.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'crates/libeditor/src/lib.rs') diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index 55302265f..60489f7e3 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs @@ -8,11 +8,12 @@ mod line_index; mod edit; mod code_actions; mod typing; +mod completion; use libsyntax2::{ - File, TextUnit, TextRange, + File, TextUnit, TextRange, SyntaxNodeRef, ast::{AstNode, NameOwner}, - algo::{walk, find_leaf_at_offset}, + algo::{walk, find_leaf_at_offset, ancestors}, SyntaxKind::{self, *}, }; pub use libsyntax2::AtomEdit; @@ -22,10 +23,11 @@ pub use self::{ symbols::{StructureNode, file_structure, FileSymbol, file_symbols}, edit::{EditBuilder, Edit}, code_actions::{ - ActionResult, find_node, + ActionResult, flip_comma, add_derive, add_impl, }, typing::join_lines, + completion::scope_completion, }; #[derive(Debug)] @@ -138,3 +140,16 @@ pub fn runnables(file: &File) -> Vec { }) .collect() } + +pub fn find_node_at_offset<'a, N: AstNode<'a>>( + syntax: SyntaxNodeRef<'a>, + offset: TextUnit, +) -> Option { + let leaves = find_leaf_at_offset(syntax, offset); + let leaf = leaves.clone() + .find(|leaf| !leaf.kind().is_trivia()) + .or_else(|| leaves.right_biased())?; + ancestors(leaf) + .filter_map(N::cast) + .next() +} -- cgit v1.2.3