Skip to main content

scope_engine/
analyzer.rs

1use crate::api::PropagationResult;
2use std::path::Path;
3
4/// Analyzer provides cross-file reference lookups via LSP or other language servers.
5///
6/// Each language server implementation (rust-analyzer, gopls, etc.) implements this trait,
7/// allowing scope-engine to query references without knowing the specific LSP server details.
8///
9/// All methods use `&self` to support interior mutability patterns (e.g. `RefCell`),
10/// so implementations can be shared behind `Mutex<dyn Analyzer + Send>`.
11pub trait Analyzer: Send {
12    /// Find all references to the symbol at the given position in the file.
13    ///
14    /// `file_path` is the absolute path to the file.
15    /// `line` is 1-based line number.
16    /// `character` is 0-based column offset.
17    /// `project_root` is the absolute path to the project root.
18    fn find_references_for_symbol(
19        &self,
20        file_path: &Path,
21        line: usize,
22        character: usize,
23        project_root: &Path,
24    ) -> Vec<PropagationResult>;
25
26    /// Notify the language server that a file was opened.
27    fn notify_did_open(&self, file_path: &Path, text: &str);
28
29    /// Notify the language server that a file was modified (full sync).
30    fn notify_did_change(&self, file_path: &Path, version: i32, text: &str);
31
32    /// Notify the language server that a file was closed.
33    fn notify_did_close(&self, file_path: &Path);
34
35    /// Whether the analyzer is available and initialized.
36    fn is_initialized(&self) -> bool;
37}