Skip to main content

travsr_plugin_protocol/
types.rs

1use crate::ffi_marker::FfiMarker;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4use travsr_core::{Edge, Node};
5
6/// Current protocol version. Bump on any breaking wire change.
7pub const PROTOCOL_VERSION: u32 = 1;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ParseRequest {
11    /// Absolute path on disk — used to read/mmap the file.
12    pub path: PathBuf,
13    /// Repo-relative path used in VName construction (the stable graph key).
14    /// Must match the `vname_path` passed to `Indexer::parse_file_with_vname`.
15    pub vname_path: String,
16    pub corpus: String,
17    pub package: String,
18    /// Populated only for git-blob indexing (content not on disk).
19    pub source: Option<Vec<u8>>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23pub struct ParseResponse {
24    pub nodes: Vec<Node>,
25    pub edges: Vec<Edge>,
26    pub ffi_markers: Vec<FfiMarker>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct InvokeRequest {
31    pub root: PathBuf,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, Default)]
35pub struct InvokeResponse {
36    pub nodes: Vec<Node>,
37    pub edges: Vec<Edge>,
38}
39
40impl InvokeResponse {
41    pub fn unsupported() -> Self {
42        Self::default()
43    }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct HandshakeRequest {
48    pub daemon_protocol_version: u32,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct HandshakeResponse {
53    pub protocol_version: u32,
54    pub plugin_version: String,
55    /// Canonical lowercase language string — must match the normative table in language_map.rs.
56    pub language: String,
57    pub extensions: Vec<String>,
58    pub supports_phase_b: bool,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(tag = "type", rename_all = "snake_case")]
63pub enum PluginRequest {
64    Handshake(HandshakeRequest),
65    Parse(ParseRequest),
66    Invoke(InvokeRequest),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(tag = "type", rename_all = "snake_case")]
71pub enum PluginResponse {
72    Handshake(HandshakeResponse),
73    Parse(ParseResponse),
74    Invoke(InvokeResponse),
75    Error(PluginError),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct PluginError {
80    pub file: String,
81    pub message: String,
82}