5726: Rename ra_text_edit -> text_edit
 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-08-12 15:04:52 +00:00 committed by GitHub
commit a573e088ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 102 additions and 94 deletions

48
Cargo.lock generated
View file

@ -358,8 +358,8 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"jod-thread", "jod-thread",
"log", "log",
"ra_toolchain",
"serde_json", "serde_json",
"toolchain",
] ]
[[package]] [[package]]
@ -927,10 +927,10 @@ dependencies = [
"ra_hir", "ra_hir",
"ra_ide_db", "ra_ide_db",
"ra_syntax", "ra_syntax",
"ra_text_edit",
"rustc-hash", "rustc-hash",
"stdx", "stdx",
"test_utils", "test_utils",
"text_edit",
] ]
[[package]] [[package]]
@ -1075,10 +1075,10 @@ dependencies = [
"ra_ide_db", "ra_ide_db",
"ra_ssr", "ra_ssr",
"ra_syntax", "ra_syntax",
"ra_text_edit",
"rustc-hash", "rustc-hash",
"stdx", "stdx",
"test_utils", "test_utils",
"text_edit",
] ]
[[package]] [[package]]
@ -1093,11 +1093,11 @@ dependencies = [
"ra_db", "ra_db",
"ra_hir", "ra_hir",
"ra_syntax", "ra_syntax",
"ra_text_edit",
"rayon", "rayon",
"rustc-hash", "rustc-hash",
"stdx", "stdx",
"test_utils", "test_utils",
"text_edit",
] ]
[[package]] [[package]]
@ -1143,9 +1143,9 @@ dependencies = [
"memmap", "memmap",
"ra_mbe", "ra_mbe",
"ra_proc_macro", "ra_proc_macro",
"ra_toolchain",
"serde_derive", "serde_derive",
"test_utils", "test_utils",
"toolchain",
"tt", "tt",
] ]
@ -1161,11 +1161,11 @@ dependencies = [
"ra_cfg", "ra_cfg",
"ra_db", "ra_db",
"ra_proc_macro", "ra_proc_macro",
"ra_toolchain",
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
"stdx", "stdx",
"toolchain",
] ]
[[package]] [[package]]
@ -1177,9 +1177,9 @@ dependencies = [
"ra_hir", "ra_hir",
"ra_ide_db", "ra_ide_db",
"ra_syntax", "ra_syntax",
"ra_text_edit",
"rustc-hash", "rustc-hash",
"test_utils", "test_utils",
"text_edit",
] ]
[[package]] [[package]]
@ -1191,7 +1191,6 @@ dependencies = [
"itertools", "itertools",
"once_cell", "once_cell",
"ra_parser", "ra_parser",
"ra_text_edit",
"rayon", "rayon",
"rowan", "rowan",
"rustc-ap-rustc_lexer", "rustc-ap-rustc_lexer",
@ -1200,23 +1199,10 @@ dependencies = [
"smol_str", "smol_str",
"stdx", "stdx",
"test_utils", "test_utils",
"text_edit",
"walkdir", "walkdir",
] ]
[[package]]
name = "ra_text_edit"
version = "0.1.0"
dependencies = [
"text-size",
]
[[package]]
name = "ra_toolchain"
version = "0.1.0"
dependencies = [
"home",
]
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.3.1" version = "1.3.1"
@ -1319,15 +1305,15 @@ dependencies = [
"ra_project_model", "ra_project_model",
"ra_ssr", "ra_ssr",
"ra_syntax", "ra_syntax",
"ra_text_edit",
"ra_toolchain",
"rayon", "rayon",
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
"stdx", "stdx",
"test_utils", "test_utils",
"text_edit",
"threadpool", "threadpool",
"toolchain",
"tt", "tt",
"vfs", "vfs",
"vfs-notify", "vfs-notify",
@ -1572,6 +1558,13 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03e7efdedc3bc78cb2337f1e2785c39e45f5ef762d9e4ebb137fff7380a6d8a" checksum = "f03e7efdedc3bc78cb2337f1e2785c39e45f5ef762d9e4ebb137fff7380a6d8a"
[[package]]
name = "text_edit"
version = "0.0.0"
dependencies = [
"text-size",
]
[[package]] [[package]]
name = "thin-dst" name = "thin-dst"
version = "1.1.0" version = "1.1.0"
@ -1612,6 +1605,13 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed"
[[package]]
name = "toolchain"
version = "0.0.0"
dependencies = [
"home",
]
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.18" version = "0.1.18"

View file

@ -14,4 +14,4 @@ log = "0.4.8"
cargo_metadata = "0.11.1" cargo_metadata = "0.11.1"
serde_json = "1.0.48" serde_json = "1.0.48"
jod-thread = "0.1.1" jod-thread = "0.1.1"
ra_toolchain = { path = "../ra_toolchain" } toolchain = { path = "../toolchain" }

View file

@ -193,7 +193,7 @@ impl FlycheckActor {
extra_args, extra_args,
features, features,
} => { } => {
let mut cmd = Command::new(ra_toolchain::cargo()); let mut cmd = Command::new(toolchain::cargo());
cmd.arg(command); cmd.arg(command);
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]) cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
.arg(self.workspace_root.join("Cargo.toml")); .arg(self.workspace_root.join("Cargo.toml"));

View file

@ -16,7 +16,7 @@ either = "1.5.3"
stdx = { path = "../stdx" } stdx = { path = "../stdx" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
ra_fmt = { path = "../ra_fmt" } ra_fmt = { path = "../ra_fmt" }
profile = { path = "../profile" } profile = { path = "../profile" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }

View file

@ -15,7 +15,7 @@ use ra_syntax::{
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
TokenAtOffset, TokenAtOffset,
}; };
use ra_text_edit::TextEditBuilder; use text_edit::{TextEdit, TextEditBuilder};
use crate::{ use crate::{
assist_config::{AssistConfig, SnippetCap}, assist_config::{AssistConfig, SnippetCap},
@ -214,7 +214,7 @@ pub(crate) struct AssistBuilder {
impl AssistBuilder { impl AssistBuilder {
pub(crate) fn new(file_id: FileId) -> AssistBuilder { pub(crate) fn new(file_id: FileId) -> AssistBuilder {
AssistBuilder { AssistBuilder {
edit: TextEditBuilder::default(), edit: TextEdit::builder(),
file_id, file_id,
is_snippet: false, is_snippet: false,
change: SourceChange::default(), change: SourceChange::default(),

View file

@ -2,6 +2,7 @@
// FIXME: rewrite according to the plan, outlined in // FIXME: rewrite according to the plan, outlined in
// https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553 // https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553
use either::Either;
use hir::{self, ModPath}; use hir::{self, ModPath};
use ra_syntax::{ use ra_syntax::{
ast::{self, NameOwner, VisibilityOwner}, ast::{self, NameOwner, VisibilityOwner},
@ -9,10 +10,9 @@ use ra_syntax::{
SyntaxKind::{PATH, PATH_SEGMENT}, SyntaxKind::{PATH, PATH_SEGMENT},
SyntaxNode, T, SyntaxNode, T,
}; };
use ra_text_edit::TextEditBuilder; use text_edit::TextEditBuilder;
use crate::assist_context::AssistContext; use crate::assist_context::AssistContext;
use either::Either;
/// Determines the containing syntax node in which to insert a `use` statement affecting `position`. /// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
pub(crate) fn find_insert_use_container( pub(crate) fn find_insert_use_container(

View file

@ -22,7 +22,7 @@ oorandom = "11.1.2"
stdx = { path = "../stdx" } stdx = { path = "../stdx" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_ide_db = { path = "../ra_ide_db" } ra_ide_db = { path = "../ra_ide_db" }
ra_cfg = { path = "../ra_cfg" } ra_cfg = { path = "../ra_cfg" }

View file

@ -4,7 +4,7 @@ use ra_syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
TextRange, TextSize, TextRange, TextSize,
}; };
use ra_text_edit::TextEdit; use text_edit::TextEdit;
use crate::{ use crate::{
completion::{ completion::{

View file

@ -37,7 +37,7 @@ use ra_syntax::{
ast::{self, edit, Impl}, ast::{self, edit, Impl},
AstNode, SyntaxKind, SyntaxNode, TextRange, T, AstNode, SyntaxKind, SyntaxNode, TextRange, T,
}; };
use ra_text_edit::TextEdit; use text_edit::TextEdit;
use crate::{ use crate::{
completion::{ completion::{

View file

@ -9,7 +9,7 @@ use ra_syntax::{
SyntaxKind::*, SyntaxKind::*,
SyntaxNode, SyntaxToken, TextRange, TextSize, SyntaxNode, SyntaxToken, TextRange, TextSize,
}; };
use ra_text_edit::Indel; use text_edit::Indel;
use super::patterns::{ use super::patterns::{
has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_impl_parent, has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_impl_parent,

View file

@ -4,7 +4,7 @@ use std::fmt;
use hir::Documentation; use hir::Documentation;
use ra_syntax::TextRange; use ra_syntax::TextRange;
use ra_text_edit::TextEdit; use text_edit::TextEdit;
use crate::completion::completion_config::SnippetCap; use crate::completion::completion_config::SnippetCap;

View file

@ -14,7 +14,7 @@ use ra_syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
SyntaxNode, TextRange, T, SyntaxNode, TextRange, T,
}; };
use ra_text_edit::{TextEdit, TextEditBuilder}; use text_edit::TextEdit;
use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; use crate::{Diagnostic, FileId, Fix, SourceFileEdit};
@ -103,7 +103,7 @@ fn check_unnecessary_braces_in_use_statement(
text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree) text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree)
.unwrap_or_else(|| { .unwrap_or_else(|| {
let to_replace = single_use_tree.syntax().text().to_string(); let to_replace = single_use_tree.syntax().text().to_string();
let mut edit_builder = TextEditBuilder::default(); let mut edit_builder = TextEdit::builder();
edit_builder.delete(use_range); edit_builder.delete(use_range);
edit_builder.insert(use_range.start(), to_replace); edit_builder.insert(use_range.start(), to_replace);
edit_builder.finish() edit_builder.finish()
@ -149,7 +149,7 @@ fn check_struct_shorthand_initialization(
let field_expr = expr.syntax().text().to_string(); let field_expr = expr.syntax().text().to_string();
let field_name_is_tup_index = name_ref.as_tuple_field().is_some(); let field_name_is_tup_index = name_ref.as_tuple_field().is_some();
if field_name == field_expr && !field_name_is_tup_index { if field_name == field_expr && !field_name_is_tup_index {
let mut edit_builder = TextEditBuilder::default(); let mut edit_builder = TextEdit::builder();
edit_builder.delete(record_field.syntax().text_range()); edit_builder.delete(record_field.syntax().text_range());
edit_builder.insert(record_field.syntax().text_range().start(), field_name); edit_builder.insert(record_field.syntax().text_range().start(), field_name);
let edit = edit_builder.finish(); let edit = edit_builder.finish();

View file

@ -13,7 +13,7 @@ use ra_ide_db::{
RootDatabase, RootDatabase,
}; };
use ra_syntax::{algo, ast, AstNode}; use ra_syntax::{algo, ast, AstNode};
use ra_text_edit::{TextEdit, TextEditBuilder}; use text_edit::TextEdit;
/// A [Diagnostic] that potentially has a fix available. /// A [Diagnostic] that potentially has a fix available.
/// ///
@ -70,7 +70,7 @@ impl DiagnosticWithFix for MissingFields {
} }
let edit = { let edit = {
let mut builder = TextEditBuilder::default(); let mut builder = TextEdit::builder();
algo::diff(&old_field_list.syntax(), &new_field_list.syntax()) algo::diff(&old_field_list.syntax(), &new_field_list.syntax())
.into_text_edit(&mut builder); .into_text_edit(&mut builder);
builder.finish() builder.finish()

View file

@ -7,7 +7,7 @@ use ra_syntax::{
SyntaxKind::{self, WHITESPACE}, SyntaxKind::{self, WHITESPACE},
SyntaxNode, SyntaxToken, TextRange, TextSize, T, SyntaxNode, SyntaxToken, TextRange, TextSize, T,
}; };
use ra_text_edit::{TextEdit, TextEditBuilder}; use text_edit::{TextEdit, TextEditBuilder};
// Feature: Join Lines // Feature: Join Lines
// //
@ -23,7 +23,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
let syntax = file.syntax(); let syntax = file.syntax();
let text = syntax.text().slice(range.start()..); let text = syntax.text().slice(range.start()..);
let pos = match text.find_char('\n') { let pos = match text.find_char('\n') {
None => return TextEditBuilder::default().finish(), None => return TextEdit::builder().finish(),
Some(pos) => pos, Some(pos) => pos,
}; };
TextRange::at(range.start() + pos, TextSize::of('\n')) TextRange::at(range.start() + pos, TextSize::of('\n'))
@ -35,7 +35,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
NodeOrToken::Node(node) => node, NodeOrToken::Node(node) => node,
NodeOrToken::Token(token) => token.parent(), NodeOrToken::Token(token) => token.parent(),
}; };
let mut edit = TextEditBuilder::default(); let mut edit = TextEdit::builder();
for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) { for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) {
let range = match range.intersect(token.text_range()) { let range = match range.intersect(token.text_range()) {
Some(range) => range, Some(range) => range,

View file

@ -96,7 +96,7 @@ pub use ra_ide_db::{
RootDatabase, RootDatabase,
}; };
pub use ra_ssr::SsrError; pub use ra_ssr::SsrError;
pub use ra_text_edit::{Indel, TextEdit}; pub use text_edit::{Indel, TextEdit};
pub type Cancelable<T> = Result<T, Canceled>; pub type Cancelable<T> = Result<T, Canceled>;

View file

@ -11,9 +11,9 @@ use ra_syntax::{
ast::{self, NameOwner}, ast::{self, NameOwner},
lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken,
}; };
use ra_text_edit::TextEdit;
use std::convert::TryInto; use std::convert::TryInto;
use test_utils::mark; use test_utils::mark;
use text_edit::TextEdit;
use crate::{ use crate::{
references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind,
@ -271,9 +271,9 @@ fn rename_reference(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use expect::{expect, Expect}; use expect::{expect, Expect};
use ra_text_edit::TextEditBuilder;
use stdx::trim_indent; use stdx::trim_indent;
use test_utils::{assert_eq_text, mark}; use test_utils::{assert_eq_text, mark};
use text_edit::TextEdit;
use crate::{mock_analysis::analysis_and_position, FileId}; use crate::{mock_analysis::analysis_and_position, FileId};
@ -281,7 +281,7 @@ mod tests {
let ra_fixture_after = &trim_indent(ra_fixture_after); let ra_fixture_after = &trim_indent(ra_fixture_after);
let (analysis, position) = analysis_and_position(ra_fixture_before); let (analysis, position) = analysis_and_position(ra_fixture_before);
let source_change = analysis.rename(position, new_name).unwrap(); let source_change = analysis.rename(position, new_name).unwrap();
let mut text_edit_builder = TextEditBuilder::default(); let mut text_edit_builder = TextEdit::builder();
let mut file_id: Option<FileId> = None; let mut file_id: Option<FileId> = None;
if let Some(change) = source_change { if let Some(change) = source_change {
for edit in change.info.source_file_edits { for edit in change.info.source_file_edits {

View file

@ -26,7 +26,7 @@ use ra_syntax::{
TextRange, TextSize, TextRange, TextSize,
}; };
use ra_text_edit::TextEdit; use text_edit::TextEdit;
use crate::SourceChange; use crate::SourceChange;

View file

@ -9,8 +9,8 @@ use ra_syntax::{
SyntaxKind::*, SyntaxKind::*,
SyntaxToken, TextRange, TextSize, TokenAtOffset, SyntaxToken, TextRange, TextSize, TokenAtOffset,
}; };
use ra_text_edit::TextEdit;
use test_utils::mark; use test_utils::mark;
use text_edit::TextEdit;
// Feature: On Enter // Feature: On Enter
// //

View file

@ -22,7 +22,7 @@ either = "1.5.3"
stdx = { path = "../stdx" } stdx = { path = "../stdx" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
profile = { path = "../profile" } profile = { path = "../profile" }
test_utils = { path = "../test_utils" } test_utils = { path = "../test_utils" }

View file

@ -4,7 +4,7 @@
//! It can be viewed as a dual for `AnalysisChange`. //! It can be viewed as a dual for `AnalysisChange`.
use ra_db::FileId; use ra_db::FileId;
use ra_text_edit::TextEdit; use text_edit::TextEdit;
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone)]
pub struct SourceChange { pub struct SourceChange {

View file

@ -23,4 +23,4 @@ cargo_metadata = "0.11.1"
difference = "2.0.0" difference = "2.0.0"
# used as proc macro test target # used as proc macro test target
serde_derive = "1.0.106" serde_derive = "1.0.106"
ra_toolchain = { path = "../ra_toolchain" } toolchain = { path = "../toolchain" }

View file

@ -12,7 +12,7 @@ mod fixtures {
// Use current project metadata to get the proc-macro dylib path // Use current project metadata to get the proc-macro dylib path
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf { pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
let command = Command::new(ra_toolchain::cargo()) let command = Command::new(toolchain::cargo())
.args(&["check", "--message-format", "json"]) .args(&["check", "--message-format", "json"])
.output() .output()
.unwrap() .unwrap()

View file

@ -17,7 +17,7 @@ cargo_metadata = "0.11.1"
arena = { path = "../arena" } arena = { path = "../arena" }
ra_cfg = { path = "../ra_cfg" } ra_cfg = { path = "../ra_cfg" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_toolchain = { path = "../ra_toolchain" } toolchain = { path = "../toolchain" }
ra_proc_macro = { path = "../ra_proc_macro" } ra_proc_macro = { path = "../ra_proc_macro" }
paths = { path = "../paths" } paths = { path = "../paths" }
stdx = { path = "../stdx" } stdx = { path = "../stdx" }

View file

@ -140,7 +140,7 @@ impl CargoWorkspace {
cargo_features: &CargoConfig, cargo_features: &CargoConfig,
) -> Result<CargoWorkspace> { ) -> Result<CargoWorkspace> {
let mut meta = MetadataCommand::new(); let mut meta = MetadataCommand::new();
meta.cargo_path(ra_toolchain::cargo()); meta.cargo_path(toolchain::cargo());
meta.manifest_path(cargo_toml.to_path_buf()); meta.manifest_path(cargo_toml.to_path_buf());
if cargo_features.all_features { if cargo_features.all_features {
meta.features(CargoOpt::AllFeatures); meta.features(CargoOpt::AllFeatures);
@ -288,7 +288,7 @@ pub fn load_extern_resources(
cargo_toml: &Path, cargo_toml: &Path,
cargo_features: &CargoConfig, cargo_features: &CargoConfig,
) -> Result<ExternResources> { ) -> Result<ExternResources> {
let mut cmd = Command::new(ra_toolchain::cargo()); let mut cmd = Command::new(toolchain::cargo());
cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
if cargo_features.all_features { if cargo_features.all_features {
cmd.arg("--all-features"); cmd.arg("--all-features");

View file

@ -513,7 +513,7 @@ fn get_rustc_cfg_options(target: Option<&str>) -> Vec<CfgFlag> {
} }
let rustc_cfgs = { let rustc_cfgs = {
let mut cmd = Command::new(ra_toolchain::rustc()); let mut cmd = Command::new(toolchain::rustc());
cmd.args(&["--print", "cfg", "-O"]); cmd.args(&["--print", "cfg", "-O"]);
if let Some(target) = target { if let Some(target) = target {
cmd.args(&["--target", target]); cmd.args(&["--target", target]);

View file

@ -101,13 +101,13 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> {
return Ok(path); return Ok(path);
} }
let current_dir = cargo_toml.parent().unwrap(); let current_dir = cargo_toml.parent().unwrap();
let mut rustc = Command::new(ra_toolchain::rustc()); let mut rustc = Command::new(toolchain::rustc());
rustc.current_dir(current_dir).args(&["--print", "sysroot"]); rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
let stdout = utf8_stdout(rustc)?; let stdout = utf8_stdout(rustc)?;
let sysroot_path = AbsPath::assert(Path::new(stdout.trim())); let sysroot_path = AbsPath::assert(Path::new(stdout.trim()));
let mut src = get_rust_src(sysroot_path); let mut src = get_rust_src(sysroot_path);
if src.is_none() { if src.is_none() {
let mut rustup = Command::new(ra_toolchain::rustup()); let mut rustup = Command::new(toolchain::rustup());
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]); rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
utf8_stdout(rustup)?; utf8_stdout(rustup)?;
src = get_rust_src(sysroot_path); src = get_rust_src(sysroot_path);

View file

@ -11,7 +11,7 @@ repository = "https://github.com/rust-analyzer/rust-analyzer"
doctest = false doctest = false
[dependencies] [dependencies]
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_ide_db = { path = "../ra_ide_db" } ra_ide_db = { path = "../ra_ide_db" }

View file

@ -4,8 +4,8 @@ use crate::matching::Var;
use crate::{resolving::ResolvedRule, Match, SsrMatches}; use crate::{resolving::ResolvedRule, Match, SsrMatches};
use ra_syntax::ast::{self, AstToken}; use ra_syntax::ast::{self, AstToken};
use ra_syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; use ra_syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
use ra_text_edit::TextEdit;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use text_edit::TextEdit;
/// Returns a text edit that will replace each match in `matches` with its corresponding replacement /// Returns a text edit that will replace each match in `matches` with its corresponding replacement
/// template. Placeholders in the template will have been substituted with whatever they matched to /// template. Placeholders in the template will have been substituted with whatever they matched to
@ -24,7 +24,7 @@ fn matches_to_edit_at_offset(
relative_start: TextSize, relative_start: TextSize,
rules: &[ResolvedRule], rules: &[ResolvedRule],
) -> TextEdit { ) -> TextEdit {
let mut edit_builder = ra_text_edit::TextEditBuilder::default(); let mut edit_builder = TextEdit::builder();
for m in &matches.matches { for m in &matches.matches {
edit_builder.replace( edit_builder.replace(
m.range.range.checked_sub(relative_start).unwrap(), m.range.range.checked_sub(relative_start).unwrap(),

View file

@ -20,7 +20,7 @@ once_cell = "1.3.1"
stdx = { path = "../stdx" } stdx = { path = "../stdx" }
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
ra_parser = { path = "../ra_parser" } ra_parser = { path = "../ra_parser" }
# This crate transitively depends on `smol_str` via `rowan`. # This crate transitively depends on `smol_str` via `rowan`.

View file

@ -11,7 +11,7 @@ cargo-fuzz = true
[dependencies] [dependencies]
ra_syntax = { path = ".." } ra_syntax = { path = ".." }
ra_text_edit = { path = "../../ra_text_edit" } text_edit = { path = "../../text_edit" }
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces

View file

@ -6,8 +6,8 @@ use std::{
}; };
use itertools::Itertools; use itertools::Itertools;
use ra_text_edit::TextEditBuilder;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use text_edit::TextEditBuilder;
use crate::{ use crate::{
AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr, AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr,

View file

@ -5,7 +5,7 @@ use std::{
str::{self, FromStr}, str::{self, FromStr},
}; };
use ra_text_edit::Indel; use text_edit::Indel;
use crate::{validation, AstNode, SourceFile, TextRange}; use crate::{validation, AstNode, SourceFile, TextRange};

View file

@ -39,8 +39,8 @@ pub mod fuzz;
use std::{marker::PhantomData, sync::Arc}; use std::{marker::PhantomData, sync::Arc};
use ra_text_edit::Indel;
use stdx::format_to; use stdx::format_to;
use text_edit::Indel;
pub use crate::{ pub use crate::{
algo::InsertPosition, algo::InsertPosition,

View file

@ -7,7 +7,7 @@
//! and try to parse only this block. //! and try to parse only this block.
use ra_parser::Reparser; use ra_parser::Reparser;
use ra_text_edit::Indel; use text_edit::Indel;
use crate::{ use crate::{
algo, algo,

View file

@ -39,11 +39,11 @@ ra_ide = { path = "../ra_ide" }
profile = { path = "../profile" } profile = { path = "../profile" }
ra_project_model = { path = "../ra_project_model" } ra_project_model = { path = "../ra_project_model" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_text_edit = { path = "../ra_text_edit" } text_edit = { path = "../text_edit" }
vfs = { path = "../vfs" } vfs = { path = "../vfs" }
vfs-notify = { path = "../vfs-notify" } vfs-notify = { path = "../vfs-notify" }
ra_cfg = { path = "../ra_cfg" } ra_cfg = { path = "../ra_cfg" }
ra_toolchain = { path = "../ra_toolchain" } toolchain = { path = "../toolchain" }
# This should only be used in CLI # This should only be used in CLI
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }

View file

@ -692,7 +692,7 @@ pub(crate) fn handle_formatting(
let mut rustfmt = match &snap.config.rustfmt { let mut rustfmt = match &snap.config.rustfmt {
RustfmtConfig::Rustfmt { extra_args } => { RustfmtConfig::Rustfmt { extra_args } => {
let mut cmd = process::Command::new(ra_toolchain::rustfmt()); let mut cmd = process::Command::new(toolchain::rustfmt());
cmd.args(extra_args); cmd.args(extra_args);
if let Some(&crate_id) = crate_ids.first() { if let Some(&crate_id) = crate_ids.first() {
// Assume all crates are in the same edition // Assume all crates are in the same edition

View file

@ -1,10 +1,9 @@
[package] [package]
edition = "2018" name = "text_edit"
name = "ra_text_edit" version = "0.0.0"
version = "0.1.0"
authors = ["rust-analyzer developers"]
publish = false
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib] [lib]
doctest = false doctest = false

View file

@ -3,8 +3,6 @@
//! `rust-analyzer` never mutates text itself and only sends diffs to clients, //! `rust-analyzer` never mutates text itself and only sends diffs to clients,
//! so `TextEdit` is the ultimate representation of the work done by //! so `TextEdit` is the ultimate representation of the work done by
//! rust-analyzer. //! rust-analyzer.
use std::{slice, vec};
pub use text_size::{TextRange, TextSize}; pub use text_size::{TextRange, TextSize};
/// `InsertDelete` -- a single "atomic" change to text /// `InsertDelete` -- a single "atomic" change to text
@ -46,20 +44,24 @@ impl Indel {
} }
impl TextEdit { impl TextEdit {
pub fn builder() -> TextEditBuilder {
TextEditBuilder::default()
}
pub fn insert(offset: TextSize, text: String) -> TextEdit { pub fn insert(offset: TextSize, text: String) -> TextEdit {
let mut builder = TextEditBuilder::default(); let mut builder = TextEdit::builder();
builder.insert(offset, text); builder.insert(offset, text);
builder.finish() builder.finish()
} }
pub fn delete(range: TextRange) -> TextEdit { pub fn delete(range: TextRange) -> TextEdit {
let mut builder = TextEditBuilder::default(); let mut builder = TextEdit::builder();
builder.delete(range); builder.delete(range);
builder.finish() builder.finish()
} }
pub fn replace(range: TextRange, replace_with: String) -> TextEdit { pub fn replace(range: TextRange, replace_with: String) -> TextEdit {
let mut builder = TextEditBuilder::default(); let mut builder = TextEdit::builder();
builder.replace(range, replace_with); builder.replace(range, replace_with);
builder.finish() builder.finish()
} }
@ -72,8 +74,8 @@ impl TextEdit {
self.indels.is_empty() self.indels.is_empty()
} }
pub fn iter(&self) -> slice::Iter<'_, Indel> { pub fn iter(&self) -> std::slice::Iter<'_, Indel> {
self.indels.iter() self.into_iter()
} }
pub fn apply(&self, text: &mut String) { pub fn apply(&self, text: &mut String) {
@ -139,13 +141,22 @@ impl TextEdit {
impl IntoIterator for TextEdit { impl IntoIterator for TextEdit {
type Item = Indel; type Item = Indel;
type IntoIter = vec::IntoIter<Self::Item>; type IntoIter = std::vec::IntoIter<Indel>;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.indels.into_iter() self.indels.into_iter()
} }
} }
impl<'a> IntoIterator for &'a TextEdit {
type Item = &'a Indel;
type IntoIter = std::slice::Iter<'a, Indel>;
fn into_iter(self) -> Self::IntoIter {
self.indels.iter()
}
}
impl TextEditBuilder { impl TextEditBuilder {
pub fn replace(&mut self, range: TextRange, replace_with: String) { pub fn replace(&mut self, range: TextRange, replace_with: String) {
self.indels.push(Indel::replace(range, replace_with)) self.indels.push(Indel::replace(range, replace_with))

View file

@ -1,9 +1,9 @@
[package] [package]
edition = "2018" name = "toolchain"
name = "ra_toolchain" version = "0.0.0"
version = "0.1.0"
authors = ["rust-analyzer developers"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib] [lib]
doctest = false doctest = false

View file

@ -1,6 +1,4 @@
//! This crate contains a single public function //! Discovery of `cargo` & `rustc` executables.
//! [`get_path_for_executable`](fn.get_path_for_executable.html).
//! See docs there for more information.
use std::{env, iter, path::PathBuf}; use std::{env, iter, path::PathBuf};
pub fn cargo() -> PathBuf { pub fn cargo() -> PathBuf {

View file

@ -121,12 +121,12 @@ export class Cargo {
} }
} }
/** Mirrors `ra_toolchain::cargo()` implementation */ /** Mirrors `toolchain::cargo()` implementation */
export function cargoPath(): string { export function cargoPath(): string {
return getPathForExecutable("cargo"); return getPathForExecutable("cargo");
} }
/** Mirrors `ra_toolchain::get_path_for_executable()` implementation */ /** Mirrors `toolchain::get_path_for_executable()` implementation */
export const getPathForExecutable = memoize( export const getPathForExecutable = memoize(
// We apply caching to decrease file-system interactions // We apply caching to decrease file-system interactions
(executableName: "cargo" | "rustc" | "rustup"): string => { (executableName: "cargo" | "rustc" | "rustup"): string => {