use vvv_core::RelPath;
use serde::{Deserialize, Serialize};
use crate::{ReferencesQuery, Selection};
use vvv_core::{LanguageId, SymbolKind};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RenameIntent {
pub name: String,
pub to: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub symbol: Option<SymbolKind>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub language: Option<LanguageId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub declared_in: Option<RelPath>,
#[serde(default, skip_serializing_if = "Selection::is_all")]
pub selection: Selection,
}
impl RenameIntent {
pub fn new(name: impl Into<String>, to: impl Into<String>) -> Self {
Self {
name: name.into(),
to: to.into(),
symbol: None,
language: None,
declared_in: None,
selection: Selection::All,
}
}
pub fn declared_in(mut self, path: impl Into<RelPath>) -> Self {
self.declared_in = Some(path.into());
self
}
pub fn of_symbol(mut self, symbol: SymbolKind) -> Self {
self.symbol = Some(symbol);
self
}
pub fn in_language(mut self, language: impl Into<LanguageId>) -> Self {
self.language = Some(language.into());
self
}
pub fn selecting(mut self, selection: Selection) -> Self {
self.selection = selection;
self
}
pub fn references(&self) -> ReferencesQuery {
ReferencesQuery {
name: self.name.clone(),
symbol: self.symbol,
language: self.language.clone(),
declared_in: self.declared_in.clone(),
}
}
}