Skip to content

Commit 9842753

Browse files
committed
progress
1 parent c98a67c commit 9842753

File tree

1 file changed

+70
-66
lines changed

1 file changed

+70
-66
lines changed

crates/pgls_lsp/tests/server.rs

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,41 +1000,54 @@ async fn test_invalidate_schema_cache(test_db: PgPool) -> Result<()> {
10001000
let (stream, sink) = client.split();
10011001
let mut server = Server::new(service);
10021002

1003-
let (sender, mut receiver) = channel(CHANNEL_BUFFER_SIZE);
1003+
let (sender, _receiver) = channel(CHANNEL_BUFFER_SIZE);
10041004
let reader = tokio::spawn(client_handler(stream, sink, sender));
10051005

10061006
server.initialize().await?;
10071007
server.initialized().await?;
10081008

10091009
server.load_configuration().await?;
10101010

1011-
// Open a document that references a non-existent 'name' column
1012-
let doc_content = "select name from public.users;";
1011+
// Open a document to get completions from
1012+
let doc_content = "select from public.users;";
10131013
server.open_document(doc_content).await?;
10141014

1015-
// Wait for typecheck diagnostics showing column doesn't exist
1016-
let got_error = tokio::time::timeout(Duration::from_secs(5), async {
1017-
loop {
1018-
match receiver.next().await {
1019-
Some(ServerNotification::PublishDiagnostics(msg)) => {
1020-
if msg
1021-
.diagnostics
1022-
.iter()
1023-
.any(|d| d.message.contains("column \"name\" does not exist"))
1024-
{
1025-
return true;
1026-
}
1027-
}
1028-
_ => continue,
1029-
}
1030-
}
1031-
})
1032-
.await
1033-
.is_ok();
1015+
// Get completions before adding the column - 'name' should NOT be present
1016+
let completions_before = server
1017+
.get_completion(CompletionParams {
1018+
work_done_progress_params: WorkDoneProgressParams::default(),
1019+
partial_result_params: PartialResultParams::default(),
1020+
context: None,
1021+
text_document_position: TextDocumentPositionParams {
1022+
text_document: TextDocumentIdentifier {
1023+
uri: url!("document.sql"),
1024+
},
1025+
position: Position {
1026+
line: 0,
1027+
character: 7,
1028+
},
1029+
},
1030+
})
1031+
.await?
1032+
.unwrap();
1033+
1034+
let items_before = match completions_before {
1035+
CompletionResponse::Array(ref a) => a,
1036+
CompletionResponse::List(ref l) => &l.items,
1037+
};
1038+
1039+
let has_name_before = items_before.iter().any(|item| {
1040+
item.label == "name"
1041+
&& item.label_details.as_ref().is_some_and(|d| {
1042+
d.description
1043+
.as_ref()
1044+
.is_some_and(|desc| desc.contains("public.users"))
1045+
})
1046+
});
10341047

10351048
assert!(
1036-
got_error,
1037-
"Expected typecheck error for non-existent column 'name'"
1049+
!has_name_before,
1050+
"Column 'name' should not be in completions before it's added to the table"
10381051
);
10391052

10401053
// Add the missing column to the database
@@ -1053,51 +1066,42 @@ async fn test_invalidate_schema_cache(test_db: PgPool) -> Result<()> {
10531066
.request::<bool, ()>("pgt/invalidate_schema_cache", "_invalidate_cache", false)
10541067
.await?;
10551068

1056-
// Change the document slightly to trigger re-analysis
1057-
server
1058-
.change_document(
1059-
1,
1060-
vec![TextDocumentContentChangeEvent {
1061-
range: Some(Range {
1062-
start: Position {
1063-
line: 0,
1064-
character: 30,
1065-
},
1066-
end: Position {
1067-
line: 0,
1068-
character: 30,
1069-
},
1070-
}),
1071-
range_length: Some(0),
1072-
text: " ".to_string(),
1073-
}],
1074-
)
1075-
.await?;
1069+
// Get completions after invalidating cache - 'name' should NOW be present
1070+
let completions_after = server
1071+
.get_completion(CompletionParams {
1072+
work_done_progress_params: WorkDoneProgressParams::default(),
1073+
partial_result_params: PartialResultParams::default(),
1074+
context: None,
1075+
text_document_position: TextDocumentPositionParams {
1076+
text_document: TextDocumentIdentifier {
1077+
uri: url!("document.sql"),
1078+
},
1079+
position: Position {
1080+
line: 0,
1081+
character: 7,
1082+
},
1083+
},
1084+
})
1085+
.await?
1086+
.unwrap();
10761087

1077-
// Wait for diagnostics to clear (no typecheck error anymore)
1078-
let error_cleared = tokio::time::timeout(Duration::from_secs(5), async {
1079-
loop {
1080-
match receiver.next().await {
1081-
Some(ServerNotification::PublishDiagnostics(msg)) => {
1082-
// Check that there's no typecheck error for the column
1083-
let has_column_error = msg
1084-
.diagnostics
1085-
.iter()
1086-
.any(|d| d.message.contains("column \"name\" does not exist"));
1087-
if !has_column_error {
1088-
return true;
1089-
}
1090-
}
1091-
_ => continue,
1092-
}
1093-
}
1094-
})
1095-
.await
1096-
.is_ok();
1088+
let items_after = match completions_after {
1089+
CompletionResponse::Array(ref a) => a,
1090+
CompletionResponse::List(ref l) => &l.items,
1091+
};
1092+
1093+
let has_name_after = items_after.iter().any(|item| {
1094+
item.label == "name"
1095+
&& item.label_details.as_ref().is_some_and(|d| {
1096+
d.description
1097+
.as_ref()
1098+
.is_some_and(|desc| desc.contains("public.users"))
1099+
})
1100+
});
10971101

10981102
assert!(
1099-
error_cleared,
1100-
"Expected typecheck error to be cleared after schema cache invalidation"
1103+
has_name_after,
1104+
"Column 'name' should be in completions after schema cache invalidation"
11011105
);
11021106

11031107
server.shutdown().await?;

0 commit comments

Comments
 (0)