kql_language_tools/
lib.rs

1//! KQL Language Tools
2//!
3//! This crate provides Rust bindings to Microsoft's `Kusto.Language` library
4//! via .NET AOT compilation. It enables KQL validation, completion, and
5//! syntax highlighting in Rust applications.
6//!
7//! ## Features
8//!
9//! - **Syntax Validation**: Check KQL queries for syntax errors
10//! - **Schema Validation**: Validate queries against a database schema
11//! - **Completions**: Get intellisense suggestions at cursor position
12//! - **Classification**: Get syntax highlighting spans
13//!
14//! ## Usage
15//!
16//! ```no_run
17//! use kql_language_tools::{KqlValidator, ValidationResult};
18//!
19//! fn main() -> Result<(), kql_language_tools::Error> {
20//!     let validator = KqlValidator::new()?;
21//!     let result = validator.validate_syntax("SecurityEvent | take 10")?;
22//!
23//!     if result.is_valid() {
24//!         println!("Query is valid!");
25//!     } else {
26//!         for diagnostic in result.diagnostics() {
27//!             println!("Error at {}:{}: {}", diagnostic.line, diagnostic.column, diagnostic.message);
28//!         }
29//!     }
30//!     Ok(())
31//! }
32//! ```
33//!
34//! ## Native Library
35//!
36//! This crate requires a native library built from the .NET AOT project.
37//! The library can be:
38//!
39//! 1. Built from source: `cd dotnet && dotnet publish -c Release -r <rid>`
40//! 2. Downloaded from releases (if using `bundled` feature)
41//! 3. Specified via `kql_language_tools_PATH` environment variable
42
43mod classification;
44mod completion;
45mod error;
46mod ffi;
47mod loader;
48mod schema;
49mod types;
50mod validator;
51
52pub use classification::{ClassificationKind, ClassificationResult, ClassifiedSpan};
53pub use completion::{CompletionItem, CompletionKind, CompletionResult};
54pub use error::Error;
55pub use schema::{Column, Function, Schema, Table};
56pub use types::{Diagnostic, DiagnosticSeverity, ValidationResult};
57pub use validator::KqlValidator;
58
59/// Result type alias for this crate
60pub type Result<T> = std::result::Result<T, Error>;
61
62/// Library version
63pub const VERSION: &str = env!("CARGO_PKG_VERSION");
64
65/// Check if the native library is available
66///
67/// Returns `true` if the native library can be loaded, `false` otherwise.
68/// This is a lightweight check that doesn't fully initialize the library.
69#[must_use]
70pub fn is_available() -> bool {
71    loader::find_library_path().is_some()
72}
73
74/// Get the path to the native library, if found
75#[must_use]
76pub fn library_path() -> Option<std::path::PathBuf> {
77    loader::find_library_path()
78}