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
#[cfg(test)]
mod tests {
use crate::handlers::test_lib::{ProviderVirtualWorkspace, VirtualSemanticToken, check};
use googletest::prelude::*;
use lsp_types::{SemanticTokenModifier, SemanticTokenType};
use std::collections::HashSet;
#[gtest]
fn test_1() -> Result<()> {
let mut ws = ProviderVirtualWorkspace::new();
ws.def(
r#"
---@class Cast1
---@field get fun(self: self, a: number): Cast1?
"#,
);
check!(ws.check_semantic_token(
r#"
---@type Cast1
local A
local _a = A:get(1) --[[@cast -?]]:get(2)
"#,
vec![
VirtualSemanticToken {
line: 1,
start: 16,
length: 3,
token_type: SemanticTokenType::COMMENT,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 1,
start: 19,
length: 1,
token_type: SemanticTokenType::KEYWORD,
token_modifier: HashSet::from([SemanticTokenModifier::DOCUMENTATION]),
},
VirtualSemanticToken {
line: 1,
start: 20,
length: 4,
token_type: SemanticTokenType::KEYWORD,
token_modifier: HashSet::from([SemanticTokenModifier::DOCUMENTATION]),
},
VirtualSemanticToken {
line: 1,
start: 25,
length: 5,
token_type: SemanticTokenType::TYPE,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 2,
start: 22,
length: 1,
token_type: SemanticTokenType::VARIABLE,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 22,
length: 2,
token_type: SemanticTokenType::VARIABLE,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 27,
length: 1,
token_type: SemanticTokenType::VARIABLE,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 29,
length: 3,
token_type: SemanticTokenType::FUNCTION,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 33,
length: 1,
token_type: SemanticTokenType::NUMBER,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 36,
length: 4,
token_type: SemanticTokenType::COMMENT,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 40,
length: 1,
token_type: SemanticTokenType::KEYWORD,
token_modifier: HashSet::from([SemanticTokenModifier::DOCUMENTATION]),
},
VirtualSemanticToken {
line: 4,
start: 41,
length: 4,
token_type: SemanticTokenType::KEYWORD,
token_modifier: HashSet::from([SemanticTokenModifier::DOCUMENTATION]),
},
VirtualSemanticToken {
line: 4,
start: 46,
length: 1,
token_type: SemanticTokenType::OPERATOR,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 47,
length: 1,
token_type: SemanticTokenType::OPERATOR,
token_modifier: HashSet::from([SemanticTokenModifier::DOCUMENTATION]),
},
VirtualSemanticToken {
line: 4,
start: 51,
length: 3,
token_type: SemanticTokenType::FUNCTION,
token_modifier: HashSet::new(),
},
VirtualSemanticToken {
line: 4,
start: 55,
length: 1,
token_type: SemanticTokenType::NUMBER,
token_modifier: HashSet::new(),
},
],
));
Ok(())
}
}