aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-11 06:56:13 +0100
committerAleksey Kladov <[email protected]>2018-08-11 06:56:13 +0100
commit35b59bb43877c496fbaf98520b3b52ff9a6518b1 (patch)
tree9d8a1d0ad251101c9107968bfb0ea17f34ef869c
parentf99551f46b1583ed43751e4d26fe76a0b913eb5f (diff)
simplify
-rw-r--r--crates/cli/src/main.rs8
-rw-r--r--crates/libeditor/src/lib.rs7
-rw-r--r--crates/libeditor/tests/test.rs6
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::{
10}; 10};
11use clap::{App, Arg, SubCommand}; 11use clap::{App, Arg, SubCommand};
12use tools::collect_tests; 12use tools::collect_tests;
13use libeditor::{ast, syntax_tree, symbols}; 13use libeditor::{File, syntax_tree, symbols};
14 14
15type Result<T> = ::std::result::Result<T, failure::Error>; 15type Result<T> = ::std::result::Result<T, failure::Error>;
16 16
@@ -68,9 +68,9 @@ fn main() -> Result<()> {
68 Ok(()) 68 Ok(())
69} 69}
70 70
71fn file() -> Result<ast::File> { 71fn file() -> Result<File> {
72 let text = read_stdin()?; 72 let text = read_stdin()?;
73 Ok(ast::File::parse(&text)) 73 Ok(libeditor::parse(&text))
74} 74}
75 75
76fn read_stdin() -> Result<String> { 76fn read_stdin() -> Result<String> {
@@ -89,7 +89,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
89 None => bail!("No test found at line {} at {}", line, file.display()), 89 None => bail!("No test found at line {} at {}", line, file.display()),
90 Some((_start_line, test)) => test, 90 Some((_start_line, test)) => test,
91 }; 91 };
92 let file = ast::File::parse(&test.text); 92 let file = libeditor::parse(&test.text);
93 let tree = syntax_tree(&file); 93 let tree = syntax_tree(&file);
94 Ok((test.text, tree)) 94 Ok((test.text, tree))
95} 95}
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;
5mod line_index; 5mod line_index;
6 6
7use libsyntax2::{ 7use libsyntax2::{
8 ast,
8 SyntaxNodeRef, AstNode, 9 SyntaxNodeRef, AstNode,
9 algo::walk, 10 algo::walk,
10 SyntaxKind::*, 11 SyntaxKind::*,
11}; 12};
12pub use libsyntax2::{TextRange, TextUnit, ast}; 13pub use libsyntax2::{File, TextRange, TextUnit};
13pub use self::line_index::{LineIndex, LineCol}; 14pub use self::line_index::{LineIndex, LineCol};
14 15
15#[derive(Debug)] 16#[derive(Debug)]
@@ -43,6 +44,10 @@ pub enum RunnableKind {
43 Bin, 44 Bin,
44} 45}
45 46
47pub fn parse(text: &str) -> ast::File {
48 ast::File::parse(text)
49}
50
46pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> { 51pub fn highlight(file: &ast::File) -> Vec<HighlightedRange> {
47 let syntax = file.syntax(); 52 let syntax = file.syntax();
48 let mut res = Vec::new(); 53 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;
3 3
4use std::fmt; 4use std::fmt;
5use itertools::Itertools; 5use itertools::Itertools;
6use libeditor::{ast, highlight, runnables, extend_selection, TextRange}; 6use libeditor::{File, highlight, runnables, extend_selection, TextRange};
7 7
8#[test] 8#[test]
9fn test_extend_selection() { 9fn test_extend_selection() {
@@ -58,8 +58,8 @@ fn test_foo() {}
58 ) 58 )
59} 59}
60 60
61fn file(text: &str) -> ast::File { 61fn file(text: &str) -> File {
62 ast::File::parse(text) 62 File::parse(text)
63} 63}
64 64
65fn dbg_eq(actual: &impl fmt::Debug, expected: &str) { 65fn dbg_eq(actual: &impl fmt::Debug, expected: &str) {