Skip to main content

pytest_language_server/
lib.rs

1//! # pytest-language-server
2//!
3//! A Language Server Protocol (LSP) implementation for pytest fixtures.
4//!
5//! This crate provides IDE features for pytest fixture development:
6//!
7//! - **Go to Definition**: Jump to fixture definitions from test functions
8//! - **Find References**: Find all usages of a fixture across the codebase
9//! - **Hover Documentation**: View fixture docstrings and signatures
10//! - **Code Completion**: Auto-complete fixture names in function signatures
11//! - **Diagnostics**: Detect undeclared fixtures, scope mismatches, and circular dependencies
12//! - **Code Actions**: Quick fixes to add missing fixture parameters
13//! - **Code Lens**: Usage counts above fixture definitions
14//! - **Inlay Hints**: Show fixture return types inline
15//! - **Call Hierarchy**: Navigate fixture dependency graphs
16//!
17//! ## Architecture
18//!
19//! The crate is organized into two main modules:
20//!
21//! - [`fixtures`]: Core fixture analysis engine with [`FixtureDatabase`] as the central data structure
22//! - [`config`]: Configuration file support for `pyproject.toml` settings
23//!
24//! ## Usage
25//!
26//! The primary entry point is [`FixtureDatabase`], which provides methods for:
27//!
28//! - Scanning workspaces for fixture definitions
29//! - Analyzing Python files for fixtures and their usages
30//! - Resolving fixture definitions based on pytest's priority rules
31//! - Providing completion context for fixture suggestions
32//!
33//! ```no_run
34//! use pytest_language_server::FixtureDatabase;
35//! use std::path::Path;
36//!
37//! let db = FixtureDatabase::new();
38//! db.scan_workspace(Path::new("./tests"));
39//!
40//! // Find a fixture definition
41//! if let Some(def) = db.find_fixture_definition(Path::new("test_file.py"), 10, 15) {
42//!     println!("Found fixture: {} at line {}", def.name, def.line);
43//! }
44//! ```
45//!
46//! ## Fixture Resolution
47//!
48//! The LSP correctly implements pytest's fixture priority/shadowing rules:
49//!
50//! 1. **Same file**: Fixtures defined in the same file have highest priority
51//! 2. **Closest conftest.py**: Walk up directory tree looking for conftest.py
52//! 3. **Third-party**: Fixtures from site-packages (50+ plugins supported)
53
54pub mod config;
55pub mod fixtures;
56
57pub use config::Config;
58pub use fixtures::{
59    CompletionContext, FixtureCycle, FixtureDatabase, FixtureDefinition, FixtureScope,
60    FixtureUsage, ParamInsertionInfo, ScopeMismatch, UndeclaredFixture,
61};
62
63// Expose decorators module for testing
64#[cfg(test)]
65pub use fixtures::decorators;