From 92665358cd98913e3fef8294e1889cc0bb919e3f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 5 May 2020 23:56:10 +0800 Subject: Rename ImplItem to AssocItem --- crates/ra_syntax/src/ast/edit.rs | 6 ++--- crates/ra_syntax/src/ast/generated/nodes.rs | 36 ++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index c507dc683..3e6dd6061 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -79,7 +79,7 @@ where impl ast::ItemList { #[must_use] - pub fn append_items(&self, items: impl IntoIterator) -> ast::ItemList { + pub fn append_items(&self, items: impl IntoIterator) -> ast::ItemList { let mut res = self.clone(); if !self.syntax().text().contains_char('\n') { res = make_multiline(res); @@ -89,8 +89,8 @@ impl ast::ItemList { } #[must_use] - pub fn append_item(&self, item: ast::ImplItem) -> ast::ItemList { - let (indent, position) = match self.impl_items().last() { + pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { + let (indent, position) = match self.assoc_items().last() { Some(it) => ( leading_indent(it.syntax()).unwrap_or_default().to_string(), InsertPosition::After(it.syntax().clone().into()), diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index c2cc25958..b00c15608 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -196,7 +196,7 @@ pub struct ItemList { impl ast::ModuleItemOwner for ItemList {} impl ItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn impl_items(&self) -> AstChildren { support::children(&self.syntax) } + pub fn assoc_items(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } @@ -1429,13 +1429,13 @@ impl ast::AttrsOwner for ModuleItem {} impl ast::VisibilityOwner for ModuleItem {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum ImplItem { +pub enum AssocItem { FnDef(FnDef), TypeAliasDef(TypeAliasDef), ConstDef(ConstDef), } -impl ast::NameOwner for ImplItem {} -impl ast::AttrsOwner for ImplItem {} +impl ast::NameOwner for AssocItem {} +impl ast::AttrsOwner for AssocItem {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ExternItem { @@ -3167,16 +3167,16 @@ impl AstNode for ModuleItem { } } } -impl From for ImplItem { - fn from(node: FnDef) -> ImplItem { ImplItem::FnDef(node) } +impl From for AssocItem { + fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } } -impl From for ImplItem { - fn from(node: TypeAliasDef) -> ImplItem { ImplItem::TypeAliasDef(node) } +impl From for AssocItem { + fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } } -impl From for ImplItem { - fn from(node: ConstDef) -> ImplItem { ImplItem::ConstDef(node) } +impl From for AssocItem { + fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } } -impl AstNode for ImplItem { +impl AstNode for AssocItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, @@ -3185,18 +3185,18 @@ impl AstNode for ImplItem { } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - FN_DEF => ImplItem::FnDef(FnDef { syntax }), - TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), - CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), + FN_DEF => AssocItem::FnDef(FnDef { syntax }), + TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), + CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - ImplItem::FnDef(it) => &it.syntax, - ImplItem::TypeAliasDef(it) => &it.syntax, - ImplItem::ConstDef(it) => &it.syntax, + AssocItem::FnDef(it) => &it.syntax, + AssocItem::TypeAliasDef(it) => &it.syntax, + AssocItem::ConstDef(it) => &it.syntax, } } } @@ -3641,7 +3641,7 @@ impl std::fmt::Display for ModuleItem { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ImplItem { +impl std::fmt::Display for AssocItem { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } -- cgit v1.2.3 From 4a6fa8f0dfcebbb4ea80394e5e4ca21f076f58f2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:15:49 +0200 Subject: Rename AtomTextEdit -> Indel --- crates/ra_syntax/src/fuzz.rs | 6 +++--- crates/ra_syntax/src/lib.rs | 14 +++++++------- crates/ra_syntax/src/parsing/reparsing.rs | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs index 10fbe3176..39f9b12ab 100644 --- a/crates/ra_syntax/src/fuzz.rs +++ b/crates/ra_syntax/src/fuzz.rs @@ -5,7 +5,7 @@ use std::{ str::{self, FromStr}, }; -use ra_text_edit::AtomTextEdit; +use ra_text_edit::Indel; use crate::{validation, AstNode, SourceFile, TextRange}; @@ -22,7 +22,7 @@ pub fn check_parser(text: &str) { #[derive(Debug, Clone)] pub struct CheckReparse { text: String, - edit: AtomTextEdit, + edit: Indel, edited_text: String, } @@ -43,7 +43,7 @@ impl CheckReparse { TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap()); let edited_text = format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]); - let edit = AtomTextEdit { delete, insert }; + let edit = Indel { delete, insert }; Some(CheckReparse { text, edit, edited_text }) } diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index d0234cada..1a7348dac 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -39,7 +39,7 @@ pub mod fuzz; use std::{marker::PhantomData, sync::Arc}; -use ra_text_edit::AtomTextEdit; +use ra_text_edit::Indel; use stdx::format_to; use crate::syntax_node::GreenNode; @@ -126,13 +126,13 @@ impl Parse { buf } - pub fn reparse(&self, edit: &AtomTextEdit) -> Parse { - self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) + pub fn reparse(&self, indel: &Indel) -> Parse { + self.incremental_reparse(indel).unwrap_or_else(|| self.full_reparse(indel)) } - fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option> { + fn incremental_reparse(&self, indel: &Indel) -> Option> { // FIXME: validation errors are not handled here - parsing::incremental_reparse(self.tree().syntax(), edit, self.errors.to_vec()).map( + parsing::incremental_reparse(self.tree().syntax(), indel, self.errors.to_vec()).map( |(green_node, errors, _reparsed_range)| Parse { green: green_node, errors: Arc::new(errors), @@ -141,8 +141,8 @@ impl Parse { ) } - fn full_reparse(&self, edit: &AtomTextEdit) -> Parse { - let text = edit.apply(self.tree().syntax().text().to_string()); + fn full_reparse(&self, indel: &Indel) -> Parse { + let text = indel.apply(self.tree().syntax().text().to_string()); SourceFile::parse(&text) } } diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index ffff0a7b2..6257e3f33 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -7,7 +7,7 @@ //! and try to parse only this block. use ra_parser::Reparser; -use ra_text_edit::AtomTextEdit; +use ra_text_edit::Indel; use crate::{ algo, @@ -24,7 +24,7 @@ use crate::{ pub(crate) fn incremental_reparse( node: &SyntaxNode, - edit: &AtomTextEdit, + edit: &Indel, errors: Vec, ) -> Option<(GreenNode, Vec, TextRange)> { if let Some((green, new_errors, old_range)) = reparse_token(node, &edit) { @@ -39,7 +39,7 @@ pub(crate) fn incremental_reparse( fn reparse_token<'node>( root: &'node SyntaxNode, - edit: &AtomTextEdit, + edit: &Indel, ) -> Option<(GreenNode, Vec, TextRange)> { let prev_token = algo::find_covering_element(root, edit.delete).as_token()?.clone(); let prev_token_kind = prev_token.kind(); @@ -88,7 +88,7 @@ fn reparse_token<'node>( fn reparse_block<'node>( root: &'node SyntaxNode, - edit: &AtomTextEdit, + edit: &Indel, ) -> Option<(GreenNode, Vec, TextRange)> { let (node, reparser) = find_reparsable_node(root, edit.delete)?; let text = get_text_after_edit(node.clone().into(), edit); @@ -108,9 +108,9 @@ fn reparse_block<'node>( Some((node.replace_with(green), new_parser_errors, node.text_range())) } -fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { +fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String { let edit = - AtomTextEdit::replace(edit.delete - element.text_range().start(), edit.insert.clone()); + Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone()); let text = match element { NodeOrToken::Token(token) => token.text().to_string(), @@ -167,7 +167,7 @@ fn merge_errors( old_errors: Vec, new_errors: Vec, range_before_reparse: TextRange, - edit: &AtomTextEdit, + edit: &Indel, ) -> Vec { let mut res = Vec::new(); @@ -198,7 +198,7 @@ mod tests { fn do_check(before: &str, replace_with: &str, reparsed_len: u32) { let (range, before) = extract_range(before); - let edit = AtomTextEdit::replace(range, replace_with.to_owned()); + let edit = Indel::replace(range, replace_with.to_owned()); let after = edit.apply(before.clone()); let fully_reparsed = SourceFile::parse(&after); -- cgit v1.2.3 From 27c7ef6d65ffa6a642768377d3f0ba85ac8564bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:23:29 +0200 Subject: Use more natural signature for Edit::apply --- crates/ra_syntax/src/lib.rs | 3 ++- crates/ra_syntax/src/parsing/reparsing.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 1a7348dac..61e686da5 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -142,7 +142,8 @@ impl Parse { } fn full_reparse(&self, indel: &Indel) -> Parse { - let text = indel.apply(self.tree().syntax().text().to_string()); + let mut text = self.tree().syntax().text().to_string(); + indel.apply(&mut text); SourceFile::parse(&text) } } diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index 6257e3f33..edbc190f8 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -109,14 +109,14 @@ fn reparse_block<'node>( } fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String { - let edit = - Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone()); + let edit = Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone()); - let text = match element { + let mut text = match element { NodeOrToken::Token(token) => token.text().to_string(), NodeOrToken::Node(node) => node.text().to_string(), }; - edit.apply(text) + edit.apply(&mut text); + text } fn is_contextual_kw(text: &str) -> bool { @@ -199,7 +199,11 @@ mod tests { fn do_check(before: &str, replace_with: &str, reparsed_len: u32) { let (range, before) = extract_range(before); let edit = Indel::replace(range, replace_with.to_owned()); - let after = edit.apply(before.clone()); + let after = { + let mut after = before.clone(); + edit.apply(&mut after); + after + }; let fully_reparsed = SourceFile::parse(&after); let incrementally_reparsed: Parse = { -- cgit v1.2.3