Skip to main content

agnix_lsp/
lib.rs

1#![allow(clippy::collapsible_if, dead_code)]
2
3//! # agnix-lsp
4//!
5//! Language Server Protocol implementation for agnix.
6//!
7//! Provides real-time validation of agent configuration files in editors
8//! that support LSP (VS Code, Neovim, Helix, etc.).
9//!
10//! ## Features
11//!
12//! - Real-time diagnostics on file open, change, and save
13//! - Quick-fix code actions for automatic repairs
14//! - Hover documentation for configuration fields
15//! - Supports all agnix validation rules
16//! - Maps agnix diagnostics to LSP diagnostics
17//!
18//! ## Usage
19//!
20//! Run the LSP server:
21//!
22//! ```bash
23//! agnix-lsp
24//! ```
25//!
26//! The server communicates over stdin/stdout using the LSP protocol.
27
28rust_i18n::i18n!("locales", fallback = "en");
29
30pub(crate) mod backend;
31pub(crate) mod code_actions;
32pub(crate) mod completion_provider;
33pub(crate) mod diagnostic_mapper;
34pub(crate) mod hover_provider;
35pub(crate) mod locale;
36pub(crate) mod position;
37pub(crate) mod vscode_config;
38
39pub use backend::Backend;
40pub use vscode_config::{VsCodeConfig, VsCodeRules, VsCodeSpecs, VsCodeVersions};
41
42use tower_lsp::{LspService, Server};
43
44/// Start the LSP server.
45///
46/// This function sets up stdin/stdout communication and runs the server
47/// until shutdown is requested. Locale is initialized from environment
48/// variables before the server starts.
49///
50/// # Errors
51///
52/// Returns an error if the server fails to start or encounters a fatal error.
53pub async fn start_server() -> anyhow::Result<()> {
54    // Initialize locale from environment variables (AGNIX_LOCALE > LANG/LC_ALL > system > "en")
55    locale::init_from_env();
56
57    let stdin = tokio::io::stdin();
58    let stdout = tokio::io::stdout();
59
60    let (service, socket) = LspService::new(Backend::new);
61    Server::new(stdin, stdout, socket).serve(service).await;
62    Ok(())
63}
64
65#[cfg(test)]
66mod testability_tests;