Skip to content

Commit 8672eb8

Browse files
authored
Merge pull request #18421 from Veykril/push-uxxwvwnqvomr
Move text-edit into ide-db
2 parents 09547e9 + 27306c5 commit 8672eb8

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

Cargo.lock

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
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" }

crates/ide-assists/Cargo.toml

Lines changed: 0 additions & 1 deletion
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

crates/ide-assists/src/handlers/bool_to_enum.rs

Lines changed: 1 addition & 1 deletion
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},

crates/ide-assists/src/handlers/destructure_struct_binding.rs

Lines changed: 1 addition & 1 deletion
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},

crates/ide-assists/src/handlers/destructure_tuple_binding.rs

Lines changed: 1 addition & 1 deletion
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},

crates/ide-assists/src/handlers/remove_unused_imports.rs

Lines changed: 1 addition & 1 deletion
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

crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs

Lines changed: 1 addition & 1 deletion
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

crates/ide-completion/Cargo.toml

Lines changed: 0 additions & 1 deletion
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

crates/ide-completion/src/completions/item_list/trait_impl.rs

Lines changed: 1 addition & 1 deletion
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,

crates/ide-completion/src/completions/postfix.rs

Lines changed: 1 addition & 1 deletion
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,

crates/ide-completion/src/context.rs

Lines changed: 1 addition & 3 deletions
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

crates/ide-completion/src/item.rs

Lines changed: 6 additions & 3 deletions
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
})

crates/ide-completion/src/lib.rs

Lines changed: 5 additions & 4 deletions
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
}

crates/ide-completion/src/render.rs

Lines changed: 1 addition & 1 deletion
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},

crates/ide-db/Cargo.toml

Lines changed: 0 additions & 1 deletion
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`.

crates/ide-db/src/documentation.rs

Lines changed: 1 addition & 1 deletion
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)]

crates/ide-db/src/lib.rs

Lines changed: 2 additions & 0 deletions
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;

crates/ide-db/src/rename.rs

Lines changed: 1 addition & 1 deletion
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)