From 3850b1c0860a075f1fd569577c2a2fecd1fc2f0c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 11:31:26 +0200 Subject: Lift SourceChange to the ra_ide_db --- crates/ra_ide/src/lib.rs | 3 +- crates/ra_ide/src/source_change.rs | 121 ------------------------------------- crates/ra_ide/src/ssr.rs | 14 ++--- crates/ra_ide/src/typing.rs | 5 +- 4 files changed, 11 insertions(+), 132 deletions(-) delete mode 100644 crates/ra_ide/src/source_change.rs (limited to 'crates/ra_ide') 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 { } pub mod mock_analysis; -mod source_change; mod prime_caches; mod status; @@ -78,7 +77,6 @@ pub use crate::{ inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, runnables::{Runnable, RunnableKind, TestId}, - source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, ssr::SsrError, syntax_highlighting::{ Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, @@ -94,6 +92,7 @@ pub use ra_ide_db::{ line_index::{LineCol, LineIndex}, line_index_utils::translate_offset_with_edit, search::SearchScope, + source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, symbol_index::Query, RootDatabase, }; diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide/src/source_change.rs deleted file mode 100644 index 10afd7825..000000000 --- a/crates/ra_ide/src/source_change.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! This modules defines type to represent changes to the source code, that flow -//! from the server to the client. -//! -//! It can be viewed as a dual for `AnalysisChange`. - -use ra_db::RelativePathBuf; -use ra_text_edit::TextEdit; - -use crate::{FileId, FilePosition, SourceRootId, TextSize}; - -#[derive(Debug)] -pub struct SourceChange { - pub label: String, - pub source_file_edits: Vec, - pub file_system_edits: Vec, - pub cursor_position: Option, -} - -impl SourceChange { - /// Creates a new SourceChange with the given label - /// from the edits. - pub(crate) fn from_edits>( - label: L, - source_file_edits: Vec, - file_system_edits: Vec, - ) -> Self { - SourceChange { - label: label.into(), - source_file_edits, - file_system_edits, - cursor_position: None, - } - } - - /// Creates a new SourceChange with the given label, - /// containing only the given `SourceFileEdits`. - pub(crate) fn source_file_edits>(label: L, edits: Vec) -> Self { - let label = label.into(); - assert!(label.starts_with(char::is_uppercase)); - SourceChange { - label: label, - source_file_edits: edits, - file_system_edits: vec![], - cursor_position: None, - } - } - - /// Creates a new SourceChange with the given label, - /// containing only the given `FileSystemEdits`. - pub(crate) fn file_system_edits>(label: L, edits: Vec) -> Self { - SourceChange { - label: label.into(), - source_file_edits: vec![], - file_system_edits: edits, - cursor_position: None, - } - } - - /// Creates a new SourceChange with the given label, - /// containing only a single `SourceFileEdit`. - pub(crate) fn source_file_edit>(label: L, edit: SourceFileEdit) -> Self { - SourceChange::source_file_edits(label, vec![edit]) - } - - /// Creates a new SourceChange with the given label - /// from the given `FileId` and `TextEdit` - pub(crate) fn source_file_edit_from>( - label: L, - file_id: FileId, - edit: TextEdit, - ) -> Self { - SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit }) - } - - /// Creates a new SourceChange with the given label - /// from the given `FileId` and `TextEdit` - pub(crate) fn file_system_edit>(label: L, edit: FileSystemEdit) -> Self { - SourceChange::file_system_edits(label, vec![edit]) - } - - /// Sets the cursor position to the given `FilePosition` - pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self { - self.cursor_position = Some(cursor_position); - self - } - - /// Sets the cursor position to the given `FilePosition` - pub(crate) fn with_cursor_opt(mut self, cursor_position: Option) -> Self { - self.cursor_position = cursor_position; - self - } -} - -#[derive(Debug)] -pub struct SourceFileEdit { - pub file_id: FileId, - pub edit: TextEdit, -} - -#[derive(Debug)] -pub enum FileSystemEdit { - CreateFile { source_root: SourceRootId, path: RelativePathBuf }, - MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, -} - -pub(crate) struct SingleFileChange { - pub label: String, - pub edit: TextEdit, - pub cursor_position: Option, -} - -impl SingleFileChange { - pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange { - SourceChange { - label: self.label, - source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], - file_system_edits: Vec::new(), - cursor_position: self.cursor_position.map(|offset| FilePosition { file_id, offset }), - } - } -} 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 @@ //! structural search replace -use crate::source_change::SourceFileEdit; +use std::{collections::HashMap, iter::once, str::FromStr}; + use ra_db::{SourceDatabase, SourceDatabaseExt}; -use ra_ide_db::symbol_index::SymbolsDatabase; -use ra_ide_db::RootDatabase; -use ra_syntax::ast::make::try_expr_from_text; +use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; use ra_syntax::ast::{ - ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, RecordField, RecordLit, + make::try_expr_from_text, ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, + RecordField, RecordLit, }; use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode}; use ra_text_edit::{TextEdit, TextEditBuilder}; use rustc_hash::FxHashMap; -use std::collections::HashMap; -use std::{iter::once, str::FromStr}; + +use crate::SourceFileEdit; #[derive(Debug, PartialEq)] 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; use ra_db::{FilePosition, SourceDatabase}; use ra_fmt::leading_indent; -use ra_ide_db::RootDatabase; +use ra_ide_db::{source_change::SingleFileChange, RootDatabase}; use ra_syntax::{ algo::find_node_at_offset, ast::{self, AstToken}, AstNode, SourceFile, TextRange, TextSize, }; + use ra_text_edit::TextEdit; -use crate::{source_change::SingleFileChange, SourceChange}; +use crate::SourceChange; pub(crate) use on_enter::on_enter; -- cgit v1.2.3