Skip to content

Commit

Permalink
added test for CompileError quick fix
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Mittal <[email protected]>
  • Loading branch information
shashank-iitbhu committed Feb 17, 2024
1 parent a80327e commit 3850faf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"DefaultOciRegistry":"ghcr.io","DefaultOciRepo":"kcl-lang","DefaultOciPlainHttp":false}
Empty file.
2 changes: 2 additions & 0 deletions kclvm/tools/src/LSP/src/test_data/diagnostics.k
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ c: Person = Person {

d = 1
d = 2
number = 2
count = nu
20 changes: 19 additions & 1 deletion kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crossbeam_channel::after;
use crossbeam_channel::select;
use indexmap::IndexSet;
use kclvm_error::diagnostic;
use kclvm_sema::core::global_state::GlobalState;
use lsp_server::RequestId;
use lsp_server::Response;
Expand Down Expand Up @@ -140,6 +141,7 @@ fn build_lsp_diag(
severity: Option<DiagnosticSeverity>,
related_info: Vec<(String, (u32, u32, u32, u32), String)>,
code: Option<NumberOrString>,
data: Option<serde_json::Value>
) -> Diagnostic {
let related_information = if related_info.is_empty() {
None
Expand Down Expand Up @@ -184,7 +186,7 @@ fn build_lsp_diag(
message,
related_information,
tags: None,
data: None,
data,
}
}

Expand All @@ -201,13 +203,15 @@ fn build_expect_diags() -> Vec<Diagnostic> {
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("InvalidSyntax".to_string())),
None,
),
build_lsp_diag(
(0, 0, 0, 10),
"pkgpath abc not found in the program".to_string(),
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("CannotFindModule".to_string())),
None,
),
build_lsp_diag(
(0, 0, 0, 10),
Expand All @@ -218,6 +222,7 @@ fn build_expect_diags() -> Vec<Diagnostic> {
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("CannotFindModule".to_string())),
None,
),
build_lsp_diag(
(8, 0, 8, 1),
Expand All @@ -229,6 +234,7 @@ fn build_expect_diags() -> Vec<Diagnostic> {
"The variable 'd' is declared here".to_string(),
)],
Some(NumberOrString::String("ImmutableError".to_string())),
None,
),
build_lsp_diag(
(7, 0, 7, 1),
Expand All @@ -240,21 +246,33 @@ fn build_expect_diags() -> Vec<Diagnostic> {
"Can not change the value of 'd', because it was declared immutable".to_string(),
)],
Some(NumberOrString::String("ImmutableError".to_string())),
None,
),
build_lsp_diag(
(2, 0, 2, 1),
"expected str, got int(1)".to_string(),
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("TypeError".to_string())),
None,
),
build_lsp_diag(
(10, 8, 10, 10),
"name 'nu' is not defined, did you mean '[\"number\", \"n\", \"num\"]'?".to_string(),
Some(DiagnosticSeverity::ERROR),
vec![],
Some(NumberOrString::String("CompileError".to_string())),
Some(serde_json::json!({ "suggested_replacement": ["number"] })),
),
build_lsp_diag(
(0, 0, 0, 10),
"Module 'abc' imported but unused".to_string(),
Some(DiagnosticSeverity::WARNING),
vec![],
Some(NumberOrString::String("UnusedImportWarning".to_string())),
None,
),

];
expected_diags
}
Expand Down
1 change: 1 addition & 0 deletions kclvm/tools/src/LSP/src/to_lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn kcl_msg_to_lsp_diags(
let data = msg
.suggested_replacement
.as_ref()
.filter(|s| !s.is_empty())
.map(|s| json!({ "suggested_replacement": [s] }));

let related_information = if related_msg.is_empty() {
Expand Down

0 comments on commit 3850faf

Please sign in to comment.