Skip to content

Commit

Permalink
Merge pull request #18421 from Veykril/push-uxxwvwnqvomr
Browse files Browse the repository at this point in the history
Move text-edit into ide-db
  • Loading branch information
Veykril authored Oct 28, 2024
2 parents 09547e9 + 27306c5 commit 8672eb8
Show file tree
Hide file tree
Showing 63 changed files with 684 additions and 707 deletions.
15 changes: 0 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ span = { path = "./crates/span", version = "0.0.0" }
stdx = { path = "./crates/stdx", version = "0.0.0" }
syntax = { path = "./crates/syntax", version = "0.0.0" }
syntax-bridge = { path = "./crates/syntax-bridge", version = "0.0.0" }
text-edit = { path = "./crates/text-edit", version = "0.0.0" }
toolchain = { path = "./crates/toolchain", version = "0.0.0" }
tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
Expand Down
1 change: 0 additions & 1 deletion crates/ide-assists/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ tracing.workspace = true
# local deps
stdx.workspace = true
syntax.workspace = true
text-edit.workspace = true
ide-db.workspace = true
hir.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/bool_to_enum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use either::Either;
use hir::ModuleDef;
use ide_db::text_edit::TextRange;
use ide_db::{
assists::{AssistId, AssistKind},
defs::Definition,
Expand All @@ -19,7 +20,6 @@ use syntax::{
},
AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T,
};
use text_edit::TextRange;

use crate::{
assist_context::{AssistContext, Assists},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hir::{sym, HasVisibility};
use ide_db::text_edit::TextRange;
use ide_db::{
assists::{AssistId, AssistKind},
defs::Definition,
Expand All @@ -8,7 +9,6 @@ use ide_db::{
};
use itertools::Itertools;
use syntax::{ast, ted, AstNode, Edition, SmolStr, SyntaxNode, ToSmolStr};
use text_edit::TextRange;

use crate::{
assist_context::{AssistContext, Assists, SourceChangeBuilder},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ide_db::text_edit::TextRange;
use ide_db::{
assists::{AssistId, AssistKind},
defs::Definition,
Expand All @@ -8,7 +9,6 @@ use syntax::{
ast::{self, make, AstNode, FieldExpr, HasName, IdentPat},
ted,
};
use text_edit::TextRange;

use crate::{
assist_context::{AssistContext, Assists, SourceChangeBuilder},
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/remove_unused_imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::hash_map::Entry;

use hir::{FileRange, HirFileIdExt, InFile, InRealFile, Module, ModuleSource};
use ide_db::text_edit::TextRange;
use ide_db::{
defs::Definition,
search::{FileReference, ReferenceCategory, SearchScope},
Expand All @@ -10,7 +11,6 @@ use syntax::{
ast::{self, Rename},
AstNode,
};
use text_edit::TextRange;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hir::{FileRange, Semantics};
use ide_db::text_edit::TextRange;
use ide_db::{
defs::Definition,
search::{SearchScope, UsageSearchResult},
Expand All @@ -11,7 +12,6 @@ use syntax::{
},
match_ast, ted, AstNode,
};
use text_edit::TextRange;

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

Expand Down
1 change: 0 additions & 1 deletion crates/ide-completion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ base-db.workspace = true
ide-db.workspace = true
stdx.workspace = true
syntax.workspace = true
text-edit.workspace = true
# completions crate should depend only on the top-level `hir` package. if you need
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
hir.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
//! ```
use hir::{db::ExpandDatabase, HasAttrs, MacroFileId, Name};
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::HasDocs, path_transform::PathTransform,
syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items, SymbolKind,
Expand All @@ -40,7 +41,6 @@ use syntax::{
ast::{self, edit_in_place::AttrsOwnerEdit, make, HasGenericArgs, HasTypeBounds},
format_smolstr, ted, AstNode, SmolStr, SyntaxElement, SyntaxKind, TextRange, ToSmolStr, T,
};
use text_edit::TextEdit;

use crate::{
context::PathCompletionCtx, CompletionContext, CompletionItem, CompletionItemKind,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/completions/postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod format_like;

use hir::ItemInNs;
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::{Documentation, HasDocs},
imports::insert_use::ImportScope,
Expand All @@ -15,7 +16,6 @@ use syntax::{
SyntaxKind::{BLOCK_EXPR, EXPR_STMT, FOR_EXPR, IF_EXPR, LOOP_EXPR, STMT_LIST, WHILE_EXPR},
TextRange, TextSize,
};
use text_edit::TextEdit;

use crate::{
completions::postfix::format_like::add_format_like_completions,
Expand Down
4 changes: 1 addition & 3 deletions crates/ide-completion/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use syntax::{
SyntaxKind::{self, *},
SyntaxToken, TextRange, TextSize, T,
};
use text_edit::Indel;

use crate::{
context::analysis::{expand_and_analyze, AnalysisResult},
Expand Down Expand Up @@ -684,8 +683,7 @@ impl<'a> CompletionContext<'a> {
// actual completion.
let file_with_fake_ident = {
let parse = db.parse(file_id);
let edit = Indel::insert(offset, COMPLETION_MARKER.to_owned());
parse.reparse(&edit, file_id.edition()).tree()
parse.reparse(TextRange::empty(offset), COMPLETION_MARKER, file_id.edition()).tree()
};

// always pick the token to the immediate left of the cursor, as that is what we are actually
Expand Down
9 changes: 6 additions & 3 deletions crates/ide-completion/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{fmt, mem};

use hir::Mutability;
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::Documentation, imports::import_assets::LocatedImport, RootDatabase, SnippetCap,
SymbolKind,
Expand All @@ -11,7 +12,6 @@ use itertools::Itertools;
use smallvec::SmallVec;
use stdx::{impl_from, never};
use syntax::{format_smolstr, Edition, SmolStr, TextRange, TextSize};
use text_edit::TextEdit;

use crate::{
context::{CompletionContext, PathCompletionCtx},
Expand Down Expand Up @@ -426,7 +426,7 @@ impl CompletionItem {
self.lookup.as_str()
}

pub fn ref_match(&self) -> Option<(String, text_edit::Indel, CompletionRelevance)> {
pub fn ref_match(&self) -> Option<(String, ide_db::text_edit::Indel, CompletionRelevance)> {
// Relevance of the ref match should be the same as the original
// match, but with exact type match set because self.ref_match
// is only set if there is an exact type match.
Expand All @@ -436,7 +436,10 @@ impl CompletionItem {
self.ref_match.map(|(mutability, offset)| {
(
format!("&{}{}", mutability.as_keyword_for_ref(), self.label),
text_edit::Indel::insert(offset, format!("&{}", mutability.as_keyword_for_ref())),
ide_db::text_edit::Indel::insert(
offset,
format!("&{}", mutability.as_keyword_for_ref()),
),
relevance,
)
})
Expand Down
9 changes: 5 additions & 4 deletions crates/ide-completion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ mod snippet;
#[cfg(test)]
mod tests;

use ide_db::text_edit::TextEdit;
use ide_db::{
helpers::mod_path_to_ast,
imports::{
import_assets::NameToImport,
insert_use::{self, ImportScope},
},
items_locator, FilePosition, RootDatabase,
items_locator,
syntax_helpers::tree_diff::diff,
FilePosition, RootDatabase,
};
use syntax::algo;
use text_edit::TextEdit;

use crate::{
completions::Completions,
Expand Down Expand Up @@ -297,6 +298,6 @@ pub fn resolve_completion_edits(
}
});

algo::diff(scope.as_syntax_node(), new_ast.as_syntax_node()).into_text_edit(&mut import_insert);
diff(scope.as_syntax_node(), new_ast.as_syntax_node()).into_text_edit(&mut import_insert);
Some(vec![import_insert.finish()])
}
2 changes: 1 addition & 1 deletion crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub(crate) mod union_literal;
pub(crate) mod variant;

use hir::{sym, AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type};
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::{Documentation, HasDocs},
helpers::item_name,
imports::import_assets::LocatedImport,
RootDatabase, SnippetCap, SymbolKind,
};
use syntax::{ast, format_smolstr, AstNode, Edition, SmolStr, SyntaxKind, TextRange, ToSmolStr};
use text_edit::TextEdit;

use crate::{
context::{DotAccess, DotAccessKind, PathCompletionCtx, PathKind, PatternContext},
Expand Down
1 change: 0 additions & 1 deletion crates/ide-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ parser.workspace = true
profile.workspace = true
stdx.workspace = true
syntax.workspace = true
text-edit.workspace = true
span.workspace = true
# ide should depend only on the top-level `hir` package. if you need
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use hir::{
resolve_doc_path_on, sym, AttrId, AttrSourceMap, AttrsWithOwner, HasAttrs, InFile,
};
use itertools::Itertools;
use span::{TextRange, TextSize};
use syntax::{
ast::{self, IsString},
AstToken,
};
use text_edit::{TextRange, TextSize};

/// Holds documentation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
2 changes: 2 additions & 0 deletions crates/ide-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod rust_doc;
pub mod search;
pub mod source_change;
pub mod symbol_index;
pub mod text_edit;
pub mod traits;
pub mod ty_filter;
pub mod use_trivial_constructor;
Expand All @@ -36,6 +37,7 @@ pub mod generated {
pub mod syntax_helpers {
pub mod format_string;
pub mod format_string_exprs;
pub mod tree_diff;
pub use hir::prettify_macro_expansion;
pub mod node_ext;
pub mod suggest_name;
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! Our current behavior is ¯\_(ツ)_/¯.
use std::fmt;

use crate::text_edit::{TextEdit, TextEditBuilder};
use base_db::AnchoredPathBuf;
use either::Either;
use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics};
Expand All @@ -32,7 +33,6 @@ use syntax::{
utils::is_raw_identifier,
AstNode, SyntaxKind, TextRange, T,
};
use text_edit::{TextEdit, TextEditBuilder};

use crate::{
defs::Definition,
Expand Down
Loading

0 comments on commit 8672eb8

Please sign in to comment.