Rename UseItem -> Use

This commit is contained in:
Aleksey Kladov 2020-07-30 14:12:04 +02:00
parent e381c02ef3
commit b1332670c7
18 changed files with 43 additions and 42 deletions

View file

@ -92,7 +92,7 @@ impl AutoImportAssets {
fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> {
let syntax_under_caret = path_under_caret.syntax().to_owned();
if syntax_under_caret.ancestors().find_map(ast::UseItem::cast).is_some() {
if syntax_under_caret.ancestors().find_map(ast::Use::cast).is_some() {
return None;
}

View file

@ -28,7 +28,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
let mut rewriter = SyntaxRewriter::default();
let mut offset = ctx.offset();
if let Some(use_item) = tree.syntax().parent().and_then(ast::UseItem::cast) {
if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
let (merged, to_delete) = next_prev()
.filter_map(|dir| neighbor(&use_item, dir))
.filter_map(|it| Some((it.clone(), it.use_tree()?)))

View file

@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use(
) -> Option<()> {
let path: ast::Path = ctx.find_node_at_offset()?;
// We don't want to mess with use statements
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {
if path.syntax().ancestors().find_map(ast::Use::cast).is_some() {
return None;
}
@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path:
match child {
// Don't modify `use` items, as this can break the `use` item when injecting a new
// import into the use tree.
ast::UseItem(_it) => continue,
ast::Use(_it) => continue,
// Don't descend into submodules, they don't have the same `use` items in scope.
ast::Module(_it) => continue,

View file

@ -225,7 +225,7 @@ fn walk_use_tree_for_best_action(
current_use_tree
.syntax()
.ancestors()
.find_map(ast::UseItem::cast)
.find_map(ast::Use::cast)
.map(|it| it.syntax().clone()),
true,
);
@ -254,7 +254,7 @@ fn walk_use_tree_for_best_action(
current_use_tree
.syntax()
.ancestors()
.find_map(ast::UseItem::cast)
.find_map(ast::Use::cast)
.map(|it| it.syntax().clone()),
true,
),
@ -304,7 +304,7 @@ fn walk_use_tree_for_best_action(
current_use_tree
.syntax()
.ancestors()
.find_map(ast::UseItem::cast)
.find_map(ast::Use::cast)
.map(|it| it.syntax().clone()),
true,
);
@ -377,7 +377,7 @@ fn best_action_for_target(
let mut storage = Vec::with_capacity(16); // this should be the only allocation
let best_action = container
.children()
.filter_map(ast::UseItem::cast)
.filter_map(ast::Use::cast)
.filter_map(|it| it.use_tree())
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
.fold(None, |best, a| match best {

View file

@ -670,7 +670,7 @@ impl ExprCollector<'_> {
}
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
ast::Item::ImplDef(_)
| ast::Item::UseItem(_)
| ast::Item::Use(_)
| ast::Item::ExternCrate(_)
| ast::Item::Module(_)
| ast::Item::MacroCall(_) => return None,

View file

@ -411,7 +411,7 @@ macro_rules! mod_items {
}
mod_items! {
Import in imports -> ast::UseItem,
Import in imports -> ast::Use,
ExternCrate in extern_crates -> ast::ExternCrate,
Function in functions -> ast::FnDef,
Struct in structs -> ast::StructDef,
@ -482,7 +482,7 @@ pub struct Import {
pub is_prelude: bool,
/// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
/// `Import`s can map to the same `use` item.
pub ast_id: FileAstId<ast::UseItem>,
pub ast_id: FileAstId<ast::Use>,
}
#[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -95,7 +95,7 @@ impl Ctx {
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
// These don't have inner items.
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::UseItem(_) => {}
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
};
let attrs = Attrs::new(item, &self.hygiene);
@ -110,7 +110,7 @@ impl Ctx {
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
ast::Item::UseItem(ast) => Some(ModItems(
ast::Item::Use(ast) => Some(ModItems(
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
)),
ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into),
@ -469,7 +469,7 @@ impl Ctx {
Some(id(self.data().impls.alloc(res)))
}
fn lower_use(&mut self, use_item: &ast::UseItem) -> Vec<FileItemTreeId<Import>> {
fn lower_use(&mut self, use_item: &ast::Use) -> Vec<FileItemTreeId<Import>> {
// FIXME: cfg_attr
let is_prelude = use_item.has_atom_attr("prelude_import");
let visibility = self.lower_visibility(use_item);

View file

@ -67,7 +67,7 @@ impl ModPath {
/// Calls `cb` with all paths, represented by this use item.
pub(crate) fn expand_use_item(
item_src: InFile<ast::UseItem>,
item_src: InFile<ast::Use>,
hygiene: &Hygiene,
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
) {

View file

@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> {
pub(super) expected_type: Option<Type>,
pub(super) name_ref_syntax: Option<ast::NameRef>,
pub(super) function_syntax: Option<ast::FnDef>,
pub(super) use_item_syntax: Option<ast::UseItem>,
pub(super) use_item_syntax: Option<ast::Use>,
pub(super) record_lit_syntax: Option<ast::RecordLit>,
pub(super) record_pat_syntax: Option<ast::RecordPat>,
pub(super) record_field_syntax: Option<ast::RecordField>,
@ -343,7 +343,7 @@ impl<'a> CompletionContext<'a> {
}
self.use_item_syntax =
self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast);
self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast);
self.function_syntax = self
.sema

View file

@ -58,7 +58,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
}
NodeOrToken::Node(node) => {
// Fold groups of imports
if node.kind() == USE_ITEM && !visited_imports.contains(&node) {
if node.kind() == USE && !visited_imports.contains(&node) {
if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) {
res.push(Fold { range, kind: FoldKind::Imports })
}
@ -83,7 +83,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
match kind {
COMMENT => Some(FoldKind::Comment),
USE_ITEM => Some(FoldKind::Imports),
USE => Some(FoldKind::Imports),
ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList),
RECORD_FIELD_DEF_LIST
| RECORD_FIELD_PAT_LIST

View file

@ -7,7 +7,7 @@ pub(super) fn use_item(p: &mut Parser, m: Marker) {
p.bump(T![use]);
use_tree(p, true);
p.expect(T![;]);
m.complete(p, USE_ITEM);
m.complete(p, USE);
}
/// Parse a use 'tree', such as `some::path` in `use some::path;`

View file

@ -130,7 +130,7 @@ pub enum SyntaxKind {
RET_TYPE,
EXTERN_CRATE,
MODULE,
USE_ITEM,
USE,
STATIC_DEF,
CONST_DEF,
TRAIT_DEF,

View file

@ -237,7 +237,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool {
// and the code is `use foo::{baz, bar}`, we'll match `bar`, since it resolves to `foo::bar`.
// However we'll then replace just the part we matched `bar`. We probably need to instead remove
// `bar` and insert a new use declaration.
node.kind() != SyntaxKind::USE_ITEM
node.kind() != SyntaxKind::USE
}
impl UsageCache {

View file

@ -262,9 +262,9 @@ impl ast::PathSegment {
}
}
impl ast::UseItem {
impl ast::Use {
#[must_use]
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem {
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use {
if let Some(old) = self.use_tree() {
return self.replace_descendant(old, use_tree);
}

View file

@ -213,12 +213,12 @@ impl UnionDef {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseItem {
pub struct Use {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for UseItem {}
impl ast::VisibilityOwner for UseItem {}
impl UseItem {
impl ast::AttrsOwner for Use {}
impl ast::VisibilityOwner for Use {}
impl Use {
pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
@ -1283,7 +1283,7 @@ pub enum Item {
TraitDef(TraitDef),
TypeAliasDef(TypeAliasDef),
UnionDef(UnionDef),
UseItem(UseItem),
Use(Use),
}
impl ast::AttrsOwner for Item {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -1562,8 +1562,8 @@ impl AstNode for UnionDef {
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for UseItem {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM }
impl AstNode for Use {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
@ -2811,15 +2811,16 @@ impl From<TypeAliasDef> for Item {
impl From<UnionDef> for Item {
fn from(node: UnionDef) -> Item { Item::UnionDef(node) }
}
impl From<UseItem> for Item {
fn from(node: UseItem) -> Item { Item::UseItem(node) }
impl From<Use> for Item {
fn from(node: Use) -> Item { Item::Use(node) }
}
impl AstNode for Item {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL
| MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF
| USE_ITEM => true,
| MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => {
true
}
_ => false,
}
}
@ -2838,7 +2839,7 @@ impl AstNode for Item {
TRAIT_DEF => Item::TraitDef(TraitDef { syntax }),
TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }),
UNION_DEF => Item::UnionDef(UnionDef { syntax }),
USE_ITEM => Item::UseItem(UseItem { syntax }),
USE => Item::Use(Use { syntax }),
_ => return None,
};
Some(res)
@ -2858,7 +2859,7 @@ impl AstNode for Item {
Item::TraitDef(it) => &it.syntax,
Item::TypeAliasDef(it) => &it.syntax,
Item::UnionDef(it) => &it.syntax,
Item::UseItem(it) => &it.syntax,
Item::Use(it) => &it.syntax,
}
}
}
@ -3531,7 +3532,7 @@ impl std::fmt::Display for UnionDef {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for UseItem {
impl std::fmt::Display for Use {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}

View file

@ -60,7 +60,7 @@ pub fn use_tree_list(use_trees: impl IntoIterator<Item = ast::UseTree>) -> ast::
ast_from_text(&format!("use {{{}}};", use_trees))
}
pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem {
pub fn use_item(use_tree: ast::UseTree) -> ast::Use {
ast_from_text(&format!("use {};", use_tree))
}

View file

@ -100,7 +100,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"RET_TYPE",
"EXTERN_CRATE",
"MODULE",
"USE_ITEM",
"USE",
"STATIC_DEF",
"CONST_DEF",
"TRAIT_DEF",

View file

@ -17,7 +17,7 @@ Item =
| TraitDef
| TypeAliasDef
| UnionDef
| UseItem
| Use
Module =
Attr* Visibility? 'mod' Name
@ -32,7 +32,7 @@ ExternCrate =
Rename =
'as' (Name | '_')
UseItem =
Use =
Attr* Visibility? 'use' UseTree ';'
UseTree =