From 2c421f473b7bb436d669b511b50192decd1d6933 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Thu, 17 Oct 2024 21:14:05 +0800 Subject: [PATCH] fix Fix lsp formmat error in intellij. Change range from u32::Max to i32::Max Signed-off-by: he1pa <18012015693@163.com> --- kclvm/tools/src/LSP/src/formatting.rs | 8 +++++--- kclvm/tools/src/LSP/src/tests.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/kclvm/tools/src/LSP/src/formatting.rs b/kclvm/tools/src/LSP/src/formatting.rs index 383e101fe..0b7833af4 100644 --- a/kclvm/tools/src/LSP/src/formatting.rs +++ b/kclvm/tools/src/LSP/src/formatting.rs @@ -19,7 +19,7 @@ pub fn format( Ok(Some(vec![TextEdit { range: range.unwrap_or(Range::new( Position::new(0, 0), - Position::new(u32::MAX, u32::MAX), + Position::new(i32::MAX as u32, i32::MAX as u32), )), new_text: source, }])) @@ -92,10 +92,12 @@ mod tests { let data_output = data_output.replace("\r\n", "\n"); let expect = vec![TextEdit { - range: Range::new(Position::new(0, 0), Position::new(u32::MAX, u32::MAX)), + range: Range::new( + Position::new(0, 0), + Position::new(i32::MAX as u32, i32::MAX as u32), + ), new_text: data_output, }]; - println!("{:?}", test_file); assert_eq!(expect, got); } diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index 676b58df0..a199ca95c 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -1328,7 +1328,10 @@ fn formatting_test() { assert_eq!( res.result.unwrap(), to_json(Some(vec![TextEdit { - range: Range::new(Position::new(0, 0), Position::new(u32::MAX, u32::MAX),), + range: Range::new( + Position::new(0, 0), + Position::new(i32::MAX as u32, i32::MAX as u32), + ), new_text: "a = 1\n\nb = 2\n\nc = 3\n\nd = 4\n".to_string() }])) .unwrap() @@ -1399,7 +1402,10 @@ fn formatting_unsaved_test() { assert_eq!( res.result.unwrap(), to_json(Some(vec![TextEdit { - range: Range::new(Position::new(0, 0), Position::new(u32::MAX, u32::MAX),), + range: Range::new( + Position::new(0, 0), + Position::new(i32::MAX as u32, i32::MAX as u32), + ), new_text: "unsaved = 0\n\na = 1\n\nb = 2\n\nc = 3\n\nd = 4\n".to_string() }])) .unwrap()