-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.rs
124 lines (108 loc) · 3.4 KB
/
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use clap::Parser;
use lsp_types::Diagnostic;
use lsp_types::Range;
use lsp_types::ShowMessageParams;
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_arg: Vec<String>,
#[serde(default)]
pub env: HashMap<String, String>,
pub include: Vec<String>,
pub exclude: Vec<String>,
pub workspace_dir: Option<String>,
}
/// Result of `<adapter command> detect-workspace`
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct DetectWorkspaceResult {
pub data: HashMap<WorkspaceFilePath, Vec<FilePath>>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct FileDiagnostics {
pub path: String,
pub diagnostics: Vec<Diagnostic>,
}
/// Result of `<adapter command> run-file-test`
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct RunFileTestResult {
pub data: Vec<FileDiagnostics>,
#[serde(default)]
pub messages: Vec<ShowMessageParams>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct TestItem {
pub id: String,
pub name: String,
/// Although FoundFileTests also has a `path` field, we keep the `path` field in TestItem
/// because sometimes we need to determine where a TestItem is located on its own
/// Example: In Rust tests, determining which file contains a test from IDs like relative::path::tests::id
/// TODO: Remove FoundFileTests.path once we confirm it's no longer needed
pub path: String,
pub start_position: Range,
pub end_position: Range,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct FoundFileTests {
pub path: String,
pub tests: Vec<TestItem>,
}
/// Result of `<adapter command> discover`
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct DiscoverResult {
pub data: Vec<FoundFileTests>,
}