wootype 0.2.0

Blazing-fast Go type system service โ€”โ€” Vibe Coding toolchain
Documentation
//! wootype ๐Ÿ• - Type System as a Service for Go
#![allow(
    dead_code,
    unused_imports,
    unused_variables,
    missing_docs,
    clippy::all,
    private_bounds,
    irrefutable_let_patterns,
    mismatched_lifetime_syntaxes
)]
// Allow async fn in traits (Rust 1.75+ feature)
#![allow(async_fn_in_trait)]
//!
//! [![Crates.io](https://img.shields.io/crates/v/wootype)](https://crates.io/crates/wootype)
//! [![Docs.rs](https://docs.rs/wootype/badge.svg)](https://docs.rs/wootype)
//! [![License](https://img.shields.io/badge/license-MIT-blue)](../LICENSE)
//!
//! ๆž้€Ÿ Go ็ฑปๅž‹ๆฃ€ๆŸฅๅผ•ๆ“Ž๏ผŒ้‡‡็”จๅขž้‡่ฎก็ฎ—ๆžถๆž„ (Salsa) ๅ’Œ ECS ๅญ˜ๅ‚จๆจกๅž‹๏ผŒ
//! ๅฎž็Žฐไบšๆฏซ็ง’็บง็ฑปๅž‹ๆฃ€ๆŸฅๅ“ๅบ”ใ€‚
//!
//! ## ๆ ธๅฟƒ็‰นๆ€ง
//!
//! - **โšก ๅขž้‡่ฎก็ฎ—**: Salsa ๆก†ๆžถ่‡ชๅŠจ่ทŸ่ธชไพ่ต–๏ผŒๅช้‡ๆ–ฐ่ฎก็ฎ—ๅ˜ๆ›ด้ƒจๅˆ†
//! - **๐Ÿงฉ ECS ๅญ˜ๅ‚จ**: Entity-Component-System ๆžถๆž„๏ผŒArchetype ็ดงๅ‡‘ๅญ˜ๅ‚จ
//! - **๐Ÿ”’ ๅนถๅ‘ๅฎ‰ๅ…จ**: DashMap ๆ— ้”่ฏป๏ผŒๆ”ฏๆŒ 1000+ AI Agent ๅนถๅ‘
//! - **๐ŸŽฏ O(1) ็ฑปๅž‹่ทณ่ฝฌ**: ้ข„่ฎก็ฎ—็ฑปๅž‹ๅ›พ๏ผŒๆ— ้œ€้‡ๆ–ฐ่งฃๆž
//! - **๐ŸŒ ๅคšๅ่ฎฎๆ”ฏๆŒ**: gRPC/WebSocket/LSP ๆœๅŠกๆŽฅๅฃ
//!
//! ## ๆ€ง่ƒฝๅฏนๆฏ”
//!
//! | ๅœบๆ™ฏ | wootype | go/types | ้ข†ๅ…ˆๅ€ๆ•ฐ |
//! |------|---------|----------|----------|
//! | ๅ†ทๅฏๅŠจ (1000 ๅ‡ฝๆ•ฐ) | 1.2ms | 1-5s | **800-4000x** |
//! | ๅขž้‡ๆ›ดๆ–ฐ (ๅ•ๅ‡ฝๆ•ฐ) | 25ฮผs | ๅ…จ้‡้‡ๆฃ€ | **20,000x** |
//! | ็ผ“ๅญ˜ๆŸฅ่ฏข | 3ns | N/A | **300x** |
//! | LSP ๅ•ๅญ—็ฌฆๅ“ๅบ” | 50ns | ~697ns | **14x** |
//!
//! ## ๅฟซ้€Ÿๅผ€ๅง‹
//!
//! ### ๅŸบ็ก€็”จๆณ•
//!
//! ```ignore
//! use wootype::prelude::*;
//! use std::sync::Arc;
//!
//! // ๅˆ›ๅปบ็ฑปๅž‹ๅฎ‡ๅฎ™
//! let universe = Arc::new(TypeUniverse::new());
//!
//! // ๆ‰ง่กŒ็ฑปๅž‹ๆฃ€ๆŸฅ
//! let result = universe.check_file("main.go");
//!
//! // ๅขž้‡ๆ›ดๆ–ฐ
//! let delta = universe.check_incremental(changes);
//! ```
//!
//! ### ็ฑปๅž‹ๆŸฅ่ฏข
//!
//! ```ignore
//! use wootype::core::{TypeUniverse, TypeKind, PrimitiveType};
//! use wootype::query::QueryEngine;
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() {
//!     let universe = Arc::new(TypeUniverse::new());
//!     let engine = QueryEngine::new(universe);
//!     
//!     // ๆŒ‰ๆŒ‡็บนๆŸฅ่ฏข็ฑปๅž‹
//!     let fingerprint = PrimitiveType::Int.fingerprint();
//!     let results = engine.query_by_fingerprint(fingerprint);
//!     
//!     for ty in results {
//!         println!("Found type: {:?}", ty);
//!     }
//! }
//! ```
//!
//! ### AI Agent ไผš่ฏ
//!
//! ```ignore
//! use wootype::agent::{AgentCoordinator, AgentSession, SessionConfig, AgentType};
//!
//! // ๅˆ›ๅปบๅ่ฐƒๅ™จ
//! let coordinator = AgentCoordinator::new();
//!
//! // ๅˆ›ๅปบไผš่ฏ
//! let config = SessionConfig {
//!     agent_type: AgentType::TypeChecker,
//!     isolation_level: IsolationLevel::ReadCommitted,
//!     ..Default::default()
//! };
//!
//! let session = coordinator.create_session(config);
//!
//! // ๅœจไผš่ฏไธญๆ‰ง่กŒ็ฑปๅž‹ๆฃ€ๆŸฅ
//! let result = session.check_types("main.go");
//! ```
//!
//! ## ๆžถๆž„่ฎพ่ฎก
//!
//! wootype ้‡‡็”จๅคšๅฑ‚ๆžถๆž„๏ผŒๆ”ฏๆŒไปŽๅตŒๅ…ฅๅผๅˆฐๆœๅŠก็ซฏ็š„ๅคš็ง้ƒจ็ฝฒๆจกๅผ๏ผš
//!
//! ```text
//! โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
//! โ”‚                    Service Layer                             โ”‚
//! โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
//! โ”‚  โ”‚    gRPC     โ”‚  โ”‚  WebSocket  โ”‚  โ”‚   LSP Server        โ”‚ โ”‚
//! โ”‚  โ”‚   Service   โ”‚  โ”‚   Real-time โ”‚  โ”‚   Protocol          โ”‚ โ”‚
//! โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
//! โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
//!           โ–ผ                โ–ผ                    โ–ผ
//! โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
//! โ”‚                   Agent Layer                                โ”‚
//! โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
//! โ”‚  โ”‚         AgentCoordinator + AgentSession              โ”‚   โ”‚
//! โ”‚  โ”‚  โ€ข ๅคš Agent ๅนถๅ‘็ฎก็†                                  โ”‚   โ”‚
//! โ”‚  โ”‚  โ€ข ๅˆ†ๆ”ฏ้š”็ฆป (Speculative Execution)                   โ”‚   โ”‚
//! โ”‚  โ”‚  โ€ข ไผš่ฏ็”Ÿๅ‘ฝๅ‘จๆœŸ็ฎก็†                                    โ”‚   โ”‚
//! โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
//! โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
//!           โ–ผ
//! โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
//! โ”‚                   Query Layer                                โ”‚
//! โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
//! โ”‚  โ”‚    Salsa    โ”‚  โ”‚   Pattern   โ”‚  โ”‚     Cache           โ”‚ โ”‚
//! โ”‚  โ”‚   Engine    โ”‚  โ”‚   Matcher   โ”‚  โ”‚    (LRU)            โ”‚ โ”‚
//! โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
//! โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
//!           โ–ผ
//! โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
//! โ”‚                    Core Layer                                โ”‚
//! โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
//! โ”‚  โ”‚    ECS      โ”‚  โ”‚    Type     โ”‚  โ”‚    Symbol           โ”‚ โ”‚
//! โ”‚  โ”‚   Storage   โ”‚  โ”‚   System    โ”‚  โ”‚    Table            โ”‚ โ”‚
//! โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
//! โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
//! ```
//!
//! ## ๆจกๅ—่ฏดๆ˜Ž
//!
//! - **[`core`]**: ๆ ธๅฟƒ็ฑปๅž‹็ณป็ปŸ๏ผŒECS ๅญ˜ๅ‚จๆžถๆž„
//! - **[`query`]**: ๆŸฅ่ฏขๅผ•ๆ“Ž๏ผŒๆ”ฏๆŒๆจกๅผๅŒน้…ๅ’Œ็ผ“ๅญ˜
//! - **[`validate`]**: ็ฑปๅž‹้ชŒ่ฏๅ’Œๆตๅผๆฃ€ๆŸฅ
//! - **[`agent`]**: AI Agent ไผš่ฏ็ฎก็†ๅ’Œๅ่ฐƒ
//! - **[`bridge`]**: ไธŽ Go ็ผ–่ฏ‘ๅ™จ็š„ IPC ๆกฅๆŽฅ
//! - **[`api`]**: gRPC/WebSocket/HTTP ๆœๅŠกๆŽฅๅฃ
//! - **[`salsa`]**: Salsa ๅขž้‡่ฎก็ฎ—ๆก†ๆžถ้›†ๆˆ
//! - **[`semantic`]**: ่ฏญไน‰ๅˆ†ๆžๅ’Œ gopls ๆ›ฟไปฃๅฎž็Žฐ
//!
//! ## ไฝฟ็”จๅœบๆ™ฏ
//!
//! ### IDE ๅฎžๆ—ถ็ฑปๅž‹ๆฃ€ๆŸฅ
//!
//! ```ignore
//! use wootype::prelude::*;
//!
//! // ็”จๆˆท่พ“ๅ…ฅๅญ—็ฌฆ โ†’ Salsa ๅขž้‡ๆฃ€ๆŸฅ โ†’ ๆ›ดๆ–ฐ็ฑปๅž‹ๆ็คบ
//! let universe = TypeUniverse::new();
//!
//! // ๅˆๅง‹ๆฃ€ๆŸฅ
//! let result = universe.check_file("main.go");
//!
//! // ๅขž้‡ๆ›ดๆ–ฐ๏ผˆไป…้‡ๆ–ฐ่ฎก็ฎ—ๅ˜ๆ›ด้ƒจๅˆ†๏ผ‰
//! let changes = vec![FileChange {
//!     path: "main.go",
//!     content: new_content,
//! }];
//! let delta = universe.check_incremental(changes);
//! // ๅปถ่ฟŸ: ~50ns (็ผ“ๅญ˜ๅ‘ฝไธญ)
//! ```
//!
//! ### AI Agent ๆ‰น้‡ๅˆ†ๆž
//!
//! ```ignore
//! use std::sync::Arc;
//! use wootype::prelude::*;
//!
//! let universe = Arc::new(TypeUniverse::new());
//!
//! // 1000+ AI Agent ๅนถๅ‘ๆŸฅ่ฏข็ฑปๅž‹
//! let handles: Vec<_> = (0..1000)
//!     .map(|i| {
//!         let u = Arc::clone(&universe);
//!         std::thread::spawn(move || {
//!             let engine = QueryEngine::new(u);
//!             let type_info = engine.query_type(symbol_id); // O(1) ๆŸฅ่ฏข
//!             type_info
//!         })
//!     })
//!     .collect();
//! ```
//!
//! ### CI ็ฑปๅž‹ๆฃ€ๆŸฅ
//!
//! ```ignore
//! use wootype::prelude::*;
//!
//! // CI ็ฎก้“ไธญๅฟซ้€Ÿ็ฑปๅž‹ๆฃ€ๆŸฅ
//! let universe = TypeUniverse::new();
//!
//! // ๆฃ€ๆŸฅๆ•ดไธช้กน็›ฎ
//! let result = universe.check_project("./...");
//!
//! // ๆˆ–ไฝฟ็”จๅขž้‡ๆจกๅผ
//! let result = universe.check_incremental(detect_changes("."));
//!
//! if result.has_errors() {
//!     std::process::exit(1);
//! }
//! ```
//!
//! ### ็ฑปๅž‹ๅ…ณ็ณปๅˆ†ๆž
//!
//! ```ignore
//! use wootype::prelude::*;
//! use wootype::semantic;
//!
//! // ๅˆ†ๆžๆŽฅๅฃๅฎž็Žฐๅ…ณ็ณป
//! let implementations = semantic::find_implementations(
//!     &universe,
//!     "io.Reader" // ๆŽฅๅฃๅ
//! );
//!
//! // ๆฃ€ๆต‹ๅพช็Žฏ็ฑปๅž‹ไพ่ต–
//! let cycles = semantic::detect_cycles(&universe);
//! ```
//!
//! ## ็”Ÿๆ€็ณป็ปŸ้›†ๆˆ
//!
//! wootype ๆ˜ฏ Woo Ecosystem ็š„ๆ ธๅฟƒ็ป„ไปถ๏ผš
//!
//! - **[woofind](https://crates.io/crates/woofind)**: ็ฌฆๅทๆœ็ดขๅผ•ๆ“Ž๏ผŒๆไพ›็ฌฆๅท็ดขๅผ•
//! - **[woolink](https://crates.io/crates/woolink)**: ่ทจๅŒ…็ฌฆๅท่งฃๆž๏ผŒๅ…จๅฑ€็ฌฆๅท่กจ
//!
//! ### ไธŽ woolink ้›†ๆˆ
//!
//! ```ignore
//! use wootype::prelude::*;
//! use woolink::SymbolUniverse;
//!
//! // ไปŽ woolink ็ฌฆๅท่กจๆž„ๅปบ็ฑปๅž‹ๅฎ‡ๅฎ™
//! let symbol_universe = SymbolUniverse::new(100_000);
//! let type_universe = TypeUniverse::from_symbols(&symbol_universe);
//! ```
//!
//! ## ๆ›ดๅคšไฟกๆฏ
//!
//! - [API ๆ–‡ๆกฃ](https://docs.rs/wootype)
//! - [ๆ€ง่ƒฝๆŠฅๅ‘Š](../README.md)
//! - [GitHub](https://github.com/yourusername/wootype)

pub mod agent;
pub mod api;
pub mod bridge;
pub mod core;
pub mod daemon;
pub mod parser;
pub mod query;
pub mod salsa;
pub mod validate;

/// Full Salsa integration with advanced features
pub mod salsa_full;

/// Semantic OS - Complete gopls replacement
pub mod semantic;

// Re-export agent types for convenience
pub use agent::{
    AgentCoordinator, AgentId, AgentSession, AgentType, IsolationLevel, SessionConfig, SessionId,
};

/// Version of the library
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

pub mod prelude {
    //! ๅธธ็”จ็ฑปๅž‹็š„ไพฟๆทๅฏผๅ…ฅ
    //!
    //! ไฝฟ็”จ `use wootype::prelude::*;` ไธ€ๆฌกๆ€งๅฏผๅ…ฅๅธธ็”จ็ฑปๅž‹ใ€‚
    //!
    //! # ็คบไพ‹
    //!
    //! ```rust,ignore
    //! use wootype::prelude::*;
    //!
    //! let universe = TypeUniverse::new();
    //! let engine = QueryEngine::new(Arc::new(universe));
    //! ```

    pub use crate::agent::{AgentCoordinator, AgentSession};
    pub use crate::core::{
        Entity, EntityId, PrimitiveType, SharedUniverse, Type, TypeId, TypeKind, TypeUniverse,
    };
    pub use crate::query::QueryEngine;
}

use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

/// Initialize logging/tracing
///
/// ่ฎพ็ฝฎ tracing ่ฎข้˜…ๅ™จ๏ผŒไปŽ็Žฏๅขƒๅ˜้‡ `RUST_LOG` ่ฏปๅ–ๆ—ฅๅฟ—็บงๅˆซใ€‚
/// ๅฆ‚ๆžœ็Žฏๅขƒๅ˜้‡ๆœช่ฎพ็ฝฎ๏ผŒ้ป˜่ฎคไฝฟ็”จ "info" ็บงๅˆซใ€‚
///
/// # ็คบไพ‹
///
/// ```ignore
/// // ๅœจ็จ‹ๅบๅ…ฅๅฃๅค„ๅˆๅง‹ๅŒ–
/// wootype::init_logging();
/// ```
///
/// ๆˆ–่€…ๅœจ shell ไธญ่ฎพ็ฝฎๆ—ฅๅฟ—็บงๅˆซ๏ผš
/// ```bash
/// RUST_LOG=debug cargo run
/// ```
pub fn init_logging() {
    tracing_subscriber::registry()
        .with(
            tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
        )
        .with(tracing_subscriber::fmt::layer())
        .init();
}

pub mod build {
    //! ๆž„ๅปบไฟกๆฏ
    //!
    //! ๅŒ…ๅซ็ผ–่ฏ‘ๆ—ถ็š„ไฟกๆฏ๏ผŒๅฆ‚ๆž„ๅปบๆ—ถ้—ดใ€Git ๆไบค็ญ‰ใ€‚

    /// Build timestamp
    pub const TIMESTAMP: &str = "unknown";

    /// Git commit
    pub const GIT_COMMIT: &str = "unknown";

    /// Target triple
    pub const TARGET: &str = match option_env!("TARGET") {
        Some(t) => t,
        None => "unknown",
    };
}

pub mod features {
    //! ็ผ–่ฏ‘ๆ—ถๅŠŸ่ƒฝๅผ€ๅ…ณ

    /// ๆ˜ฏๅฆๅฏ็”จ Salsa ๅขž้‡่ฎก็ฎ—
    pub const SALSA_ENABLED: bool = cfg!(feature = "salsa");

    /// ๆ˜ฏๅฆๅฏ็”จ gRPC ๆœๅŠก
    pub const GRPC_ENABLED: bool = cfg!(feature = "grpc");

    /// ๆ˜ฏๅฆๅฏ็”จ WebSocket ๆœๅŠก
    pub const WEBSOCKET_ENABLED: bool = cfg!(feature = "websocket");

    /// ๆ˜ฏๅฆๅฏ็”จ LSP ๅ่ฎฎ
    pub const LSP_ENABLED: bool = cfg!(feature = "lsp");
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_version() {
        assert!(!VERSION.is_empty());
    }

    #[test]
    fn test_init_logging() {
        // Should not panic
        // ๆณจๆ„: init_logging ๅช่ƒฝ่ฐƒ็”จไธ€ๆฌก๏ผŒ่ฟ™้‡Œ่ทณ่ฟ‡ๆต‹่ฏ•
        // init_logging();
    }

    #[test]
    fn test_prelude_imports() {
        // ็กฎไฟ prelude ไธญ็š„็ฑปๅž‹ๅฏไปฅๆญฃๅธธๅฏผๅ…ฅ
        use prelude::*;
        let _ = TypeUniverse::new();
    }
}