Skip to main content

vvv_engine/protocol/
source.rs

1//! Versioned source locations shared by search and navigation.
2use serde::{Deserialize, Serialize};
3use vvv_core::{LanguageId, RelPath, Span, SymbolKind};
4
5/// Digest of complete file contents, independent of their path.
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
7#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
8#[serde(transparent)]
9pub struct ContentId(String);
10
11impl ContentId {
12    pub(crate) fn from_fingerprint(value: &crate::plan::Fingerprint) -> Self {
13        Self(value.as_str().to_owned())
14    }
15
16    pub(crate) fn of_bytes(bytes: &[u8]) -> Self {
17        Self(blake3::hash(bytes).to_hex().to_string())
18    }
19
20    pub fn of(text: &str) -> Self {
21        Self(crate::plan::Fingerprint::of(text).as_str().to_owned())
22    }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
27pub struct SourceAnchor {
28    pub path: RelPath,
29    pub content: ContentId,
30    pub span: Span,
31}
32
33/// A declaration in one source version, not an identity across edits.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
36pub struct SymbolRef {
37    pub language: LanguageId,
38    pub declaration: SourceAnchor,
39    pub name_span: Span,
40    pub kind: SymbolKind,
41}