Skip to main content

termesh_core/
search.rs

1//! Protocol-neutral vocabulary shared by search services and the application model.
2
3use std::path::PathBuf;
4
5use crate::SearchRequestId;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum SearchMode {
9    Files,
10    Text,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct SearchRequest {
15    pub id: SearchRequestId,
16    pub root: PathBuf,
17    pub mode: SearchMode,
18    pub query: String,
19    pub limit: usize,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct SearchMatch {
24    pub path: PathBuf,
25    /// One-based line number when this is a text match.
26    pub line: Option<usize>,
27    /// One-based character column when this is a text match.
28    pub column: Option<usize>,
29    pub text: Option<String>,
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub enum SearchEvent {
34    Started { id: SearchRequestId },
35    Batch { id: SearchRequestId, matches: Vec<SearchMatch> },
36    Finished { id: SearchRequestId, truncated: bool },
37    Cancelled { id: SearchRequestId },
38    Failed { id: SearchRequestId, message: String, partial: bool },
39}