Skip to main content

a3s_code_core/code_intelligence/
service.rs

1use super::{
2    CodeDiagnostic, CodeIntelligenceResult, CodeIntelligenceStatus, CodeLocation, CodePosition,
3    CodeQueryResult, DocumentSymbol, NavigationKind, SymbolInformation,
4};
5use crate::workspace::WorkspacePath;
6use async_trait::async_trait;
7use tokio::sync::watch;
8use tokio_util::sync::CancellationToken;
9
10/// Workspace-scoped provider for read-only semantic code queries.
11///
12/// Implementations operate on saved documents. Unsaved editor buffers are
13/// intentionally outside this contract so independent views cannot overwrite
14/// one another's semantic state.
15#[async_trait]
16pub trait WorkspaceCodeIntelligence: Send + Sync {
17    /// Subscribe to runtime lifecycle and capability changes.
18    fn subscribe_status(&self) -> watch::Receiver<CodeIntelligenceStatus>;
19
20    /// Return the latest status snapshot without waiting for a state change.
21    fn status(&self) -> CodeIntelligenceStatus {
22        let receiver = self.subscribe_status();
23        let status = receiver.borrow().clone();
24        status
25    }
26
27    /// Return the hierarchical symbol outline for a saved document.
28    async fn document_symbols(
29        &self,
30        path: &WorkspacePath,
31        cancellation: CancellationToken,
32    ) -> CodeIntelligenceResult<CodeQueryResult<DocumentSymbol>>;
33
34    /// Search symbols across the workspace, bounded by `limit`.
35    async fn search_symbols(
36        &self,
37        query: &str,
38        limit: usize,
39        cancellation: CancellationToken,
40    ) -> CodeIntelligenceResult<CodeQueryResult<SymbolInformation>>;
41
42    /// Resolve one semantic navigation operation from a saved document.
43    async fn navigate(
44        &self,
45        kind: NavigationKind,
46        path: &WorkspacePath,
47        position: CodePosition,
48        cancellation: CancellationToken,
49    ) -> CodeIntelligenceResult<CodeQueryResult<CodeLocation>>;
50
51    /// Pull diagnostics for one saved document, or for the workspace when
52    /// `path` is `None`.
53    async fn diagnostics(
54        &self,
55        path: Option<&WorkspacePath>,
56        cancellation: CancellationToken,
57    ) -> CodeIntelligenceResult<CodeQueryResult<CodeDiagnostic>>;
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    fn assert_send_sync<T: Send + Sync + ?Sized>() {}
65
66    #[test]
67    fn service_trait_is_object_safe_send_and_sync() {
68        assert_send_sync::<dyn WorkspaceCodeIntelligence>();
69    }
70}