diff options
author | Aleksey Kladov <[email protected]> | 2020-05-06 10:31:26 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-06 10:32:34 +0100 |
commit | 3850b1c0860a075f1fd569577c2a2fecd1fc2f0c (patch) | |
tree | fd9a78d80ae77f1fb706ba48bff0195be24bf5d6 | |
parent | beb35c3ecb4aa5139571aba70f7364d135302775 (diff) |
Lift SourceChange to the ra_ide_db
-rw-r--r-- | crates/ra_ide/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide/src/ssr.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_db/src/source_change.rs (renamed from crates/ra_ide/src/source_change.rs) | 25 | ||||
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 2 |
6 files changed, 25 insertions, 25 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 12c005f06..4ed02f60e 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -16,7 +16,6 @@ macro_rules! eprintln { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
19 | mod source_change; | ||
20 | 19 | ||
21 | mod prime_caches; | 20 | mod prime_caches; |
22 | mod status; | 21 | mod status; |
@@ -78,7 +77,6 @@ pub use crate::{ | |||
78 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 77 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
79 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, | 78 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, |
80 | runnables::{Runnable, RunnableKind, TestId}, | 79 | runnables::{Runnable, RunnableKind, TestId}, |
81 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | ||
82 | ssr::SsrError, | 80 | ssr::SsrError, |
83 | syntax_highlighting::{ | 81 | syntax_highlighting::{ |
84 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 82 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, |
@@ -94,6 +92,7 @@ pub use ra_ide_db::{ | |||
94 | line_index::{LineCol, LineIndex}, | 92 | line_index::{LineCol, LineIndex}, |
95 | line_index_utils::translate_offset_with_edit, | 93 | line_index_utils::translate_offset_with_edit, |
96 | search::SearchScope, | 94 | search::SearchScope, |
95 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | ||
97 | symbol_index::Query, | 96 | symbol_index::Query, |
98 | RootDatabase, | 97 | RootDatabase, |
99 | }; | 98 | }; |
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 8bf52d0fa..1873d1d0d 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs | |||
@@ -1,18 +1,18 @@ | |||
1 | //! structural search replace | 1 | //! structural search replace |
2 | 2 | ||
3 | use crate::source_change::SourceFileEdit; | 3 | use std::{collections::HashMap, iter::once, str::FromStr}; |
4 | |||
4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 5 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
5 | use ra_ide_db::symbol_index::SymbolsDatabase; | 6 | use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; |
6 | use ra_ide_db::RootDatabase; | ||
7 | use ra_syntax::ast::make::try_expr_from_text; | ||
8 | use ra_syntax::ast::{ | 7 | use ra_syntax::ast::{ |
9 | ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, RecordField, RecordLit, | 8 | make::try_expr_from_text, ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, |
9 | RecordField, RecordLit, | ||
10 | }; | 10 | }; |
11 | use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode}; | 11 | use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode}; |
12 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 12 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
14 | use std::collections::HashMap; | 14 | |
15 | use std::{iter::once, str::FromStr}; | 15 | use crate::SourceFileEdit; |
16 | 16 | ||
17 | #[derive(Debug, PartialEq)] | 17 | #[derive(Debug, PartialEq)] |
18 | pub struct SsrError(String); | 18 | pub struct SsrError(String); |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index a03da4693..6f04f0be4 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -17,15 +17,16 @@ mod on_enter; | |||
17 | 17 | ||
18 | use ra_db::{FilePosition, SourceDatabase}; | 18 | use ra_db::{FilePosition, SourceDatabase}; |
19 | use ra_fmt::leading_indent; | 19 | use ra_fmt::leading_indent; |
20 | use ra_ide_db::RootDatabase; | 20 | use ra_ide_db::{source_change::SingleFileChange, RootDatabase}; |
21 | use ra_syntax::{ | 21 | use ra_syntax::{ |
22 | algo::find_node_at_offset, | 22 | algo::find_node_at_offset, |
23 | ast::{self, AstToken}, | 23 | ast::{self, AstToken}, |
24 | AstNode, SourceFile, TextRange, TextSize, | 24 | AstNode, SourceFile, TextRange, TextSize, |
25 | }; | 25 | }; |
26 | |||
26 | use ra_text_edit::TextEdit; | 27 | use ra_text_edit::TextEdit; |
27 | 28 | ||
28 | use crate::{source_change::SingleFileChange, SourceChange}; | 29 | use crate::SourceChange; |
29 | 30 | ||
30 | pub(crate) use on_enter::on_enter; | 31 | pub(crate) use on_enter::on_enter; |
31 | 32 | ||
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index e6f2d36e9..52fcd7b6f 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -10,6 +10,7 @@ pub mod change; | |||
10 | pub mod defs; | 10 | pub mod defs; |
11 | pub mod search; | 11 | pub mod search; |
12 | pub mod imports_locator; | 12 | pub mod imports_locator; |
13 | pub mod source_change; | ||
13 | mod wasm_shims; | 14 | mod wasm_shims; |
14 | 15 | ||
15 | use std::sync::Arc; | 16 | use std::sync::Arc; |
diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide_db/src/source_change.rs index 10afd7825..4dd01b312 100644 --- a/crates/ra_ide/src/source_change.rs +++ b/crates/ra_ide_db/src/source_change.rs | |||
@@ -3,13 +3,12 @@ | |||
3 | //! | 3 | //! |
4 | //! It can be viewed as a dual for `AnalysisChange`. | 4 | //! It can be viewed as a dual for `AnalysisChange`. |
5 | 5 | ||
6 | use ra_db::RelativePathBuf; | 6 | use ra_db::{FileId, FilePosition, RelativePathBuf, SourceRootId}; |
7 | use ra_text_edit::TextEdit; | 7 | use ra_text_edit::{TextEdit, TextSize}; |
8 | |||
9 | use crate::{FileId, FilePosition, SourceRootId, TextSize}; | ||
10 | 8 | ||
11 | #[derive(Debug)] | 9 | #[derive(Debug)] |
12 | pub struct SourceChange { | 10 | pub struct SourceChange { |
11 | /// For display in the undo log in the editor | ||
13 | pub label: String, | 12 | pub label: String, |
14 | pub source_file_edits: Vec<SourceFileEdit>, | 13 | pub source_file_edits: Vec<SourceFileEdit>, |
15 | pub file_system_edits: Vec<FileSystemEdit>, | 14 | pub file_system_edits: Vec<FileSystemEdit>, |
@@ -19,7 +18,7 @@ pub struct SourceChange { | |||
19 | impl SourceChange { | 18 | impl SourceChange { |
20 | /// Creates a new SourceChange with the given label | 19 | /// Creates a new SourceChange with the given label |
21 | /// from the edits. | 20 | /// from the edits. |
22 | pub(crate) fn from_edits<L: Into<String>>( | 21 | pub fn from_edits<L: Into<String>>( |
23 | label: L, | 22 | label: L, |
24 | source_file_edits: Vec<SourceFileEdit>, | 23 | source_file_edits: Vec<SourceFileEdit>, |
25 | file_system_edits: Vec<FileSystemEdit>, | 24 | file_system_edits: Vec<FileSystemEdit>, |
@@ -34,7 +33,7 @@ impl SourceChange { | |||
34 | 33 | ||
35 | /// Creates a new SourceChange with the given label, | 34 | /// Creates a new SourceChange with the given label, |
36 | /// containing only the given `SourceFileEdits`. | 35 | /// containing only the given `SourceFileEdits`. |
37 | pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | 36 | pub fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { |
38 | let label = label.into(); | 37 | let label = label.into(); |
39 | assert!(label.starts_with(char::is_uppercase)); | 38 | assert!(label.starts_with(char::is_uppercase)); |
40 | SourceChange { | 39 | SourceChange { |
@@ -58,13 +57,13 @@ impl SourceChange { | |||
58 | 57 | ||
59 | /// Creates a new SourceChange with the given label, | 58 | /// Creates a new SourceChange with the given label, |
60 | /// containing only a single `SourceFileEdit`. | 59 | /// containing only a single `SourceFileEdit`. |
61 | pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { | 60 | pub fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { |
62 | SourceChange::source_file_edits(label, vec![edit]) | 61 | SourceChange::source_file_edits(label, vec![edit]) |
63 | } | 62 | } |
64 | 63 | ||
65 | /// Creates a new SourceChange with the given label | 64 | /// Creates a new SourceChange with the given label |
66 | /// from the given `FileId` and `TextEdit` | 65 | /// from the given `FileId` and `TextEdit` |
67 | pub(crate) fn source_file_edit_from<L: Into<String>>( | 66 | pub fn source_file_edit_from<L: Into<String>>( |
68 | label: L, | 67 | label: L, |
69 | file_id: FileId, | 68 | file_id: FileId, |
70 | edit: TextEdit, | 69 | edit: TextEdit, |
@@ -74,18 +73,18 @@ impl SourceChange { | |||
74 | 73 | ||
75 | /// Creates a new SourceChange with the given label | 74 | /// Creates a new SourceChange with the given label |
76 | /// from the given `FileId` and `TextEdit` | 75 | /// from the given `FileId` and `TextEdit` |
77 | pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { | 76 | pub fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { |
78 | SourceChange::file_system_edits(label, vec![edit]) | 77 | SourceChange::file_system_edits(label, vec![edit]) |
79 | } | 78 | } |
80 | 79 | ||
81 | /// Sets the cursor position to the given `FilePosition` | 80 | /// Sets the cursor position to the given `FilePosition` |
82 | pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self { | 81 | pub fn with_cursor(mut self, cursor_position: FilePosition) -> Self { |
83 | self.cursor_position = Some(cursor_position); | 82 | self.cursor_position = Some(cursor_position); |
84 | self | 83 | self |
85 | } | 84 | } |
86 | 85 | ||
87 | /// Sets the cursor position to the given `FilePosition` | 86 | /// Sets the cursor position to the given `FilePosition` |
88 | pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self { | 87 | pub fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self { |
89 | self.cursor_position = cursor_position; | 88 | self.cursor_position = cursor_position; |
90 | self | 89 | self |
91 | } | 90 | } |
@@ -103,14 +102,14 @@ pub enum FileSystemEdit { | |||
103 | MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, | 102 | MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, |
104 | } | 103 | } |
105 | 104 | ||
106 | pub(crate) struct SingleFileChange { | 105 | pub struct SingleFileChange { |
107 | pub label: String, | 106 | pub label: String, |
108 | pub edit: TextEdit, | 107 | pub edit: TextEdit, |
109 | pub cursor_position: Option<TextSize>, | 108 | pub cursor_position: Option<TextSize>, |
110 | } | 109 | } |
111 | 110 | ||
112 | impl SingleFileChange { | 111 | impl SingleFileChange { |
113 | pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange { | 112 | pub fn into_source_change(self, file_id: FileId) -> SourceChange { |
114 | SourceChange { | 113 | SourceChange { |
115 | label: self.label, | 114 | label: self.label, |
116 | source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], | 115 | source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], |
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 7138bbc65..64b67f2ad 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | //! so `TextEdit` is the ultimate representation of the work done by | 4 | //! so `TextEdit` is the ultimate representation of the work done by |
5 | //! rust-analyzer. | 5 | //! rust-analyzer. |
6 | 6 | ||
7 | use text_size::{TextRange, TextSize}; | 7 | pub use text_size::{TextRange, TextSize}; |
8 | 8 | ||
9 | /// `InsertDelete` -- a single "atomic" change to text | 9 | /// `InsertDelete` -- a single "atomic" change to text |
10 | /// | 10 | /// |