More lsp endpoints we were missing (#6612)

* add prepare rename

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add document color

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-04-30 19:47:36 -07:00
committed by GitHub
parent 2d77aa0d36
commit b686c79b49
10 changed files with 529 additions and 76 deletions

View File

@ -3,8 +3,8 @@ use std::collections::{BTreeMap, HashMap};
use pretty_assertions::assert_eq;
use tower_lsp::{
lsp_types::{
CodeActionKind, CodeActionOrCommand, Diagnostic, SemanticTokenModifier, SemanticTokenType, TextEdit,
WorkspaceEdit,
CodeActionKind, CodeActionOrCommand, Diagnostic, PrepareRenameResponse, SemanticTokenModifier,
SemanticTokenType, TextEdit, WorkspaceEdit,
},
LanguageServer,
};
@ -4146,3 +4146,173 @@ async fn kcl_test_kcl_lsp_code_actions_lint_offset_planes() {
})
);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_kcl_lsp_prepare_rename() {
let server = kcl_lsp_server(false).await.unwrap();
// Send open file.
server
.did_open(tower_lsp::lsp_types::DidOpenTextDocumentParams {
text_document: tower_lsp::lsp_types::TextDocumentItem {
uri: "file:///test.kcl".try_into().unwrap(),
language_id: "kcl".to_string(),
version: 1,
text: r#"thing= 1"#.to_string(),
},
})
.await;
// Send rename request.
let result = server
.prepare_rename(tower_lsp::lsp_types::TextDocumentPositionParams {
text_document: tower_lsp::lsp_types::TextDocumentIdentifier {
uri: "file:///test.kcl".try_into().unwrap(),
},
position: tower_lsp::lsp_types::Position { line: 0, character: 2 },
})
.await
.unwrap()
.unwrap();
// Check the result.
assert_eq!(
result,
PrepareRenameResponse::DefaultBehavior { default_behavior: true }
);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_kcl_lsp_document_color() {
let server = kcl_lsp_server(false).await.unwrap();
// Send open file.
server
.did_open(tower_lsp::lsp_types::DidOpenTextDocumentParams {
text_document: tower_lsp::lsp_types::TextDocumentItem {
uri: "file:///test.kcl".try_into().unwrap(),
language_id: "kcl".to_string(),
version: 1,
text: r#"// Add color to a revolved solid.
sketch001 = startSketchOn(XY)
|> circle(center = [15, 0], radius = 5)
|> revolve(angle = 360, axis = Y)
|> appearance(color = '#ff0000', metalness = 90, roughness = 90)"#
.to_string(),
},
})
.await;
// Send document color request.
let result = server
.document_color(tower_lsp::lsp_types::DocumentColorParams {
text_document: tower_lsp::lsp_types::TextDocumentIdentifier {
uri: "file:///test.kcl".try_into().unwrap(),
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
})
.await
.unwrap();
// Check the result.
assert_eq!(
result,
vec![tower_lsp::lsp_types::ColorInformation {
range: tower_lsp::lsp_types::Range {
start: tower_lsp::lsp_types::Position { line: 4, character: 24 },
end: tower_lsp::lsp_types::Position { line: 4, character: 33 },
},
color: tower_lsp::lsp_types::Color {
red: 1.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
},
}]
);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_kcl_lsp_color_presentation() {
let server = kcl_lsp_server(false).await.unwrap();
let text = r#"// Add color to a revolved solid.
sketch001 = startSketchOn(XY)
|> circle(center = [15, 0], radius = 5)
|> revolve(angle = 360, axis = Y)
|> appearance(color = '#ff0000', metalness = 90, roughness = 90)"#;
// Send open file.
server
.did_open(tower_lsp::lsp_types::DidOpenTextDocumentParams {
text_document: tower_lsp::lsp_types::TextDocumentItem {
uri: "file:///test.kcl".try_into().unwrap(),
language_id: "kcl".to_string(),
version: 1,
text: text.to_string(),
},
})
.await;
// Send document color request.
let result = server
.document_color(tower_lsp::lsp_types::DocumentColorParams {
text_document: tower_lsp::lsp_types::TextDocumentIdentifier {
uri: "file:///test.kcl".try_into().unwrap(),
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
})
.await
.unwrap();
// Check the result.
assert_eq!(
result,
vec![tower_lsp::lsp_types::ColorInformation {
range: tower_lsp::lsp_types::Range {
start: tower_lsp::lsp_types::Position { line: 4, character: 24 },
end: tower_lsp::lsp_types::Position { line: 4, character: 33 },
},
color: tower_lsp::lsp_types::Color {
red: 1.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
},
}]
);
// Send color presentation request.
let result = server
.color_presentation(tower_lsp::lsp_types::ColorPresentationParams {
text_document: tower_lsp::lsp_types::TextDocumentIdentifier {
uri: "file:///test.kcl".try_into().unwrap(),
},
range: tower_lsp::lsp_types::Range {
start: tower_lsp::lsp_types::Position { line: 4, character: 24 },
end: tower_lsp::lsp_types::Position { line: 4, character: 33 },
},
color: tower_lsp::lsp_types::Color {
red: 1.0,
green: 0.0,
blue: 1.0,
alpha: 1.0,
},
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
})
.await
.unwrap();
// Check the result.
assert_eq!(
result,
vec![tower_lsp::lsp_types::ColorPresentation {
label: "#ff00ff".to_string(),
text_edit: None,
additional_text_edits: None,
}]
);
}