nocturne 0.0.1

Code analyzer
Documentation
pub mod rust;
pub mod semantic;

use std::fmt;

/// Position in source code (line, column)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Position {
    pub line: usize,
    pub column: usize,
}

/// A range in source code
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Range {
    pub start: Position,
    pub end: Position,
}

/// Severity of a diagnostic
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
    Error,
    Warning,
    Info,
    Hint,
}

/// A diagnostic message (error, warning, etc.)
#[derive(Debug, Clone)]
pub struct Diagnostic {
    pub severity: Severity,
    pub message: String,
    pub range: Option<Range>,
}

impl fmt::Display for Diagnostic {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let severity = match self.severity {
            Severity::Error => "error",
            Severity::Warning => "warning",
            Severity::Info => "info",
            Severity::Hint => "hint",
        };

        if let Some(range) = &self.range {
            write!(
                f,
                "{}: {} ({}:{} - {}:{})",
                severity,
                self.message,
                range.start.line,
                range.start.column,
                range.end.line,
                range.end.column
            )
        } else {
            write!(f, "{}: {}", severity, self.message)
        }
    }
}

/// Type of symbol
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SymbolKind {
    Function,
    Struct,
    Enum,
    Trait,
    Module,
    Const,
    Static,
    Type,
    Impl,
    Macro,
    Variable,
}

/// A symbol in the code
#[derive(Debug, Clone)]
pub struct Symbol {
    pub kind: SymbolKind,
    pub name: String,
    pub range: Range,
    pub detail: Option<String>,
}

/// Completion item suggestion
#[derive(Debug, Clone)]
pub struct CompletionItem {
    pub label: String,
    pub kind: SymbolKind,
    pub detail: Option<String>,
    pub documentation: Option<String>,
}

/// Type information for a symbol or expression
#[derive(Debug, Clone)]
pub struct TypeInfo {
    pub name: String,
    pub full_name: String,
    pub documentation: Option<String>,
}

/// Hover information at a position
#[derive(Debug, Clone)]
pub struct HoverInfo {
    pub range: Range,
    pub contents: String,
    pub type_info: Option<TypeInfo>,
}

/// Reference to a symbol
#[derive(Debug, Clone)]
pub struct Reference {
    pub range: Range,
    pub is_definition: bool,
}

/// Signature information for function calls
#[derive(Debug, Clone)]
pub struct SignatureHelp {
    pub label: String,
    pub documentation: Option<String>,
    pub parameters: Vec<ParameterInfo>,
    pub active_parameter: Option<usize>,
}

#[derive(Debug, Clone)]
pub struct ParameterInfo {
    pub label: String,
    pub documentation: Option<String>,
}

/// Main trait for language analysis
pub trait Judge {
    /// Parse the source code and return diagnostics
    fn diagnostics(&self, source: &str) -> Vec<Diagnostic>;

    /// Get all symbols in the source code
    fn symbols(&self, source: &str) -> Result<Vec<Symbol>, String>;

    /// Find symbol at a specific position
    fn symbol_at_position(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<Symbol>, String>;

    /// Get completion suggestions at a position
    fn completions(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Vec<CompletionItem>, String>;

    /// Format the source code
    fn format(&self, source: &str) -> Result<String, String>;
}

/// Extended trait for semantic analysis (requires project context)
pub trait SemanticJudge: Judge {
    /// Get hover information at a position
    fn hover(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<HoverInfo>, String>;

    /// Get type information at a position
    fn type_at_position(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<TypeInfo>, String>;

    /// Find all references to a symbol
    fn find_references(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Vec<Reference>, String>;

    /// Go to definition
    fn goto_definition(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<Range>, String>;

    /// Get signature help for function calls
    fn signature_help(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<SignatureHelp>, String>;

    /// Infer the type of an expression at a position
    fn infer_type(
        &self,
        source: &str,
        position: Position,
    ) -> Result<Option<String>, String>;
}