use super::{
CodeDiagnostic, CodeIntelligenceResult, CodeIntelligenceStatus, CodeLocation, CodePosition,
CodeQueryResult, DocumentSymbol, NavigationKind, SymbolInformation,
};
use crate::workspace::WorkspacePath;
use async_trait::async_trait;
use tokio::sync::watch;
use tokio_util::sync::CancellationToken;
#[async_trait]
pub trait WorkspaceCodeIntelligence: Send + Sync {
fn subscribe_status(&self) -> watch::Receiver<CodeIntelligenceStatus>;
fn status(&self) -> CodeIntelligenceStatus {
let receiver = self.subscribe_status();
let status = receiver.borrow().clone();
status
}
async fn document_symbols(
&self,
path: &WorkspacePath,
cancellation: CancellationToken,
) -> CodeIntelligenceResult<CodeQueryResult<DocumentSymbol>>;
async fn search_symbols(
&self,
query: &str,
limit: usize,
cancellation: CancellationToken,
) -> CodeIntelligenceResult<CodeQueryResult<SymbolInformation>>;
async fn navigate(
&self,
kind: NavigationKind,
path: &WorkspacePath,
position: CodePosition,
cancellation: CancellationToken,
) -> CodeIntelligenceResult<CodeQueryResult<CodeLocation>>;
async fn diagnostics(
&self,
path: Option<&WorkspacePath>,
cancellation: CancellationToken,
) -> CodeIntelligenceResult<CodeQueryResult<CodeDiagnostic>>;
}
#[cfg(test)]
mod tests {
use super::*;
fn assert_send_sync<T: Send + Sync + ?Sized>() {}
#[test]
fn service_trait_is_object_safe_send_and_sync() {
assert_send_sync::<dyn WorkspaceCodeIntelligence>();
}
}