From 35b59bb43877c496fbaf98520b3b52ff9a6518b1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 08:56:13 +0300 Subject: simplify --- crates/cli/src/main.rs | 8 ++++---- crates/libeditor/src/lib.rs | 7 ++++++- crates/libeditor/tests/test.rs | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 45e0a1e4f..863aeb99d 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -10,7 +10,7 @@ use std::{ }; use clap::{App, Arg, SubCommand}; use tools::collect_tests; -use libeditor::{ast, syntax_tree, symbols}; +use libeditor::{File, syntax_tree, symbols}; type Result = ::std::result::Result; @@ -68,9 +68,9 @@ fn main() -> Result<()> { Ok(()) } -fn file() -> Result { +fn file() -> Result { let text = read_stdin()?; - Ok(ast::File::parse(&text)) + Ok(libeditor::parse(&text)) } fn read_stdin() -> Result { @@ -89,7 +89,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { None => bail!("No test found at line {} at {}", line, file.display()), Some((_start_line, test)) => test, }; - let file = ast::File::parse(&test.text); + let file = libeditor::parse(&test.text); let tree = syntax_tree(&file); Ok((test.text, tree)) } diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index f77647338..c762a8b0b 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs @@ -5,11 +5,12 @@ mod extend_selection; mod line_index; use libsyntax2::{ + ast, SyntaxNodeRef, AstNode, algo::walk, SyntaxKind::*, }; -pub use libsyntax2::{TextRange, TextUnit, ast}; +pub use libsyntax2::{File, TextRange, TextUnit}; pub use self::line_index::{LineIndex, LineCol}; #[derive(Debug)] @@ -43,6 +44,10 @@ pub enum RunnableKind { Bin, } +pub fn parse(text: &str) -> ast::File { + ast::File::parse(text) +} + pub fn highlight(file: &ast::File) -> Vec { let syntax = file.syntax(); let mut res = Vec::new(); diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index 2a84c5080..d617f4b99 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs @@ -3,7 +3,7 @@ extern crate itertools; use std::fmt; use itertools::Itertools; -use libeditor::{ast, highlight, runnables, extend_selection, TextRange}; +use libeditor::{File, highlight, runnables, extend_selection, TextRange}; #[test] fn test_extend_selection() { @@ -58,8 +58,8 @@ fn test_foo() {} ) } -fn file(text: &str) -> ast::File { - ast::File::parse(text) +fn file(text: &str) -> File { + File::parse(text) } fn dbg_eq(actual: &impl fmt::Debug, expected: &str) { -- cgit v1.2.3