testing_language_server/
spec.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use clap::Parser;
use lsp_types::Diagnostic;
use lsp_types::Range;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;

#[derive(Parser, Debug)]
pub enum AdapterCommands {
    Discover(DiscoverArgs),
    RunFileTest(RunFileTestArgs),
    DetectWorkspace(DetectWorkspaceArgs),
}

/// Arguments for `<adapter command> discover` command
#[derive(clap::Args, Debug)]
#[command(version, about, long_about = None)]
pub struct DiscoverArgs {
    #[arg(short, long)]
    pub file_paths: Vec<String>,
    #[arg(last = true)]
    pub extra: Vec<String>,
}

/// Arguments for `<adapter command> run-file-test` command
#[derive(clap::Args, Debug)]
#[command(version, about, long_about = None)]
pub struct RunFileTestArgs {
    #[arg(short, long)]
    pub file_paths: Vec<String>,

    #[arg(short, long)]
    pub workspace: String,

    #[arg(last = true)]
    pub extra: Vec<String>,
}

/// Arguments for `<adapter command> detect-workspace` command
#[derive(clap::Args, Debug)]
#[command(version, about, long_about = None)]
pub struct DetectWorkspaceArgs {
    #[arg(short, long)]
    pub file_paths: Vec<String>,
    #[arg(last = true)]
    pub extra: Vec<String>,
}

pub type AdapterId = String;
pub type FilePath = String;
pub type WorkspaceFilePath = String;

#[derive(Debug, Serialize, Clone)]
pub struct WorkspaceAnalysis {
    pub adapter_config: AdapterConfiguration,
    pub workspaces: DetectWorkspaceResult,
}

impl WorkspaceAnalysis {
    pub fn new(adapter_config: AdapterConfiguration, workspaces: DetectWorkspaceResult) -> Self {
        Self {
            adapter_config,
            workspaces,
        }
    }
}

#[derive(Debug, Deserialize, Clone, Serialize, Default)]
pub struct AdapterConfiguration {
    pub path: String,
    #[serde(default)]
    pub extra_args: Vec<String>,
    #[serde(default)]
    pub envs: HashMap<String, String>,
    pub include_patterns: Vec<String>,
    pub exclude_patterns: Vec<String>,
    pub workspace_dir: Option<String>,
}

/// Result of `<adapter command> detect-workspace`
pub type DetectWorkspaceResult = HashMap<WorkspaceFilePath, Vec<FilePath>>;

/// Result of `<adapter command> run-file-test`
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct RunFileTestResultItem {
    pub path: String,
    pub diagnostics: Vec<Diagnostic>,
}

pub type RunFileTestResult = Vec<RunFileTestResultItem>;

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct TestItem {
    pub id: String,
    pub name: String,
    pub start_position: Range,
    pub end_position: Range,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct DiscoverResultItem {
    pub path: String,
    pub tests: Vec<TestItem>,
}

/// Result of `<adapter command> discover`
pub type DiscoverResult = Vec<DiscoverResultItem>;