diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_editor/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_editor/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_editor/src/typing.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 24 | ||||
-rw-r--r-- | crates/ra_syntax/src/text_utils.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 3 | ||||
-rw-r--r-- | crates/ra_text_edit/Cargo.toml | 12 | ||||
-rw-r--r-- | crates/ra_text_edit/src/edit.rs (renamed from crates/ra_editor/src/edit.rs) | 5 | ||||
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 29 | ||||
-rw-r--r-- | crates/ra_text_edit/src/text_utils.rs | 5 |
18 files changed, 69 insertions, 40 deletions
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index fe9765a66..4a7b99947 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml | |||
@@ -14,6 +14,7 @@ rustc-hash = "1.0" | |||
14 | parking_lot = "0.6.4" | 14 | parking_lot = "0.6.4" |
15 | ra_syntax = { path = "../ra_syntax" } | 15 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_editor = { path = "../ra_editor" } | 16 | ra_editor = { path = "../ra_editor" } |
17 | ra_text_edit = { path = "../ra_text_edit" } | ||
17 | ra_db = { path = "../ra_db" } | 18 | ra_db = { path = "../ra_db" } |
18 | hir = { path = "../ra_hir", package = "ra_hir" } | 19 | hir = { path = "../ra_hir", package = "ra_hir" } |
19 | test_utils = { path = "../test_utils" } | 20 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 0f154112a..e83330966 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | mod reference_completion; | 1 | mod reference_completion; |
2 | 2 | ||
3 | use ra_editor::find_node_at_offset; | 3 | use ra_editor::find_node_at_offset; |
4 | use ra_text_edit::AtomEdit; | ||
4 | use ra_syntax::{ | 5 | use ra_syntax::{ |
5 | algo::visit::{visitor_ctx, VisitorCtx}, | 6 | algo::visit::{visitor_ctx, VisitorCtx}, |
6 | ast, | 7 | ast, |
7 | AstNode, AtomEdit, | 8 | AstNode, |
8 | SyntaxNodeRef, | 9 | SyntaxNodeRef, |
9 | }; | 10 | }; |
10 | use ra_db::SyntaxDatabase; | 11 | use ra_db::SyntaxDatabase; |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index eaf24cb36..2f8f1dab5 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -18,7 +18,8 @@ pub mod mock_analysis; | |||
18 | 18 | ||
19 | use std::{fmt, sync::Arc}; | 19 | use std::{fmt, sync::Arc}; |
20 | 20 | ||
21 | use ra_syntax::{AtomEdit, SourceFileNode, TextRange, TextUnit}; | 21 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; |
22 | use ra_text_edit::AtomEdit; | ||
22 | use ra_db::FileResolverImp; | 23 | use ra_db::FileResolverImp; |
23 | use rayon::prelude::*; | 24 | use rayon::prelude::*; |
24 | use relative_path::RelativePathBuf; | 25 | use relative_path::RelativePathBuf; |
diff --git a/crates/ra_editor/Cargo.toml b/crates/ra_editor/Cargo.toml index 7791da156..c29be1350 100644 --- a/crates/ra_editor/Cargo.toml +++ b/crates/ra_editor/Cargo.toml | |||
@@ -12,6 +12,7 @@ join_to_string = "0.1.1" | |||
12 | rustc-hash = "1.0" | 12 | rustc-hash = "1.0" |
13 | 13 | ||
14 | ra_syntax = { path = "../ra_syntax" } | 14 | ra_syntax = { path = "../ra_syntax" } |
15 | ra_text_edit = { path = "../ra_text_edit" } | ||
15 | 16 | ||
16 | [dev-dependencies] | 17 | [dev-dependencies] |
17 | test_utils = { path = "../test_utils" } | 18 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index ce080ee97..ddc44c778 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | mod code_actions; | 1 | mod code_actions; |
2 | mod edit; | ||
3 | mod extend_selection; | 2 | mod extend_selection; |
4 | mod folding_ranges; | 3 | mod folding_ranges; |
5 | mod line_index; | 4 | mod line_index; |
@@ -10,14 +9,13 @@ mod typing; | |||
10 | 9 | ||
11 | pub use self::{ | 10 | pub use self::{ |
12 | code_actions::{add_derive, add_impl, flip_comma, introduce_variable, LocalEdit}, | 11 | code_actions::{add_derive, add_impl, flip_comma, introduce_variable, LocalEdit}, |
13 | edit::{Edit, EditBuilder}, | ||
14 | extend_selection::extend_selection, | 12 | extend_selection::extend_selection, |
15 | folding_ranges::{folding_ranges, Fold, FoldKind}, | 13 | folding_ranges::{folding_ranges, Fold, FoldKind}, |
16 | line_index::{LineCol, LineIndex}, | 14 | line_index::{LineCol, LineIndex}, |
17 | symbols::{file_structure, file_symbols, FileSymbol, StructureNode}, | 15 | symbols::{file_structure, file_symbols, FileSymbol, StructureNode}, |
18 | typing::{join_lines, on_enter, on_eq_typed}, | 16 | typing::{join_lines, on_enter, on_eq_typed}, |
19 | }; | 17 | }; |
20 | pub use ra_syntax::AtomEdit; | 18 | use ra_text_edit::{Edit, EditBuilder}; |
21 | use ra_syntax::{ | 19 | use ra_syntax::{ |
22 | algo::find_leaf_at_offset, | 20 | algo::find_leaf_at_offset, |
23 | ast::{self, AstNode, NameOwner}, | 21 | ast::{self, AstNode, NameOwner}, |
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 01acdda7c..cf9af001b 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -3,11 +3,12 @@ use std::mem; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, | 4 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, |
5 | ast, | 5 | ast, |
6 | text_utils::{contains_offset_nonstrict, intersect}, | 6 | text_utils::intersect, |
7 | AstNode, SourceFileNode, SyntaxKind, | 7 | AstNode, SourceFileNode, SyntaxKind, |
8 | SyntaxKind::*, | 8 | SyntaxKind::*, |
9 | SyntaxNodeRef, TextRange, TextUnit, | 9 | SyntaxNodeRef, TextRange, TextUnit, |
10 | }; | 10 | }; |
11 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
11 | 12 | ||
12 | use crate::{find_node_at_offset, EditBuilder, LocalEdit}; | 13 | use crate::{find_node_at_offset, EditBuilder, LocalEdit}; |
13 | 14 | ||
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 5ee218b6b..133decc52 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -28,6 +28,7 @@ rustc-hash = "1.0" | |||
28 | 28 | ||
29 | ra_syntax = { path = "../ra_syntax" } | 29 | ra_syntax = { path = "../ra_syntax" } |
30 | ra_editor = { path = "../ra_editor" } | 30 | ra_editor = { path = "../ra_editor" } |
31 | ra_text_edit = { path = "../ra_text_edit" } | ||
31 | ra_analysis = { path = "../ra_analysis" } | 32 | ra_analysis = { path = "../ra_analysis" } |
32 | gen_lsp_server = { path = "../gen_lsp_server" } | 33 | gen_lsp_server = { path = "../gen_lsp_server" } |
33 | 34 | ||
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 28368787c..8bf8576be 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -3,7 +3,8 @@ use languageserver_types::{ | |||
3 | TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, | 3 | TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; |
6 | use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; | 6 | use ra_editor::{LineCol, LineIndex}; |
7 | use ra_text_edit::{AtomEdit, Edit}; | ||
7 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
8 | 9 | ||
9 | use crate::{req, server_world::ServerWorld, Result}; | 10 | use crate::{req, server_world::ServerWorld, Result}; |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 92e92f836..21ca22c5c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -9,7 +9,8 @@ use languageserver_types::{ | |||
9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, | 9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; |
12 | use ra_syntax::{TextUnit, text_utils::{contains_offset_nonstrict, intersect}}; | 12 | use ra_syntax::{TextUnit, text_utils::intersect}; |
13 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
13 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
14 | use serde_json::to_value; | 15 | use serde_json::to_value; |
15 | 16 | ||
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 8ad8ed196..8c9a7e238 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -15,6 +15,7 @@ drop_bomb = "0.1.4" | |||
15 | parking_lot = "0.6.0" | 15 | parking_lot = "0.6.0" |
16 | rowan = "0.1.2" | 16 | rowan = "0.1.2" |
17 | text_unit = "0.1.5" | 17 | text_unit = "0.1.5" |
18 | ra_text_edit = { path = "../ra_text_edit" } | ||
18 | 19 | ||
19 | [dev-dependencies] | 20 | [dev-dependencies] |
20 | test_utils = { path = "../test_utils" } | 21 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 0e5c9baad..7295fb237 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -41,13 +41,13 @@ pub use rowan::{SmolStr, TextRange, TextUnit}; | |||
41 | pub use crate::{ | 41 | pub use crate::{ |
42 | ast::AstNode, | 42 | ast::AstNode, |
43 | lexer::{tokenize, Token}, | 43 | lexer::{tokenize, Token}, |
44 | reparsing::AtomEdit, | ||
45 | syntax_kinds::SyntaxKind, | 44 | syntax_kinds::SyntaxKind, |
46 | yellow::{ | 45 | yellow::{ |
47 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, | 46 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, |
48 | }, | 47 | }, |
49 | }; | 48 | }; |
50 | 49 | ||
50 | use ra_text_edit::AtomEdit; | ||
51 | use crate::yellow::GreenNode; | 51 | use crate::yellow::GreenNode; |
52 | 52 | ||
53 | /// `SourceFileNode` represents a parse tree for a single Rust file. | 53 | /// `SourceFileNode` represents a parse tree for a single Rust file. |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 732fb0e4a..873809a5a 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -6,29 +6,7 @@ use crate::parser_impl; | |||
6 | use crate::text_utils::replace_range; | 6 | use crate::text_utils::replace_range; |
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; | 7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | 9 | use ra_text_edit::AtomEdit; | |
10 | #[derive(Debug, Clone)] | ||
11 | pub struct AtomEdit { | ||
12 | pub delete: TextRange, | ||
13 | pub insert: String, | ||
14 | } | ||
15 | |||
16 | impl AtomEdit { | ||
17 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | ||
18 | AtomEdit { | ||
19 | delete: range, | ||
20 | insert: replace_with, | ||
21 | } | ||
22 | } | ||
23 | |||
24 | pub fn delete(range: TextRange) -> AtomEdit { | ||
25 | AtomEdit::replace(range, String::new()) | ||
26 | } | ||
27 | |||
28 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | ||
29 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | ||
30 | } | ||
31 | } | ||
32 | 10 | ||
33 | pub(crate) fn incremental_reparse( | 11 | pub(crate) fn incremental_reparse( |
34 | node: SyntaxNodeRef, | 12 | node: SyntaxNodeRef, |
diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs index a90f8a083..417d43e1b 100644 --- a/crates/ra_syntax/src/text_utils.rs +++ b/crates/ra_syntax/src/text_utils.rs | |||
@@ -1,8 +1,4 @@ | |||
1 | use crate::{TextRange, TextUnit}; | 1 | use crate::TextRange; |
2 | |||
3 | pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { | ||
4 | range.start() <= offset && offset <= range.end() | ||
5 | } | ||
6 | 2 | ||
7 | pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { | 3 | pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { |
8 | let start = r1.start().max(r2.start()); | 4 | let start = r1.start().max(r2.start()); |
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 5395ca90b..46bde9a08 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use std::{fmt, ops}; | 1 | use std::{fmt, ops}; |
2 | 2 | ||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
3 | use crate::{ | 4 | use crate::{ |
4 | text_utils::{contains_offset_nonstrict, intersect}, | 5 | text_utils::intersect, |
5 | SyntaxNodeRef, TextRange, TextUnit, | 6 | SyntaxNodeRef, TextRange, TextUnit, |
6 | }; | 7 | }; |
7 | 8 | ||
diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml new file mode 100644 index 000000000..3c4157a4e --- /dev/null +++ b/crates/ra_text_edit/Cargo.toml | |||
@@ -0,0 +1,12 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_text_edit" | ||
4 | version = "0.1.0" | ||
5 | authors = ["Aleksey Kladov <[email protected]>"] | ||
6 | publish = false | ||
7 | |||
8 | [dependencies] | ||
9 | text_unit = "0.1.5" | ||
10 | |||
11 | [dev-dependencies] | ||
12 | test_utils = { path = "../test_utils" } | ||
diff --git a/crates/ra_editor/src/edit.rs b/crates/ra_text_edit/src/edit.rs index 372b8d14c..560cf2bbc 100644 --- a/crates/ra_editor/src/edit.rs +++ b/crates/ra_text_edit/src/edit.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use crate::{TextRange, TextUnit}; | 1 | use crate::AtomEdit; |
2 | use ra_syntax::{text_utils::contains_offset_nonstrict, AtomEdit}; | 2 | use crate::text_utils::contains_offset_nonstrict; |
3 | use text_unit::{TextRange, TextUnit}; | ||
3 | 4 | ||
4 | #[derive(Debug, Clone)] | 5 | #[derive(Debug, Clone)] |
5 | pub struct Edit { | 6 | pub struct Edit { |
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs new file mode 100644 index 000000000..789471e8a --- /dev/null +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -0,0 +1,29 @@ | |||
1 | mod edit; | ||
2 | pub mod text_utils; | ||
3 | |||
4 | pub use crate::edit::{Edit, EditBuilder}; | ||
5 | |||
6 | use text_unit::{TextRange, TextUnit}; | ||
7 | |||
8 | #[derive(Debug, Clone)] | ||
9 | pub struct AtomEdit { | ||
10 | pub delete: TextRange, | ||
11 | pub insert: String, | ||
12 | } | ||
13 | |||
14 | impl AtomEdit { | ||
15 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | ||
16 | AtomEdit { | ||
17 | delete: range, | ||
18 | insert: replace_with, | ||
19 | } | ||
20 | } | ||
21 | |||
22 | pub fn delete(range: TextRange) -> AtomEdit { | ||
23 | AtomEdit::replace(range, String::new()) | ||
24 | } | ||
25 | |||
26 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | ||
27 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | ||
28 | } | ||
29 | } | ||
diff --git a/crates/ra_text_edit/src/text_utils.rs b/crates/ra_text_edit/src/text_utils.rs new file mode 100644 index 000000000..e3b4dc4fe --- /dev/null +++ b/crates/ra_text_edit/src/text_utils.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | use text_unit::{TextRange, TextUnit}; | ||
2 | |||
3 | pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { | ||
4 | range.start() <= offset && offset <= range.end() | ||
5 | } | ||