Skip to content

Commit

Permalink
fix: fix call arg symbol pos (#1494)
Browse files Browse the repository at this point in the history
* fix: fix call arg symbol pos

Signed-off-by: he1pa <[email protected]>

* fix ut

Signed-off-by: he1pa <[email protected]>

* fix ut

Signed-off-by: he1pa <[email protected]>

---------

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Jul 12, 2024
1 parent eb63521 commit 408f4c4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
filename: "test.k",
line: 1,
column: Some(
28,
22,
),
},
),
Expand Down Expand Up @@ -891,7 +891,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
filename: "test.k",
line: 1,
column: Some(
43,
38,
),
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
filename: "test.k",
line: 3,
column: Some(
25,
19,
),
},
),
Expand Down Expand Up @@ -1093,7 +1093,7 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
filename: "test.k",
line: 3,
column: Some(
40,
35,
),
},
),
Expand Down
4 changes: 2 additions & 2 deletions kclvm/sema/src/advanced_resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ impl<'ctx> AdvancedResolver<'ctx> {
if let Some(value) = &kw.node.value {
self.expr(value)?;
}
let (start_pos, end_pos): Range = kw.get_span_pos();
let (start_pos, end_pos): Range = kw.node.arg.get_span_pos();
let value = self.gs.get_symbols_mut().alloc_value_symbol(
ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false),
self.ctx.get_node_key(&kw.id),
Expand Down Expand Up @@ -1383,7 +1383,7 @@ impl<'ctx> AdvancedResolver<'ctx> {
if let Some(value) = &kw.node.value {
self.expr(value)?;
}
let (start_pos, end_pos): Range = kw.get_span_pos();
let (start_pos, end_pos): Range = kw.node.arg.get_span_pos();
let value = self.gs.get_symbols_mut().alloc_value_symbol(
ValueSymbol::new(kw.node.arg.node.get_name(), start_pos, end_pos, None, false),
self.ctx.get_node_key(&kw.id),
Expand Down
38 changes: 21 additions & 17 deletions kclvm/tools/src/LSP/src/semantic_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,7 @@ mod tests {
#[test]
#[bench_test]
fn semantic_tokens_full_test() {
let (file, _, _, gs) = compile_test_file("src/test_data/sema_token.k");
let expected = [
(0, 15, 1, 3), // m
(1, 5, 3, 4), // num
(1, 7, 7, 1), // Persons
(1, 4, 4, 2), // name
(2, 0, 2, 0), // p5
(0, 4, 7, 1), // Persons
(0, 10, 7, 1), // Persons
(1, 4, 4, 2), // name
(2, 0, 1, 0), // n
(0, 3, 3, 4), // num
(2, 0, 4, 8), // func
(0, 14, 1, 0), // x
(1, 4, 1, 0), // x
];
let (file, _, _, gs) = compile_test_file("src/test_data/sema_token/sema_token.k");
let res = semantic_tokens_full(&file, &gs);
if let Some(tokens) = res {
match &tokens {
Expand All @@ -185,7 +170,26 @@ mod tests {
)
})
.collect();
assert_eq!(get, expected);
// (delta line, delta col(if delta line != 0, from 0), length, kind)
// (0, 15, 1, 3), // m
// (1, 5, 3, 4), // num
// (1, 7, 7, 1), // Persons
// (1, 4, 4, 2), // name
// (2, 0, 2, 0), // p5
// (0, 4, 7, 1), // Persons
// (0, 10, 7, 1), // Persons
// (1, 4, 4, 2), // name
// (2, 0, 1, 0), // n
// (0, 3, 3, 4), // num
// (2, 0, 4, 8), // func
// (0, 14, 1, 0), // x
// (1, 4, 1, 0), // x
// (3, 0, 1, 0), // a
// (0, 4, 4, 8), // func
// (1, 0, 1, 0), // b
// (0, 4, 4, 8), // func
// (0, 5, 1, 0) // x
insta::assert_snapshot!(format!("{:?}", get));
}
lsp_types::SemanticTokensResult::Partial(_) => {
panic!("test failed")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tools/src/LSP/src/semantic_token.rs
expression: "format!(\"{:?}\", get)"
---
[(0, 15, 1, 3), (1, 5, 3, 4), (1, 7, 7, 1), (1, 4, 4, 2), (2, 0, 2, 0), (0, 4, 7, 1), (0, 10, 7, 1), (1, 4, 4, 2), (2, 0, 1, 0), (0, 3, 3, 4), (2, 0, 4, 8), (0, 14, 1, 0), (1, 4, 1, 0), (3, 0, 1, 0), (0, 4, 4, 8), (1, 0, 1, 0), (0, 4, 4, 8), (0, 5, 1, 0)]
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ n: num = 1

func = lambda x{
x
}
}

a = func("123")
b = func(x="123")
4 changes: 2 additions & 2 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ fn build_expect_diags() -> Vec<Diagnostic> {
),
build_lsp_diag(
(10, 8, 10, 10),
"name 'nu' is not defined, did you mean '[\"number\", \"n\", \"num\"]'?".to_string(),
"name 'nu' is not defined, did you mean '[\"number\"]'?".to_string(),
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("CompileError".to_string())),
Some(serde_json::json!({ "suggested_replacement": ["number", "n", "num"] })),
Some(serde_json::json!({ "suggested_replacement": ["number"] })),
),
build_lsp_diag(
(0, 0, 0, 10),
Expand Down

0 comments on commit 408f4c4

Please sign in to comment.