-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrequest.rs
More file actions
146 lines (136 loc) · 4.04 KB
/
Copy pathrequest.rs
File metadata and controls
146 lines (136 loc) · 4.04 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// SPDX-License-Identifier: Apache-2.0
use std::path::PathBuf;
use code2graph::{RefRole, SymbolId, SymbolKind};
use crate::config::GlobalOptions;
/// A complete, owned CLI invocation suitable for host-side tests or embedding.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CliRequest {
pub global: GlobalOptions,
pub command: CommandRequest,
}
/// The selected CLI operation. These are requests only: no variant performs I/O.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandRequest {
Index {
path: Option<PathBuf>,
force: bool,
trust_mtime: bool,
},
Status,
Symbols {
text: String,
file: Option<String>,
kind: Option<SymbolKind>,
case_sensitive: bool,
},
Def {
selector: Selector,
file: Option<String>,
kind: Option<SymbolKind>,
require_unique: bool,
},
Callers {
selector: Selector,
file: Option<String>,
kind: Option<SymbolKind>,
require_unique: bool,
role: Option<RefRole>,
},
Callees {
selector: Selector,
file: Option<String>,
kind: Option<SymbolKind>,
require_unique: bool,
role: Option<RefRole>,
},
Impact {
selector: Selector,
file: Option<String>,
kind: Option<SymbolKind>,
require_unique: bool,
role: Option<RefRole>,
depth: u32,
},
Usages {
selector: Selector,
file: Option<String>,
kind: Option<SymbolKind>,
require_unique: bool,
role: Option<RefRole>,
},
DiffImpact {
base: Option<String>,
role: Option<RefRole>,
depth: u32,
},
Imports {
file: String,
},
ModuleDeps,
References {
file: String,
name: Option<String>,
role: Option<RefRole>,
},
Cache {
op: CacheOp,
},
}
/// A cache-management operation. These are requests only: no variant performs I/O.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CacheOp {
/// Report this project's cache directory and database path.
Path,
/// Report cache footprint and per-snapshot breakdown.
Status,
/// Delete this project's cache, or every project's cache with `all`.
Clear { all: bool },
}
impl CommandRequest {
/// Stable command spelling for diagnostics and host capability errors.
pub const fn name(&self) -> &'static str {
match self {
Self::Index { .. } => "index",
Self::Status => "status",
Self::Symbols { .. } => "symbols",
Self::Def { .. } => "def",
Self::Callers { .. } => "callers",
Self::Callees { .. } => "callees",
Self::Impact { .. } => "impact",
Self::DiffImpact { .. } => "diff-impact",
Self::Usages { .. } => "usages",
Self::Imports { .. } => "imports",
Self::ModuleDeps => "module-deps",
Self::References { .. } => "references",
Self::Cache { .. } => "cache",
}
}
/// Effective resolved-edge role filter. Call traversal defaults to calls;
/// `usages` deliberately keeps `None` to mean every role.
pub fn effective_relation_role(&self) -> Option<RefRole> {
match self {
Self::Callers { role, .. } | Self::Callees { role, .. } | Self::Impact { role, .. } => {
Some(role.unwrap_or(RefRole::Call))
}
Self::Usages { role, .. } => *role,
_ => None,
}
}
}
/// Exactly one non-guessing symbol selector.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Selector {
Name(String),
/// Exact lossless structural identity decoded through `SymbolId` serde.
Id(SymbolId),
/// A plural SCIP display lookup, never an exact structural identity.
Scip(String),
Position(SourcePosition),
}
/// Human source position. Both coordinates are 1-based; omitted column is one.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourcePosition {
pub file: String,
pub line: u32,
pub column: u32,
}