# nocturne
A language-agnostic code analysis library that provides LSP-like functionality without the LSP protocol.
## Overview
nocturne allows you to analyze source code by providing it as a string and performing various operations similar to what Language Server Protocols (LSPs) do, such as:
- **Diagnostics**: Parse code and find syntax errors
- **Symbol extraction**: Find all functions, structs, types, etc. with full signatures
- **Symbol lookup**: Find symbols at specific positions
- **Completions**: Get completion suggestions
- **Formatting**: Validate and format code
## Rust Support:
- Hover information
- Type inference
- Go to definition
- Find references
- Signature help
## Supported Languages
- **Rust**: Uses rust-analyzer's syntax parser (`ra_ap_syntax`) for robust parsing and analysis
## Usage
```rust
use nocturne::{nocturne, Position};
use nocturne::rust::Rustnocturne;
fn main() {
let nocturne = Rustnocturne::new();
// Parse and check for errors
let source = r#"
fn main() {
println!("Hello, world!");
}
"#;
let diagnostics = nocturne.diagnostics(source);
if diagnostics.is_empty() {
println!("No errors!");
}
// Find all symbols
let symbols = nocturne.symbols(source).unwrap();
for symbol in symbols {
println!("{:?}: {}", symbol.kind, symbol.name);
}
// Find symbol at a specific position
let position = Position { line: 2, column: 12 };
if let Some(symbol) = nocturne.symbol_at_position(source, position).unwrap() {
println!("Found: {}", symbol.name);
}
}
```
## Running Examples
```bash
cargo run --example basic
```
## Running Tests
```bash
cargo test -p nocturne
```