use std::{
collections::HashMap,
fmt::Debug,
path::{Path, PathBuf},
sync::Arc,
};
#[cfg(test)]
use mockall::{automock, predicate::*};
#[cfg(test)]
use tokio_stream::wrappers::ReceiverStream;
#[cfg(test)]
use crate::models::resolved::ResolvedSymbol;
use crate::models::{self};
#[derive(Debug)]
pub enum SymbolKindFilter {
Global(Vec<models::parsed::SymbolKind>),
PerLanguage(HashMap<models::parsed::Language, Vec<models::parsed::SymbolKind>>),
}
#[cfg_attr(
test,
automock(type QueryContext=super::types::Context; type QueryResult=ReceiverStream<ResolvedSymbol>;)
)]
pub trait Resolver: Send + Sync + Debug {
#[allow(missing_docs)]
type QueryContext;
#[allow(missing_docs)]
type QueryResult;
fn query(&self, query: String, ctx: Self::QueryContext) -> Self::QueryResult;
}
#[derive(Default, Debug, Clone)]
pub struct Context {
pub current_file: Arc<Option<PathBuf>>,
pub symbol_kinds: Arc<Option<SymbolKindFilter>>,
}
impl Context {
#[must_use]
pub fn with_current_file(mut self, current_file: impl AsRef<Path>) -> Self {
self.current_file = Arc::new(Some(current_file.as_ref().into()));
self
}
#[must_use]
pub fn with_symbol_kinds(mut self, symbol_kinds: SymbolKindFilter) -> Self {
self.symbol_kinds = Arc::new(Some(symbol_kinds));
self
}
}