Skip to content

Commit 8e97f40

Browse files
authored
Merge pull request rust-lang#18421 from Veykril/push-uxxwvwnqvomr
Move text-edit into ide-db
2 parents b12859a + 86ae80c commit 8e97f40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+684
-707
lines changed

Diff for: src/tools/rust-analyzer/Cargo.lock

-15
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ dependencies = [
671671
"syntax",
672672
"test-fixture",
673673
"test-utils",
674-
"text-edit",
675674
"toolchain",
676675
"tracing",
677676
"triomphe",
@@ -693,7 +692,6 @@ dependencies = [
693692
"syntax",
694693
"test-fixture",
695694
"test-utils",
696-
"text-edit",
697695
"tracing",
698696
]
699697

@@ -712,7 +710,6 @@ dependencies = [
712710
"syntax",
713711
"test-fixture",
714712
"test-utils",
715-
"text-edit",
716713
"tracing",
717714
]
718715

@@ -744,7 +741,6 @@ dependencies = [
744741
"syntax",
745742
"test-fixture",
746743
"test-utils",
747-
"text-edit",
748744
"tracing",
749745
"triomphe",
750746
]
@@ -766,7 +762,6 @@ dependencies = [
766762
"syntax",
767763
"test-fixture",
768764
"test-utils",
769-
"text-edit",
770765
"tracing",
771766
]
772767

@@ -785,7 +780,6 @@ dependencies = [
785780
"syntax",
786781
"test-fixture",
787782
"test-utils",
788-
"text-edit",
789783
"triomphe",
790784
]
791785

@@ -1979,7 +1973,6 @@ dependencies = [
19791973
"smol_str",
19801974
"stdx",
19811975
"test-utils",
1982-
"text-edit",
19831976
"tracing",
19841977
"triomphe",
19851978
]
@@ -2027,14 +2020,6 @@ dependencies = [
20272020
"tracing",
20282021
]
20292022

2030-
[[package]]
2031-
name = "text-edit"
2032-
version = "0.0.0"
2033-
dependencies = [
2034-
"itertools",
2035-
"text-size",
2036-
]
2037-
20382023
[[package]]
20392024
name = "text-size"
20402025
version = "1.1.1"

Diff for: src/tools/rust-analyzer/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ span = { path = "./crates/span", version = "0.0.0" }
7979
stdx = { path = "./crates/stdx", version = "0.0.0" }
8080
syntax = { path = "./crates/syntax", version = "0.0.0" }
8181
syntax-bridge = { path = "./crates/syntax-bridge", version = "0.0.0" }
82-
text-edit = { path = "./crates/text-edit", version = "0.0.0" }
8382
toolchain = { path = "./crates/toolchain", version = "0.0.0" }
8483
tt = { path = "./crates/tt", version = "0.0.0" }
8584
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }

Diff for: src/tools/rust-analyzer/crates/ide-assists/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ tracing.workspace = true
2323
# local deps
2424
stdx.workspace = true
2525
syntax.workspace = true
26-
text-edit.workspace = true
2726
ide-db.workspace = true
2827
hir.workspace = true
2928

Diff for: src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use either::Either;
22
use hir::ModuleDef;
3+
use ide_db::text_edit::TextRange;
34
use ide_db::{
45
assists::{AssistId, AssistKind},
56
defs::Definition,
@@ -19,7 +20,6 @@ use syntax::{
1920
},
2021
AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T,
2122
};
22-
use text_edit::TextRange;
2323

2424
use crate::{
2525
assist_context::{AssistContext, Assists},

Diff for: src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_struct_binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use hir::{sym, HasVisibility};
2+
use ide_db::text_edit::TextRange;
23
use ide_db::{
34
assists::{AssistId, AssistKind},
45
defs::Definition,
@@ -8,7 +9,6 @@ use ide_db::{
89
};
910
use itertools::Itertools;
1011
use syntax::{ast, ted, AstNode, Edition, SmolStr, SyntaxNode, ToSmolStr};
11-
use text_edit::TextRange;
1212

1313
use crate::{
1414
assist_context::{AssistContext, Assists, SourceChangeBuilder},

Diff for: src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_tuple_binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ide_db::text_edit::TextRange;
12
use ide_db::{
23
assists::{AssistId, AssistKind},
34
defs::Definition,
@@ -8,7 +9,6 @@ use syntax::{
89
ast::{self, make, AstNode, FieldExpr, HasName, IdentPat},
910
ted,
1011
};
11-
use text_edit::TextRange;
1212

1313
use crate::{
1414
assist_context::{AssistContext, Assists, SourceChangeBuilder},

Diff for: src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::hash_map::Entry;
22

33
use hir::{FileRange, HirFileIdExt, InFile, InRealFile, Module, ModuleSource};
4+
use ide_db::text_edit::TextRange;
45
use ide_db::{
56
defs::Definition,
67
search::{FileReference, ReferenceCategory, SearchScope},
@@ -10,7 +11,6 @@ use syntax::{
1011
ast::{self, Rename},
1112
AstNode,
1213
};
13-
use text_edit::TextRange;
1414

1515
use crate::{AssistContext, AssistId, AssistKind, Assists};
1616

Diff for: src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use hir::{FileRange, Semantics};
2+
use ide_db::text_edit::TextRange;
23
use ide_db::{
34
defs::Definition,
45
search::{SearchScope, UsageSearchResult},
@@ -11,7 +12,6 @@ use syntax::{
1112
},
1213
match_ast, ted, AstNode,
1314
};
14-
use text_edit::TextRange;
1515

1616
use crate::{AssistContext, AssistId, AssistKind, Assists};
1717

Diff for: src/tools/rust-analyzer/crates/ide-completion/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ base-db.workspace = true
2525
ide-db.workspace = true
2626
stdx.workspace = true
2727
syntax.workspace = true
28-
text-edit.workspace = true
2928
# completions crate should depend only on the top-level `hir` package. if you need
3029
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
3130
hir.workspace = true

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//! ```
3333
3434
use hir::{db::ExpandDatabase, HasAttrs, MacroFileId, Name};
35+
use ide_db::text_edit::TextEdit;
3536
use ide_db::{
3637
documentation::HasDocs, path_transform::PathTransform,
3738
syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items, SymbolKind,
@@ -40,7 +41,6 @@ use syntax::{
4041
ast::{self, edit_in_place::AttrsOwnerEdit, make, HasGenericArgs, HasTypeBounds},
4142
format_smolstr, ted, AstNode, SmolStr, SyntaxElement, SyntaxKind, TextRange, ToSmolStr, T,
4243
};
43-
use text_edit::TextEdit;
4444

4545
use crate::{
4646
context::PathCompletionCtx, CompletionContext, CompletionItem, CompletionItemKind,

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod format_like;
44

55
use hir::ItemInNs;
6+
use ide_db::text_edit::TextEdit;
67
use ide_db::{
78
documentation::{Documentation, HasDocs},
89
imports::insert_use::ImportScope,
@@ -15,7 +16,6 @@ use syntax::{
1516
SyntaxKind::{BLOCK_EXPR, EXPR_STMT, FOR_EXPR, IF_EXPR, LOOP_EXPR, STMT_LIST, WHILE_EXPR},
1617
TextRange, TextSize,
1718
};
18-
use text_edit::TextEdit;
1919

2020
use crate::{
2121
completions::postfix::format_like::add_format_like_completions,

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/context.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use syntax::{
2020
SyntaxKind::{self, *},
2121
SyntaxToken, TextRange, TextSize, T,
2222
};
23-
use text_edit::Indel;
2423

2524
use crate::{
2625
context::analysis::{expand_and_analyze, AnalysisResult},
@@ -684,8 +683,7 @@ impl<'a> CompletionContext<'a> {
684683
// actual completion.
685684
let file_with_fake_ident = {
686685
let parse = db.parse(file_id);
687-
let edit = Indel::insert(offset, COMPLETION_MARKER.to_owned());
688-
parse.reparse(&edit, file_id.edition()).tree()
686+
parse.reparse(TextRange::empty(offset), COMPLETION_MARKER, file_id.edition()).tree()
689687
};
690688

691689
// always pick the token to the immediate left of the cursor, as that is what we are actually

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/item.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::{fmt, mem};
44

55
use hir::Mutability;
6+
use ide_db::text_edit::TextEdit;
67
use ide_db::{
78
documentation::Documentation, imports::import_assets::LocatedImport, RootDatabase, SnippetCap,
89
SymbolKind,
@@ -11,7 +12,6 @@ use itertools::Itertools;
1112
use smallvec::SmallVec;
1213
use stdx::{impl_from, never};
1314
use syntax::{format_smolstr, Edition, SmolStr, TextRange, TextSize};
14-
use text_edit::TextEdit;
1515

1616
use crate::{
1717
context::{CompletionContext, PathCompletionCtx},
@@ -426,7 +426,7 @@ impl CompletionItem {
426426
self.lookup.as_str()
427427
}
428428

429-
pub fn ref_match(&self) -> Option<(String, text_edit::Indel, CompletionRelevance)> {
429+
pub fn ref_match(&self) -> Option<(String, ide_db::text_edit::Indel, CompletionRelevance)> {
430430
// Relevance of the ref match should be the same as the original
431431
// match, but with exact type match set because self.ref_match
432432
// is only set if there is an exact type match.
@@ -436,7 +436,10 @@ impl CompletionItem {
436436
self.ref_match.map(|(mutability, offset)| {
437437
(
438438
format!("&{}{}", mutability.as_keyword_for_ref(), self.label),
439-
text_edit::Indel::insert(offset, format!("&{}", mutability.as_keyword_for_ref())),
439+
ide_db::text_edit::Indel::insert(
440+
offset,
441+
format!("&{}", mutability.as_keyword_for_ref()),
442+
),
440443
relevance,
441444
)
442445
})

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ mod snippet;
1010
#[cfg(test)]
1111
mod tests;
1212

13+
use ide_db::text_edit::TextEdit;
1314
use ide_db::{
1415
helpers::mod_path_to_ast,
1516
imports::{
1617
import_assets::NameToImport,
1718
insert_use::{self, ImportScope},
1819
},
19-
items_locator, FilePosition, RootDatabase,
20+
items_locator,
21+
syntax_helpers::tree_diff::diff,
22+
FilePosition, RootDatabase,
2023
};
21-
use syntax::algo;
22-
use text_edit::TextEdit;
2324

2425
use crate::{
2526
completions::Completions,
@@ -297,6 +298,6 @@ pub fn resolve_completion_edits(
297298
}
298299
});
299300

300-
algo::diff(scope.as_syntax_node(), new_ast.as_syntax_node()).into_text_edit(&mut import_insert);
301+
diff(scope.as_syntax_node(), new_ast.as_syntax_node()).into_text_edit(&mut import_insert);
301302
Some(vec![import_insert.finish()])
302303
}

Diff for: src/tools/rust-analyzer/crates/ide-completion/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ pub(crate) mod union_literal;
1111
pub(crate) mod variant;
1212

1313
use hir::{sym, AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type};
14+
use ide_db::text_edit::TextEdit;
1415
use ide_db::{
1516
documentation::{Documentation, HasDocs},
1617
helpers::item_name,
1718
imports::import_assets::LocatedImport,
1819
RootDatabase, SnippetCap, SymbolKind,
1920
};
2021
use syntax::{ast, format_smolstr, AstNode, Edition, SmolStr, SyntaxKind, TextRange, ToSmolStr};
21-
use text_edit::TextEdit;
2222

2323
use crate::{
2424
context::{DotAccess, DotAccessKind, PathCompletionCtx, PathKind, PatternContext},

Diff for: src/tools/rust-analyzer/crates/ide-db/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ parser.workspace = true
3535
profile.workspace = true
3636
stdx.workspace = true
3737
syntax.workspace = true
38-
text-edit.workspace = true
3938
span.workspace = true
4039
# ide should depend only on the top-level `hir` package. if you need
4140
# something from some `hir-xxx` subpackage, reexport the API via `hir`.

Diff for: src/tools/rust-analyzer/crates/ide-db/src/documentation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use hir::{
55
resolve_doc_path_on, sym, AttrId, AttrSourceMap, AttrsWithOwner, HasAttrs, InFile,
66
};
77
use itertools::Itertools;
8+
use span::{TextRange, TextSize};
89
use syntax::{
910
ast::{self, IsString},
1011
AstToken,
1112
};
12-
use text_edit::{TextRange, TextSize};
1313

1414
/// Holds documentation
1515
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

Diff for: src/tools/rust-analyzer/crates/ide-db/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod rust_doc;
1919
pub mod search;
2020
pub mod source_change;
2121
pub mod symbol_index;
22+
pub mod text_edit;
2223
pub mod traits;
2324
pub mod ty_filter;
2425
pub mod use_trivial_constructor;
@@ -36,6 +37,7 @@ pub mod generated {
3637
pub mod syntax_helpers {
3738
pub mod format_string;
3839
pub mod format_string_exprs;
40+
pub mod tree_diff;
3941
pub use hir::prettify_macro_expansion;
4042
pub mod node_ext;
4143
pub mod suggest_name;

Diff for: src/tools/rust-analyzer/crates/ide-db/src/rename.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! Our current behavior is ¯\_(ツ)_/¯.
2323
use std::fmt;
2424

25+
use crate::text_edit::{TextEdit, TextEditBuilder};
2526
use base_db::AnchoredPathBuf;
2627
use either::Either;
2728
use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics};
@@ -32,7 +33,6 @@ use syntax::{
3233
utils::is_raw_identifier,
3334
AstNode, SyntaxKind, TextRange, T,
3435
};
35-
use text_edit::{TextEdit, TextEditBuilder};
3636

3737
use crate::{
3838
defs::Definition,

0 commit comments

Comments
 (0)