diff options
Diffstat (limited to 'support/texlab/src/features/rename')
-rw-r--r-- | support/texlab/src/features/rename/command.rs | 37 | ||||
-rw-r--r-- | support/texlab/src/features/rename/entry.rs | 66 | ||||
-rw-r--r-- | support/texlab/src/features/rename/label.rs | 76 |
3 files changed, 0 insertions, 179 deletions
diff --git a/support/texlab/src/features/rename/command.rs b/support/texlab/src/features/rename/command.rs deleted file mode 100644 index 1e5f2ff0ca..0000000000 --- a/support/texlab/src/features/rename/command.rs +++ /dev/null @@ -1,37 +0,0 @@ -use rowan::{TextRange, TextSize}; -use rustc_hash::FxHashMap; - -use crate::{syntax::latex, util::cursor::CursorContext}; - -use super::{Indel, Params, RenameResult}; - -pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> { - context.cursor.command_range(context.offset) -} - -pub(super) fn rename(context: &CursorContext<Params>) -> Option<RenameResult> { - prepare_rename(context)?; - let name = context.cursor.as_tex()?.text(); - let mut changes = FxHashMap::default(); - for document in context.related() { - if let Some(data) = document.parse(context.db).as_tex() { - let root = data.root(context.db); - let edits = root - .descendants_with_tokens() - .filter_map(|element| element.into_token()) - .filter(|token| token.kind() == latex::COMMAND_NAME && token.text() == name) - .map(|token| { - let range = token.text_range(); - Indel { - delete: TextRange::new(range.start() + TextSize::from(1), range.end()), - insert: context.params.new_name.clone(), - } - }) - .collect(); - - changes.insert(document, edits); - } - } - - Some(RenameResult { changes }) -} diff --git a/support/texlab/src/features/rename/entry.rs b/support/texlab/src/features/rename/entry.rs deleted file mode 100644 index 67c0388f4f..0000000000 --- a/support/texlab/src/features/rename/entry.rs +++ /dev/null @@ -1,66 +0,0 @@ -use rowan::{ast::AstNode, TextRange}; -use rustc_hash::FxHashMap; - -use crate::{ - db::parse::DocumentData, - syntax::{ - bibtex::{self, HasName}, - latex, - }, - util::cursor::CursorContext, -}; - -use super::{Indel, Params, RenameResult}; - -pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> { - let (_, range) = context - .find_citation_key_word() - .or_else(|| context.find_entry_key())?; - - Some(range) -} - -pub(super) fn rename(context: &CursorContext<Params>) -> Option<RenameResult> { - prepare_rename(context)?; - let (key_text, _) = context - .find_citation_key_word() - .or_else(|| context.find_entry_key())?; - - let mut changes = FxHashMap::default(); - for document in context.related() { - match document.parse(context.db) { - DocumentData::Tex(data) => { - let root = data.root(context.db); - let edits: Vec<_> = root - .descendants() - .filter_map(latex::Citation::cast) - .filter_map(|citation| citation.key_list()) - .flat_map(|keys| keys.keys()) - .filter(|key| key.to_string() == key_text) - .map(|key| Indel { - delete: latex::small_range(&key), - insert: context.params.new_name.clone(), - }) - .collect(); - changes.insert(document, edits); - } - DocumentData::Bib(data) => { - let root = data.root(context.db); - let edits: Vec<_> = root - .descendants() - .filter_map(bibtex::Entry::cast) - .filter_map(|entry| entry.name_token()) - .filter(|key| key.text() == key_text) - .map(|key| Indel { - delete: key.text_range(), - insert: context.params.new_name.clone(), - }) - .collect(); - changes.insert(document, edits); - } - DocumentData::Log(_) | DocumentData::TexlabRoot(_) | DocumentData::Tectonic(_) => {} - } - } - - Some(RenameResult { changes }) -} diff --git a/support/texlab/src/features/rename/label.rs b/support/texlab/src/features/rename/label.rs deleted file mode 100644 index 7e596209d8..0000000000 --- a/support/texlab/src/features/rename/label.rs +++ /dev/null @@ -1,76 +0,0 @@ -use rowan::{ast::AstNode, TextRange}; -use rustc_hash::FxHashMap; - -use crate::{syntax::latex, util::cursor::CursorContext}; - -use super::{Indel, Params, RenameResult}; - -pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> { - let (_, range) = context.find_label_name_key()?; - Some(range) -} - -pub(super) fn rename(context: &CursorContext<Params>) -> Option<RenameResult> { - prepare_rename(context)?; - let (name_text, _) = context.find_label_name_key()?; - - let mut changes = FxHashMap::default(); - for document in context.related() { - if let Some(data) = document.parse(context.db).as_tex() { - let mut edits = Vec::new(); - for node in data.root(context.db).descendants() { - if let Some(range) = latex::LabelDefinition::cast(node.clone()) - .and_then(|label| label.name()) - .and_then(|name| name.key()) - .filter(|name| name.to_string() == name_text) - .map(|name| latex::small_range(&name)) - { - edits.push(Indel { - delete: range, - insert: context.params.new_name.clone(), - }); - } - - latex::LabelReference::cast(node.clone()) - .and_then(|label| label.name_list()) - .into_iter() - .flat_map(|label| label.keys()) - .filter(|name| name.to_string() == name_text) - .for_each(|name| { - edits.push(Indel { - delete: latex::small_range(&name), - insert: context.params.new_name.clone(), - }); - }); - - if let Some(label) = latex::LabelReferenceRange::cast(node.clone()) { - if let Some(name_from) = label - .from() - .and_then(|name| name.key()) - .filter(|name| name.to_string() == name_text) - { - edits.push(Indel { - delete: latex::small_range(&name_from), - insert: context.params.new_name.clone(), - }); - } - - if let Some(name_to) = label - .to() - .and_then(|name| name.key()) - .filter(|name| name.to_string() == name_text) - { - edits.push(Indel { - delete: latex::small_range(&name_to), - insert: context.params.new_name.clone(), - }); - } - } - } - - changes.insert(document, edits); - } - } - - Some(RenameResult { changes }) -} |