aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/cli/src/main.rs4
-rw-r--r--crates/libanalysis/src/lib.rs14
-rw-r--r--crates/libanalysis/src/module_map.rs4
-rw-r--r--crates/libanalysis/src/symbol_index.rs4
-rw-r--r--crates/libeditor/src/code_actions.rs8
-rw-r--r--crates/libeditor/src/extend_selection.rs4
-rw-r--r--crates/libeditor/src/lib.rs16
-rw-r--r--crates/libeditor/src/symbols.rs6
-rw-r--r--crates/libeditor/src/typing.rs4
-rw-r--r--crates/libeditor/tests/test.rs8
-rw-r--r--crates/libsyntax2/src/lib.rs6
11 files changed, 39 insertions, 39 deletions
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index e8e2ce7ee..fc28691fc 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::{ParsedFile, syntax_tree, file_structure}; 13use libeditor::{File, syntax_tree, file_structure};
14 14
15type Result<T> = ::std::result::Result<T, failure::Error>; 15type Result<T> = ::std::result::Result<T, failure::Error>;
16 16
@@ -68,7 +68,7 @@ fn main() -> Result<()> {
68 Ok(()) 68 Ok(())
69} 69}
70 70
71fn file() -> Result<ParsedFile> { 71fn file() -> Result<File> {
72 let text = read_stdin()?; 72 let text = read_stdin()?;
73 Ok(libeditor::parse(&text)) 73 Ok(libeditor::parse(&text))
74} 74}
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index a0f17a689..c84ab6077 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -27,7 +27,7 @@ use std::{
27}; 27};
28 28
29use libsyntax2::{ 29use libsyntax2::{
30 ParsedFile, 30 File,
31 TextUnit, TextRange, SmolStr, 31 TextUnit, TextRange, SmolStr,
32 ast::{self, AstNode, NameOwner}, 32 ast::{self, AstNode, NameOwner},
33 SyntaxKind::*, 33 SyntaxKind::*,
@@ -132,7 +132,7 @@ impl WorldState {
132 132
133 133
134impl World { 134impl World {
135 pub fn file_syntax(&self, file_id: FileId) -> Result<ParsedFile> { 135 pub fn file_syntax(&self, file_id: FileId) -> Result<File> {
136 let data = self.file_data(file_id)?; 136 let data = self.file_data(file_id)?;
137 Ok(data.syntax().clone()) 137 Ok(data.syntax().clone())
138 } 138 }
@@ -265,7 +265,7 @@ struct WorldData {
265struct FileData { 265struct FileData {
266 text: String, 266 text: String,
267 symbols: OnceCell<FileSymbols>, 267 symbols: OnceCell<FileSymbols>,
268 syntax: OnceCell<ParsedFile>, 268 syntax: OnceCell<File>,
269 lines: OnceCell<LineIndex>, 269 lines: OnceCell<LineIndex>,
270} 270}
271 271
@@ -279,14 +279,14 @@ impl FileData {
279 } 279 }
280 } 280 }
281 281
282 fn syntax(&self) -> &ParsedFile { 282 fn syntax(&self) -> &File {
283 self.syntax 283 self.syntax
284 .get_or_init(|| ParsedFile::parse(&self.text)) 284 .get_or_init(|| File::parse(&self.text))
285 } 285 }
286 286
287 fn syntax_transient(&self) -> ParsedFile { 287 fn syntax_transient(&self) -> File {
288 self.syntax.get().map(|s| s.clone()) 288 self.syntax.get().map(|s| s.clone())
289 .unwrap_or_else(|| ParsedFile::parse(&self.text)) 289 .unwrap_or_else(|| File::parse(&self.text))
290 } 290 }
291 291
292 fn symbols(&self) -> &FileSymbols { 292 fn symbols(&self) -> &FileSymbols {
diff --git a/crates/libanalysis/src/module_map.rs b/crates/libanalysis/src/module_map.rs
index e8d32928a..6a9104d84 100644
--- a/crates/libanalysis/src/module_map.rs
+++ b/crates/libanalysis/src/module_map.rs
@@ -4,13 +4,13 @@ use std::{
4 4
5use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; 5use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
6use libsyntax2::{ 6use libsyntax2::{
7 ParsedFile, 7 File,
8 ast::{self, AstNode, NameOwner}, 8 ast::{self, AstNode, NameOwner},
9 SyntaxNode, SmolStr, 9 SyntaxNode, SmolStr,
10}; 10};
11use {FileId, FileResolver}; 11use {FileId, FileResolver};
12 12
13type SyntaxProvider<'a> = dyn Fn(FileId) -> ParsedFile + 'a; 13type SyntaxProvider<'a> = dyn Fn(FileId) -> File + 'a;
14 14
15#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] 15#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
16pub struct ModuleId(FileId); 16pub struct ModuleId(FileId);
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs
index 426de4c76..73cbf5702 100644
--- a/crates/libanalysis/src/symbol_index.rs
+++ b/crates/libanalysis/src/symbol_index.rs
@@ -1,6 +1,6 @@
1use libeditor::{FileSymbol, file_symbols}; 1use libeditor::{FileSymbol, file_symbols};
2use libsyntax2::{ 2use libsyntax2::{
3 ParsedFile, 3 File,
4 SyntaxKind::{self, *}, 4 SyntaxKind::{self, *},
5}; 5};
6use fst::{self, IntoStreamer, Streamer}; 6use fst::{self, IntoStreamer, Streamer};
@@ -12,7 +12,7 @@ pub(crate) struct FileSymbols {
12} 12}
13 13
14impl FileSymbols { 14impl FileSymbols {
15 pub(crate) fn new(file: &ParsedFile) -> FileSymbols { 15 pub(crate) fn new(file: &File) -> FileSymbols {
16 let mut symbols = file_symbols(file) 16 let mut symbols = file_symbols(file)
17 .into_iter() 17 .into_iter()
18 .map(|s| (s.name.as_str().to_lowercase(), s)) 18 .map(|s| (s.name.as_str().to_lowercase(), s))
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs
index c7c043b39..b3305be2a 100644
--- a/crates/libeditor/src/code_actions.rs
+++ b/crates/libeditor/src/code_actions.rs
@@ -3,7 +3,7 @@ use std::{
3}; 3};
4 4
5use libsyntax2::{ 5use libsyntax2::{
6 ParsedFile, 6 File,
7 ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, 7 ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner},
8 SyntaxKind::COMMA, 8 SyntaxKind::COMMA,
9 SyntaxNodeRef, 9 SyntaxNodeRef,
@@ -21,7 +21,7 @@ pub struct ActionResult {
21 pub cursor_position: Option<TextUnit>, 21 pub cursor_position: Option<TextUnit>,
22} 22}
23 23
24pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { 24pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
25 let syntax = file.syntax(); 25 let syntax = file.syntax();
26 26
27 let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; 27 let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?;
@@ -38,7 +38,7 @@ pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO
38 }) 38 })
39} 39}
40 40
41pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { 41pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
42 let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; 42 let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?;
43 Some(move || { 43 Some(move || {
44 let derive_attr = nominal 44 let derive_attr = nominal
@@ -65,7 +65,7 @@ pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO
65 }) 65 })
66} 66}
67 67
68pub fn add_impl<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { 68pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
69 let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; 69 let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?;
70 let name = nominal.name()?; 70 let name = nominal.name()?;
71 71
diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs
index 32873f491..d1724b528 100644
--- a/crates/libeditor/src/extend_selection.rs
+++ b/crates/libeditor/src/extend_selection.rs
@@ -1,10 +1,10 @@
1use libsyntax2::{ 1use libsyntax2::{
2 ParsedFile, TextRange, SyntaxNodeRef, 2 File, TextRange, SyntaxNodeRef,
3 SyntaxKind::WHITESPACE, 3 SyntaxKind::WHITESPACE,
4 algo::{find_leaf_at_offset, find_covering_node, ancestors}, 4 algo::{find_leaf_at_offset, find_covering_node, ancestors},
5}; 5};
6 6
7pub fn extend_selection(file: &ParsedFile, range: TextRange) -> Option<TextRange> { 7pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> {
8 let syntax = file.syntax(); 8 let syntax = file.syntax();
9 extend(syntax.borrowed(), range) 9 extend(syntax.borrowed(), range)
10} 10}
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs
index 681cca81d..a6e6deba7 100644
--- a/crates/libeditor/src/lib.rs
+++ b/crates/libeditor/src/lib.rs
@@ -14,7 +14,7 @@ use libsyntax2::{
14 algo::{walk, find_leaf_at_offset}, 14 algo::{walk, find_leaf_at_offset},
15 SyntaxKind::{self, *}, 15 SyntaxKind::{self, *},
16}; 16};
17pub use libsyntax2::{ParsedFile, TextRange, TextUnit}; 17pub use libsyntax2::{File, TextRange, TextUnit};
18pub use self::{ 18pub use self::{
19 line_index::{LineIndex, LineCol}, 19 line_index::{LineIndex, LineCol},
20 extend_selection::extend_selection, 20 extend_selection::extend_selection,
@@ -51,11 +51,11 @@ pub enum RunnableKind {
51 Bin, 51 Bin,
52} 52}
53 53
54pub fn parse(text: &str) -> ParsedFile { 54pub fn parse(text: &str) -> File {
55 ParsedFile::parse(text) 55 File::parse(text)
56} 56}
57 57
58pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> { 58pub fn matching_brace(file: &File, offset: TextUnit) -> Option<TextUnit> {
59 const BRACES: &[SyntaxKind] = &[ 59 const BRACES: &[SyntaxKind] = &[
60 L_CURLY, R_CURLY, 60 L_CURLY, R_CURLY,
61 L_BRACK, R_BRACK, 61 L_BRACK, R_BRACK,
@@ -75,7 +75,7 @@ pub fn matching_brace(file: &ParsedFile, offset: TextUnit) -> Option<TextUnit> {
75 Some(matching_node.range().start()) 75 Some(matching_node.range().start())
76} 76}
77 77
78pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> { 78pub fn highlight(file: &File) -> Vec<HighlightedRange> {
79 let mut res = Vec::new(); 79 let mut res = Vec::new();
80 for node in walk::preorder(file.syntax()) { 80 for node in walk::preorder(file.syntax()) {
81 let tag = match node.kind() { 81 let tag = match node.kind() {
@@ -98,7 +98,7 @@ pub fn highlight(file: &ParsedFile) -> Vec<HighlightedRange> {
98 res 98 res
99} 99}
100 100
101pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> { 101pub fn diagnostics(file: &File) -> Vec<Diagnostic> {
102 let mut res = Vec::new(); 102 let mut res = Vec::new();
103 103
104 for node in walk::preorder(file.syntax()) { 104 for node in walk::preorder(file.syntax()) {
@@ -116,11 +116,11 @@ pub fn diagnostics(file: &ParsedFile) -> Vec<Diagnostic> {
116 res 116 res
117} 117}
118 118
119pub fn syntax_tree(file: &ParsedFile) -> String { 119pub fn syntax_tree(file: &File) -> String {
120 ::libsyntax2::utils::dump_tree(file.syntax()) 120 ::libsyntax2::utils::dump_tree(file.syntax())
121} 121}
122 122
123pub fn runnables(file: &ParsedFile) -> Vec<Runnable> { 123pub fn runnables(file: &File) -> Vec<Runnable> {
124 file.ast() 124 file.ast()
125 .functions() 125 .functions()
126 .filter_map(|f| { 126 .filter_map(|f| {
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs
index 37cef6389..98a35dcdf 100644
--- a/crates/libeditor/src/symbols.rs
+++ b/crates/libeditor/src/symbols.rs
@@ -1,5 +1,5 @@
1use libsyntax2::{ 1use libsyntax2::{
2 SyntaxKind, SyntaxNodeRef, AstNode, ParsedFile, SmolStr, 2 SyntaxKind, SyntaxNodeRef, AstNode, File, SmolStr,
3 ast::{self, NameOwner}, 3 ast::{self, NameOwner},
4 algo::{ 4 algo::{
5 visit::{visitor, Visitor}, 5 visit::{visitor, Visitor},
@@ -24,7 +24,7 @@ pub struct FileSymbol {
24 pub kind: SyntaxKind, 24 pub kind: SyntaxKind,
25} 25}
26 26
27pub fn file_symbols(file: &ParsedFile) -> Vec<FileSymbol> { 27pub fn file_symbols(file: &File) -> Vec<FileSymbol> {
28 preorder(file.syntax()) 28 preorder(file.syntax())
29 .filter_map(to_symbol) 29 .filter_map(to_symbol)
30 .collect() 30 .collect()
@@ -52,7 +52,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
52} 52}
53 53
54 54
55pub fn file_structure(file: &ParsedFile) -> Vec<StructureNode> { 55pub fn file_structure(file: &File) -> Vec<StructureNode> {
56 let mut res = Vec::new(); 56 let mut res = Vec::new();
57 let mut stack = Vec::new(); 57 let mut stack = Vec::new();
58 58
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs
index ebc7c77d2..e7eba671f 100644
--- a/crates/libeditor/src/typing.rs
+++ b/crates/libeditor/src/typing.rs
@@ -1,5 +1,5 @@
1use libsyntax2::{ 1use libsyntax2::{
2 TextUnit, TextRange, SyntaxNodeRef, ParsedFile, 2 TextUnit, TextRange, SyntaxNodeRef, File,
3 algo::{ 3 algo::{
4 walk::preorder, 4 walk::preorder,
5 find_covering_node, 5 find_covering_node,
@@ -10,7 +10,7 @@ use libsyntax2::{
10 10
11use {ActionResult, EditBuilder}; 11use {ActionResult, EditBuilder};
12 12
13pub fn join_lines(file: &ParsedFile, range: TextRange) -> ActionResult { 13pub fn join_lines(file: &File, range: TextRange) -> ActionResult {
14 let range = if range.is_empty() { 14 let range = if range.is_empty() {
15 let text = file.syntax().text(); 15 let text = file.syntax().text();
16 let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; 16 let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))];
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs
index 4f7c2e07a..3114a128e 100644
--- a/crates/libeditor/tests/test.rs
+++ b/crates/libeditor/tests/test.rs
@@ -5,7 +5,7 @@ extern crate assert_eq_text;
5 5
6use assert_eq_text::{assert_eq_dbg}; 6use assert_eq_text::{assert_eq_dbg};
7use libeditor::{ 7use libeditor::{
8 ParsedFile, TextUnit, TextRange, ActionResult, 8 File, TextUnit, TextRange, ActionResult,
9 highlight, runnables, extend_selection, file_structure, 9 highlight, runnables, extend_selection, file_structure,
10 flip_comma, add_derive, add_impl, matching_brace, 10 flip_comma, add_derive, add_impl, matching_brace,
11 join_lines, 11 join_lines,
@@ -234,11 +234,11 @@ struct Foo { f: u32 }
234"); 234");
235} 235}
236 236
237fn file(text: &str) -> ParsedFile { 237fn file(text: &str) -> File {
238 ParsedFile::parse(text) 238 File::parse(text)
239} 239}
240 240
241fn check_action<F: Fn(&ParsedFile, TextUnit) -> Option<ActionResult>>( 241fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>>(
242 before: &str, 242 before: &str,
243 after: &str, 243 after: &str,
244 f: F, 244 f: F,
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 9b45e2575..ab4a40435 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -51,14 +51,14 @@ pub use {
51}; 51};
52 52
53#[derive(Clone, Debug)] 53#[derive(Clone, Debug)]
54pub struct ParsedFile { 54pub struct File {
55 root: SyntaxNode 55 root: SyntaxNode
56} 56}
57 57
58impl ParsedFile { 58impl File {
59 pub fn parse(text: &str) -> Self { 59 pub fn parse(text: &str) -> Self {
60 let root = ::parse(text); 60 let root = ::parse(text);
61 ParsedFile { root } 61 File { root }
62 } 62 }
63 pub fn ast(&self) -> ast::Root { 63 pub fn ast(&self) -> ast::Root {
64 ast::Root::cast(self.syntax()).unwrap() 64 ast::Root::cast(self.syntax()).unwrap()