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    /// Corpus identifier (e.g. `github.com/org/repo`). Used by SCIP ingest to
33    /// produce correct VNames. Defaults to empty string for backwards compatibility
34    /// with plugin binaries that predate this field.
35    #[serde(default)]
36    pub corpus: String,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, Default)]
40pub struct InvokeResponse {
41    pub nodes: Vec<Node>,
42    pub edges: Vec<Edge>,
43}
44
45impl InvokeResponse {
46    pub fn unsupported() -> Self {
47        Self::default()
48    }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct HandshakeRequest {
53    pub daemon_protocol_version: u32,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct HandshakeResponse {
58    pub protocol_version: u32,
59    pub plugin_version: String,
60    /// Canonical lowercase language string — must match the normative table in language_map.rs.
61    pub language: String,
62    pub extensions: Vec<String>,
63    pub supports_phase_b: bool,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(tag = "type", rename_all = "snake_case")]
68pub enum PluginRequest {
69    Handshake(HandshakeRequest),
70    Parse(ParseRequest),
71    Invoke(InvokeRequest),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(tag = "type", rename_all = "snake_case")]
76pub enum PluginResponse {
77    Handshake(HandshakeResponse),
78    Parse(ParseResponse),
79    Invoke(InvokeResponse),
80    Error(PluginError),
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct PluginError {
85    pub file: String,
86    pub message: String,
87}