aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernardo <[email protected]>2018-12-10 21:09:12 +0000
committerBernardo <[email protected]>2018-12-10 21:09:12 +0000
commit7344d28768c43d8955bf23c183d606be08f27c64 (patch)
treef0773b4db640dac303f1f683115c780ac3eb0b9c
parentf655f993fe6d9faa81b0e776b9b24308d2ea1c68 (diff)
extract AtomEdit and Edit into new ra_text_edit crate
-rw-r--r--Cargo.lock12
-rw-r--r--crates/ra_analysis/Cargo.toml1
-rw-r--r--crates/ra_analysis/src/completion.rs3
-rw-r--r--crates/ra_analysis/src/lib.rs3
-rw-r--r--crates/ra_editor/Cargo.toml1
-rw-r--r--crates/ra_editor/src/lib.rs4
-rw-r--r--crates/ra_editor/src/typing.rs3
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/conv.rs3
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs3
-rw-r--r--crates/ra_syntax/Cargo.toml1
-rw-r--r--crates/ra_syntax/src/lib.rs2
-rw-r--r--crates/ra_syntax/src/reparsing.rs24
-rw-r--r--crates/ra_syntax/src/text_utils.rs6
-rw-r--r--crates/ra_syntax/src/yellow/syntax_text.rs3
-rw-r--r--crates/ra_text_edit/Cargo.toml12
-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.rs29
-rw-r--r--crates/ra_text_edit/src/text_utils.rs5
19 files changed, 81 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1f69a91b2..56d5c65b9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -610,6 +610,7 @@ dependencies = [
610 "ra_editor 0.1.0", 610 "ra_editor 0.1.0",
611 "ra_hir 0.1.0", 611 "ra_hir 0.1.0",
612 "ra_syntax 0.1.0", 612 "ra_syntax 0.1.0",
613 "ra_text_edit 0.1.0",
613 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 614 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
614 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 615 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
615 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 616 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -649,6 +650,7 @@ dependencies = [
649 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", 650 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
650 "join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 651 "join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
651 "ra_syntax 0.1.0", 652 "ra_syntax 0.1.0",
653 "ra_text_edit 0.1.0",
652 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 654 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
653 "superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 655 "superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
654 "test_utils 0.1.0", 656 "test_utils 0.1.0",
@@ -687,6 +689,7 @@ dependencies = [
687 "ra_analysis 0.1.0", 689 "ra_analysis 0.1.0",
688 "ra_editor 0.1.0", 690 "ra_editor 0.1.0",
689 "ra_syntax 0.1.0", 691 "ra_syntax 0.1.0",
692 "ra_text_edit 0.1.0",
690 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 693 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
691 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 694 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
692 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 695 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -710,6 +713,7 @@ dependencies = [
710 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 713 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
711 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", 714 "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
712 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 715 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
716 "ra_text_edit 0.1.0",
713 "rowan 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 717 "rowan 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
714 "test_utils 0.1.0", 718 "test_utils 0.1.0",
715 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 719 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -718,6 +722,14 @@ dependencies = [
718] 722]
719 723
720[[package]] 724[[package]]
725name = "ra_text_edit"
726version = "0.1.0"
727dependencies = [
728 "test_utils 0.1.0",
729 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
730]
731
732[[package]]
721name = "rand" 733name = "rand"
722version = "0.4.3" 734version = "0.4.3"
723source = "registry+https://github.com/rust-lang/crates.io-index" 735source = "registry+https://github.com/rust-lang/crates.io-index"
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"
14parking_lot = "0.6.4" 14parking_lot = "0.6.4"
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
16ra_editor = { path = "../ra_editor" } 16ra_editor = { path = "../ra_editor" }
17ra_text_edit = { path = "../ra_text_edit" }
17ra_db = { path = "../ra_db" } 18ra_db = { path = "../ra_db" }
18hir = { path = "../ra_hir", package = "ra_hir" } 19hir = { path = "../ra_hir", package = "ra_hir" }
19test_utils = { path = "../test_utils" } 20test_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 @@
1mod reference_completion; 1mod reference_completion;
2 2
3use ra_editor::find_node_at_offset; 3use ra_editor::find_node_at_offset;
4use ra_text_edit::AtomEdit;
4use ra_syntax::{ 5use 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};
10use ra_db::SyntaxDatabase; 11use 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
19use std::{fmt, sync::Arc}; 19use std::{fmt, sync::Arc};
20 20
21use ra_syntax::{AtomEdit, SourceFileNode, TextRange, TextUnit}; 21use ra_syntax::{SourceFileNode, TextRange, TextUnit};
22use ra_text_edit::AtomEdit;
22use ra_db::FileResolverImp; 23use ra_db::FileResolverImp;
23use rayon::prelude::*; 24use rayon::prelude::*;
24use relative_path::RelativePathBuf; 25use 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"
12rustc-hash = "1.0" 12rustc-hash = "1.0"
13 13
14ra_syntax = { path = "../ra_syntax" } 14ra_syntax = { path = "../ra_syntax" }
15ra_text_edit = { path = "../ra_text_edit" }
15 16
16[dev-dependencies] 17[dev-dependencies]
17test_utils = { path = "../test_utils" } 18test_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 @@
1mod code_actions; 1mod code_actions;
2mod edit;
3mod extend_selection; 2mod extend_selection;
4mod folding_ranges; 3mod folding_ranges;
5mod line_index; 4mod line_index;
@@ -10,14 +9,13 @@ mod typing;
10 9
11pub use self::{ 10pub 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};
20pub use ra_syntax::AtomEdit; 18use ra_text_edit::{Edit, EditBuilder};
21use ra_syntax::{ 19use 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;
3use ra_syntax::{ 3use 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};
11use ra_text_edit::text_utils::contains_offset_nonstrict;
11 12
12use crate::{find_node_at_offset, EditBuilder, LocalEdit}; 13use 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
29ra_syntax = { path = "../ra_syntax" } 29ra_syntax = { path = "../ra_syntax" }
30ra_editor = { path = "../ra_editor" } 30ra_editor = { path = "../ra_editor" }
31ra_text_edit = { path = "../ra_text_edit" }
31ra_analysis = { path = "../ra_analysis" } 32ra_analysis = { path = "../ra_analysis" }
32gen_lsp_server = { path = "../gen_lsp_server" } 33gen_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};
5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; 5use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition};
6use ra_editor::{AtomEdit, Edit, LineCol, LineIndex}; 6use ra_editor::{LineCol, LineIndex};
7use ra_text_edit::{AtomEdit, Edit};
7use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 8use ra_syntax::{SyntaxKind, TextRange, TextUnit};
8 9
9use crate::{req, server_world::ServerWorld, Result}; 10use 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};
11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; 11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition};
12use ra_syntax::{TextUnit, text_utils::{contains_offset_nonstrict, intersect}}; 12use ra_syntax::{TextUnit, text_utils::intersect};
13use ra_text_edit::text_utils::contains_offset_nonstrict;
13use rustc_hash::FxHashMap; 14use rustc_hash::FxHashMap;
14use serde_json::to_value; 15use 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"
15parking_lot = "0.6.0" 15parking_lot = "0.6.0"
16rowan = "0.1.2" 16rowan = "0.1.2"
17text_unit = "0.1.5" 17text_unit = "0.1.5"
18ra_text_edit = { path = "../ra_text_edit" }
18 19
19[dev-dependencies] 20[dev-dependencies]
20test_utils = { path = "../test_utils" } 21test_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};
41pub use crate::{ 41pub 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
50use ra_text_edit::AtomEdit;
51use crate::yellow::GreenNode; 51use 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;
6use crate::text_utils::replace_range; 6use crate::text_utils::replace_range;
7use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; 7use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef};
8use crate::{SyntaxKind::*, TextRange, TextUnit}; 8use crate::{SyntaxKind::*, TextRange, TextUnit};
9 9use ra_text_edit::AtomEdit;
10#[derive(Debug, Clone)]
11pub struct AtomEdit {
12 pub delete: TextRange,
13 pub insert: String,
14}
15
16impl 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
33pub(crate) fn incremental_reparse( 11pub(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 @@
1use crate::{TextRange, TextUnit}; 1use crate::TextRange;
2
3pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
4 range.start() <= offset && offset <= range.end()
5}
6 2
7pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { 3pub 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 @@
1use std::{fmt, ops}; 1use std::{fmt, ops};
2 2
3use ra_text_edit::text_utils::contains_offset_nonstrict;
3use crate::{ 4use 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]
2edition = "2018"
3name = "ra_text_edit"
4version = "0.1.0"
5authors = ["Aleksey Kladov <[email protected]>"]
6publish = false
7
8[dependencies]
9text_unit = "0.1.5"
10
11[dev-dependencies]
12test_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 @@
1use crate::{TextRange, TextUnit}; 1use crate::AtomEdit;
2use ra_syntax::{text_utils::contains_offset_nonstrict, AtomEdit}; 2use crate::text_utils::contains_offset_nonstrict;
3use text_unit::{TextRange, TextUnit};
3 4
4#[derive(Debug, Clone)] 5#[derive(Debug, Clone)]
5pub struct Edit { 6pub 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 @@
1mod edit;
2pub mod text_utils;
3
4pub use crate::edit::{Edit, EditBuilder};
5
6use text_unit::{TextRange, TextUnit};
7
8#[derive(Debug, Clone)]
9pub struct AtomEdit {
10 pub delete: TextRange,
11 pub insert: String,
12}
13
14impl 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 @@
1use text_unit::{TextRange, TextUnit};
2
3pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
4 range.start() <= offset && offset <= range.end()
5}