Skip to main content

vvv_engine/protocol/
references.rs

1use vvv_core::RelPath;
2
3use serde::{Deserialize, Serialize};
4
5use vvv_core::{LanguageId, SymbolKind};
6
7/// The declaration(s) called `name`, and every identifier that spells it,
8/// each judged against the declaration meant. What `rename` gathers before
9/// it plans, and what `references` answers on its own.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct ReferencesQuery {
12    pub name: String,
13    #[serde(default, skip_serializing_if = "Option::is_none")]
14    pub symbol: Option<SymbolKind>,
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    pub language: Option<LanguageId>,
17    /// The file declaring the symbol meant, when several share the name.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub declared_in: Option<RelPath>,
20}
21
22impl ReferencesQuery {
23    pub fn new(name: impl Into<String>) -> Self {
24        Self {
25            name: name.into(),
26            symbol: None,
27            language: None,
28            declared_in: None,
29        }
30    }
31
32    pub fn declared_in(mut self, path: impl Into<RelPath>) -> Self {
33        self.declared_in = Some(path.into());
34        self
35    }
36
37    pub fn of_symbol(mut self, symbol: SymbolKind) -> Self {
38        self.symbol = Some(symbol);
39        self
40    }
41
42    pub fn in_language(mut self, language: impl Into<LanguageId>) -> Self {
43        self.language = Some(language.into());
44        self
45    }
46}