Skip to content

Commit 2fb6417

Browse files
committed
wip OLS01007
1 parent 7b20b19 commit 2fb6417

File tree

5 files changed

+166
-2
lines changed

5 files changed

+166
-2
lines changed

server/src/core/file_mgr.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct FileInfo {
8989
pub noqas_blocs: HashMap<u32, NoqaInfo>,
9090
noqas_lines: HashMap<u32, NoqaInfo>,
9191
diagnostic_filters: Vec<DiagnosticFilter>,
92+
93+
pub diag_test_comments: Vec<(u32, Vec<String>)>, //for tests: line and list of codes
9294
}
9395

9496
impl FileInfo {
@@ -109,6 +111,7 @@ impl FileInfo {
109111
noqas_blocs: HashMap::new(),
110112
noqas_lines: HashMap::new(),
111113
diagnostic_filters: Vec::new(),
114+
diag_test_comments: vec![],
112115
}
113116
}
114117
pub fn update(&mut self, session: &mut SessionInfo, uri: &str, content: Option<&Vec<TextDocumentContentChangeEvent>>, version: Option<i32>, in_workspace: bool, force: bool) -> bool {
@@ -191,7 +194,7 @@ impl FileInfo {
191194
if in_workspace {
192195
self.noqas_blocs.clear();
193196
self.noqas_lines.clear();
194-
self.extract_tokens(&parsed_module, &source);
197+
self.extract_tokens(&parsed_module, &source, session.sync_odoo.test_mode);
195198
}
196199
self.valid = true;
197200
for error in parsed_module.errors().iter() {
@@ -229,7 +232,7 @@ impl FileInfo {
229232
self._build_ast(session, session.sync_odoo.get_file_mgr().borrow().is_in_workspace(&self.uri));
230233
}
231234

232-
pub fn extract_tokens(&mut self, parsed_module: &Parsed<ModModule>, source: &String) {
235+
pub fn extract_tokens(&mut self, parsed_module: &Parsed<ModModule>, source: &String, parse_test_comments: bool) {
233236
let mut is_first_expr: bool = true;
234237
let mut noqa_to_add = None;
235238
let mut previous_token: Option<&Token> = None;
@@ -269,6 +272,14 @@ impl FileInfo {
269272
}
270273
}
271274
}
275+
if parse_test_comments {
276+
if text.starts_with("#OLS") || text.starts_with("# OLS") {
277+
let codes = text.split(",").map(|s| s.trim().trim_start_matches('#').trim().to_string()).collect::<Vec<String>>();
278+
let char = self.file_info_ast.borrow().text_rope.as_ref().unwrap().try_byte_to_char(token.start().to_usize()).expect("unable to get char from bytes");
279+
let line = self.file_info_ast.borrow().text_rope.as_ref().unwrap().try_char_to_line(char).ok().expect("unable to get line from char");
280+
self.diag_test_comments.push((line as u32, codes));
281+
}
282+
}
272283
},
273284
TokenKind::Class | TokenKind::Def => {
274285
if noqa_to_add.is_some() {

server/src/core/odoo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub struct SyncOdoo {
9595
pub import_cache: Option<ImportCache>,
9696
pub capabilities: lsp_types::ClientCapabilities,
9797
pub opened_files: Vec<String>,
98+
99+
pub test_mode: bool,
98100
}
99101

100102
unsafe impl Send for SyncOdoo {}
@@ -137,6 +139,8 @@ impl SyncOdoo {
137139
import_cache: None,
138140
capabilities: lsp_types::ClientCapabilities::default(),
139141
opened_files: vec![],
142+
143+
test_mode: false,
140144
};
141145
sync_odoo
142146
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
def a():
2+
pass
3+
4+
a()
5+
a(5) #OLS01007
6+
7+
def b(value):
8+
pass
9+
10+
b() # OLS01007
11+
b(10)
12+
13+
def c(x = 7):
14+
pass
15+
16+
c()
17+
c(5)
18+
c(5, 9) # OLS01007
19+
20+
def d(x, y=0):
21+
pass
22+
23+
d() # OLS01007
24+
d(5)
25+
d(5, 6)
26+
d(5, 6, 7) # OLS01007
27+
28+
def e(*args):
29+
pass
30+
31+
e()
32+
e(1)
33+
e(1, 2, 3)
34+
35+
def f(x, *args):
36+
pass
37+
38+
f() # OLS01007
39+
f(1)
40+
f(1, 2)
41+
f(1, 2, 3)
42+
43+
def g(x, y, *args):
44+
pass
45+
46+
g() # OLS01007
47+
g(1) # OLS01007
48+
g(1, 2)
49+
g(1, 2, 3)
50+
g(1, 2, 3, 4)
51+
52+
def h(x, y=10, *args):
53+
pass
54+
55+
h() # OLS01007
56+
h(1)
57+
h(1, 2)
58+
h(1, 2, 3)
59+
60+
def i(x, y, z=0):
61+
pass
62+
63+
i() # OLS01007
64+
i(1) # OLS01007
65+
i(1, 2)
66+
i(1, 2, 3)
67+
i(1, 2, 3, 4) # OLS01007
68+
69+
# Position-only parameters (Python 3.8+)
70+
def j(x, y, /):
71+
pass
72+
73+
j(1, 2)
74+
j(1) # OLS01007
75+
j(x=1, y=2) # OLS01007 (positional-only)
76+
j(1, 2, 3) # OLS01007
77+
78+
def k(x, /, y, z=0):
79+
pass
80+
81+
k(1, 2)
82+
k(1, 2, 3)
83+
k(1) # OLS01007
84+
k(1, 2, 3, 4) # OLS01007
85+
k(x=1, y=2) # OLS01007
86+
87+
# Keyword-only parameters (after a bare *)
88+
def l(*, x):
89+
pass
90+
91+
l(x=1)
92+
l() # OLS01007
93+
l(1) # OLS01007
94+
95+
def m(a, *, x, y=3):
96+
pass
97+
98+
m(1, x=2)
99+
m(1, x=2, y=4)
100+
m(1) # OLS01007
101+
m(1, 2) # OLS01007
102+
103+
# Mixed positional-only + regular + keyword-only
104+
def n(a, b, /, c, *, d, e=0):
105+
pass
106+
107+
n(1, 2, 3, d=4)
108+
n(1, 2, 3, d=4, e=5)
109+
n(1, 2, c=3, d=4)
110+
n(a=1, b=2, c=3, d=4) # OLS01007 (a/b positional-only)
111+
n(1, 2) # OLS01007
112+
n(1, 2, 3) # OLS01007 (missing keyword-only d)
113+
n(1, 2, 3, 4, d=5) # OLS01007 (too many positional arguments)
114+
115+
# Functions mixing defaults and varargs + keywords
116+
def o(a, b=1, *args, c, d=0):
117+
pass
118+
119+
o(1, c=2)
120+
o(1, 2, c=3)
121+
o(1, 2, 3, 4, c=5)
122+
o() # OLS01007
123+
o(1) # OLS01007 (missing c)
124+
o(1, 2, 3, d=5) # OLS01007 (missing c)
125+
o(1, 2, c=3, 5) # OLS01000 (positional after keyword)
126+
127+
# Fully variadic keyword-only
128+
def p(**kwargs):
129+
pass
130+
131+
p()
132+
p(x=1, y=2)
133+
134+
# Positional + keyword-only interaction
135+
def q(a, b, *, x, y=10):
136+
pass
137+
138+
q(1, 2, x=3)
139+
q(1, 2, x=3, y=4)
140+
q(1, 2) # OLS01007
141+
q(1, 2, 3) # OLS01007
142+
q(a=1, b=2, x=3) # valid
143+
q(a=1, b=2, 3) # OLS01000 (positional after keyword)

server/tests/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod ols01003;
66
pub mod ols01004;
77
pub mod ols01005;
88
pub mod ols01006;
9+
pub mod ols01007;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#[test]
3+
fn test_ols01007() {
4+
panic!("Not implemented yet");
5+
}

0 commit comments

Comments
 (0)