vvv_engine/protocol/intent/
rename.rs1use vvv_core::RelPath;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{ReferencesQuery, Selection};
6use vvv_core::{LanguageId, SymbolKind};
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub struct RenameIntent {
15 pub name: String,
16 pub to: String,
17 #[serde(default, skip_serializing_if = "Option::is_none")]
18 pub symbol: Option<SymbolKind>,
19 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub language: Option<LanguageId>,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub declared_in: Option<RelPath>,
24 #[serde(default, skip_serializing_if = "Selection::is_all")]
25 pub selection: Selection,
26}
27
28impl RenameIntent {
29 pub fn new(name: impl Into<String>, to: impl Into<String>) -> Self {
30 Self {
31 name: name.into(),
32 to: to.into(),
33 symbol: None,
34 language: None,
35 declared_in: None,
36 selection: Selection::All,
37 }
38 }
39
40 pub fn declared_in(mut self, path: impl Into<RelPath>) -> Self {
41 self.declared_in = Some(path.into());
42 self
43 }
44
45 pub fn of_symbol(mut self, symbol: SymbolKind) -> Self {
46 self.symbol = Some(symbol);
47 self
48 }
49
50 pub fn in_language(mut self, language: impl Into<LanguageId>) -> Self {
51 self.language = Some(language.into());
52 self
53 }
54
55 pub fn selecting(mut self, selection: Selection) -> Self {
56 self.selection = selection;
57 self
58 }
59
60 pub fn references(&self) -> ReferencesQuery {
62 ReferencesQuery {
63 name: self.name.clone(),
64 symbol: self.symbol,
65 language: self.language.clone(),
66 declared_in: self.declared_in.clone(),
67 }
68 }
69}