summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/language_server.rs62
-rw-r--r--cli/lsp/tsc.rs5
2 files changed, 65 insertions, 2 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 74dcf2136..b55c38189 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -3025,6 +3025,68 @@ mod tests {
harness.run().await;
}
+ #[tokio::test]
+ async fn test_completions_optional() {
+ let mut harness = LspTestHarness::new(vec![
+ ("initialize_request.json", LspResponse::RequestAny),
+ ("initialized_notification.json", LspResponse::None),
+ (
+ "did_open_notification_completion_optional.json",
+ LspResponse::None,
+ ),
+ (
+ "completion_request_optional.json",
+ LspResponse::Request(
+ 2,
+ json!({
+ "isIncomplete": false,
+ "items": [
+ {
+ "label": "b?",
+ "kind": 5,
+ "sortText": "1",
+ "filterText": "b",
+ "insertText": "b",
+ "data": {
+ "tsc": {
+ "specifier": "file:///a/file.ts",
+ "position": 79,
+ "name": "b",
+ "useCodeSnippet": false
+ }
+ }
+ }
+ ]
+ }),
+ ),
+ ),
+ (
+ "completion_resolve_request_optional.json",
+ LspResponse::Request(
+ 4,
+ json!({
+ "label": "b?",
+ "kind": 5,
+ "detail": "(property) A.b?: string | undefined",
+ "documentation": {
+ "kind": "markdown",
+ "value": ""
+ },
+ "sortText": "1",
+ "filterText": "b",
+ "insertText": "b"
+ }),
+ ),
+ ),
+ (
+ "shutdown_request.json",
+ LspResponse::Request(3, json!(null)),
+ ),
+ ("exit_notification.json", LspResponse::None),
+ ]);
+ harness.run().await;
+ }
+
#[derive(Deserialize)]
struct PerformanceAverages {
averages: Vec<PerformanceAverage>,
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 1e7ae6f89..7b7f791d0 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -1188,10 +1188,10 @@ impl CompletionEntry {
}
let text_edit =
- if let (Some(text_span), Some(new_text)) = (range, insert_text) {
+ if let (Some(text_span), Some(new_text)) = (range, &insert_text) {
let range = text_span.to_range(line_index);
let insert_replace_edit = lsp::InsertReplaceEdit {
- new_text,
+ new_text: new_text.clone(),
insert: range,
replace: range,
};
@@ -1216,6 +1216,7 @@ impl CompletionEntry {
preselect,
text_edit,
filter_text,
+ insert_text,
detail,
tags,
data: Some(json!({