pytest_language_server/fixtures/
types.rs

1//! Data structures for fixture definitions, usages, and related types.
2
3use std::path::PathBuf;
4
5/// A fixture definition extracted from a Python file.
6#[derive(Debug, Clone, PartialEq)]
7pub struct FixtureDefinition {
8    pub name: String,
9    pub file_path: PathBuf,
10    pub line: usize,
11    pub start_char: usize, // Character position where the fixture name starts (on the line)
12    pub end_char: usize,   // Character position where the fixture name ends (on the line)
13    pub docstring: Option<String>,
14    pub return_type: Option<String>, // The return type annotation (for generators, the yielded type)
15    pub is_third_party: bool, // Whether this fixture is from a third-party package (site-packages)
16}
17
18/// A fixture usage (reference) in a Python file.
19#[derive(Debug, Clone)]
20pub struct FixtureUsage {
21    pub name: String,
22    pub file_path: PathBuf,
23    pub line: usize,
24    pub start_char: usize, // Character position where this usage starts (on the line)
25    pub end_char: usize,   // Character position where this usage ends (on the line)
26}
27
28/// An undeclared fixture used in a function body without being declared as a parameter.
29#[derive(Debug, Clone)]
30#[allow(dead_code)] // Fields used for debugging and future features
31pub struct UndeclaredFixture {
32    pub name: String,
33    pub file_path: PathBuf,
34    pub line: usize,
35    pub start_char: usize,
36    pub end_char: usize,
37    pub function_name: String, // Name of the test/fixture function where this is used
38    pub function_line: usize,  // Line where the function is defined
39}
40
41/// Context for code completion.
42#[derive(Debug, Clone, PartialEq)]
43pub enum CompletionContext {
44    /// Inside a function signature (parameter list) - suggest fixtures as parameters.
45    FunctionSignature {
46        function_name: String,
47        function_line: usize,
48        is_fixture: bool,
49        declared_params: Vec<String>,
50    },
51    /// Inside a function body - suggest fixtures with auto-add to parameters.
52    FunctionBody {
53        function_name: String,
54        function_line: usize,
55        is_fixture: bool,
56        declared_params: Vec<String>,
57    },
58    /// Inside @pytest.mark.usefixtures("...") decorator - suggest fixture names as strings.
59    UsefixuturesDecorator,
60    /// Inside @pytest.mark.parametrize(..., indirect=...) - suggest fixture names as strings.
61    ParametrizeIndirect,
62}
63
64/// Information about where to insert a new parameter in a function signature.
65#[derive(Debug, Clone, PartialEq)]
66pub struct ParamInsertionInfo {
67    /// Line number (1-indexed) where the function signature is.
68    pub line: usize,
69    /// Character position where the new parameter should be inserted.
70    pub char_pos: usize,
71    /// Whether a comma needs to be added before the new parameter.
72    pub needs_comma: bool,
73}