summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/rename
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/src/features/rename')
-rw-r--r--support/texlab/src/features/rename/command.rs30
-rw-r--r--support/texlab/src/features/rename/entry.rs40
-rw-r--r--support/texlab/src/features/rename/label.rs34
3 files changed, 41 insertions, 63 deletions
diff --git a/support/texlab/src/features/rename/command.rs b/support/texlab/src/features/rename/command.rs
index aaa08f8cb4..5610b2f7ee 100644
--- a/support/texlab/src/features/rename/command.rs
+++ b/support/texlab/src/features/rename/command.rs
@@ -1,29 +1,21 @@
-use std::sync::Arc;
-
-use lsp_types::RenameParams;
use rowan::{TextRange, TextSize};
use rustc_hash::FxHashMap;
-use crate::{
- features::cursor::{CursorContext, HasPosition},
- syntax::latex,
-};
+use crate::util::cursor::CursorContext;
-use super::{Indel, RenameResult};
+use super::{Indel, Params, RenameResult};
-pub(super) fn prepare_command_rename<P: HasPosition>(
- context: &CursorContext<P>,
-) -> Option<TextRange> {
+pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> {
context.cursor.command_range(context.offset)
}
-pub(super) fn rename_command(context: &CursorContext<RenameParams>) -> Option<RenameResult> {
- prepare_command_rename(context)?;
- let name = context.cursor.as_latex()?.text();
+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.request.workspace.documents_by_uri.values() {
- if let Some(data) = document.data.as_latex() {
- let root = latex::SyntaxNode::new_root(data.green.clone());
+ 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())
@@ -32,12 +24,12 @@ pub(super) fn rename_command(context: &CursorContext<RenameParams>) -> Option<Re
let range = token.text_range();
Indel {
delete: TextRange::new(range.start() + TextSize::from(1), range.end()),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
}
})
.collect();
- changes.insert(Arc::clone(&document.uri), edits);
+ changes.insert(document, edits);
}
}
diff --git a/support/texlab/src/features/rename/entry.rs b/support/texlab/src/features/rename/entry.rs
index 6eac79030b..79ee25ac71 100644
--- a/support/texlab/src/features/rename/entry.rs
+++ b/support/texlab/src/features/rename/entry.rs
@@ -1,23 +1,18 @@
-use std::sync::Arc;
-
-use lsp_types::RenameParams;
use rowan::{ast::AstNode, TextRange};
use rustc_hash::FxHashMap;
use crate::{
- features::cursor::{CursorContext, HasPosition},
+ db::parse::DocumentData,
syntax::{
bibtex::{self, HasName},
latex,
},
- DocumentData,
+ util::cursor::CursorContext,
};
-use super::{Indel, RenameResult};
+use super::{Indel, Params, RenameResult};
-pub(super) fn prepare_entry_rename<P: HasPosition>(
- context: &CursorContext<P>,
-) -> Option<TextRange> {
+pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> {
let (_, range) = context
.find_citation_key_word()
.or_else(|| context.find_entry_key())?;
@@ -25,18 +20,17 @@ pub(super) fn prepare_entry_rename<P: HasPosition>(
Some(range)
}
-pub(super) fn rename_entry(context: &CursorContext<RenameParams>) -> Option<RenameResult> {
- prepare_entry_rename(context)?;
+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.request.workspace.documents_by_uri.values() {
- let uri = Arc::clone(&document.uri);
- match &document.data {
- DocumentData::Latex(data) => {
- let root = latex::SyntaxNode::new_root(data.green.clone());
+ 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)
@@ -45,13 +39,13 @@ pub(super) fn rename_entry(context: &CursorContext<RenameParams>) -> Option<Rena
.filter(|key| key.to_string() == key_text)
.map(|key| Indel {
delete: latex::small_range(&key),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
})
.collect();
- changes.insert(uri, edits);
+ changes.insert(document, edits);
}
- DocumentData::Bibtex(data) => {
- let root = bibtex::SyntaxNode::new_root(data.green.clone());
+ DocumentData::Bib(data) => {
+ let root = data.root(context.db);
let edits: Vec<_> = root
.descendants()
.filter_map(bibtex::Entry::cast)
@@ -59,12 +53,12 @@ pub(super) fn rename_entry(context: &CursorContext<RenameParams>) -> Option<Rena
.filter(|key| key.text() == key_text)
.map(|key| Indel {
delete: key.text_range(),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
})
.collect();
- changes.insert(uri, edits);
+ changes.insert(document, edits);
}
- DocumentData::BuildLog(_) => {}
+ DocumentData::Log(_) => {}
}
}
diff --git a/support/texlab/src/features/rename/label.rs b/support/texlab/src/features/rename/label.rs
index 30a99c3b36..d38d13ae93 100644
--- a/support/texlab/src/features/rename/label.rs
+++ b/support/texlab/src/features/rename/label.rs
@@ -1,32 +1,24 @@
-use std::sync::Arc;
-
-use lsp_types::RenameParams;
use rowan::{ast::AstNode, TextRange};
use rustc_hash::FxHashMap;
-use crate::{
- features::cursor::{CursorContext, HasPosition},
- syntax::latex,
-};
+use crate::{syntax::latex, util::cursor::CursorContext};
-use super::{Indel, RenameResult};
+use super::{Indel, Params, RenameResult};
-pub(super) fn prepare_label_rename<P: HasPosition>(
- context: &CursorContext<P>,
-) -> Option<TextRange> {
+pub(super) fn prepare_rename<T>(context: &CursorContext<T>) -> Option<TextRange> {
let (_, range) = context.find_label_name_key()?;
Some(range)
}
-pub(super) fn rename_label(context: &CursorContext<RenameParams>) -> Option<RenameResult> {
- prepare_label_rename(context)?;
+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.request.workspace.documents_by_uri.values() {
- if let Some(data) = document.data.as_latex() {
+ for document in context.related() {
+ if let Some(data) = document.parse(context.db).as_tex() {
let mut edits = Vec::new();
- for node in latex::SyntaxNode::new_root(data.green.clone()).descendants() {
+ 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())
@@ -35,7 +27,7 @@ pub(super) fn rename_label(context: &CursorContext<RenameParams>) -> Option<Rena
{
edits.push(Indel {
delete: range,
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
});
}
@@ -47,7 +39,7 @@ pub(super) fn rename_label(context: &CursorContext<RenameParams>) -> Option<Rena
.for_each(|name| {
edits.push(Indel {
delete: latex::small_range(&name),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
});
});
@@ -59,7 +51,7 @@ pub(super) fn rename_label(context: &CursorContext<RenameParams>) -> Option<Rena
{
edits.push(Indel {
delete: latex::small_range(&name1),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
});
}
@@ -70,13 +62,13 @@ pub(super) fn rename_label(context: &CursorContext<RenameParams>) -> Option<Rena
{
edits.push(Indel {
delete: latex::small_range(&name2),
- insert: context.request.params.new_name.clone(),
+ insert: context.params.new_name.clone(),
});
}
}
}
- changes.insert(Arc::clone(&document.uri), edits);
+ changes.insert(document, edits);
}
}