@@ -934,16 +934,18 @@ pub(crate) fn handle_related_tests(
934
934
935
935
pub ( crate ) fn handle_completion (
936
936
snap : GlobalStateSnapshot ,
937
- params : lsp_types:: CompletionParams ,
937
+ lsp_types :: CompletionParams { text_document_position , context , .. } : lsp_types:: CompletionParams ,
938
938
) -> anyhow:: Result < Option < lsp_types:: CompletionResponse > > {
939
939
let _p = tracing:: span!( tracing:: Level :: INFO , "handle_completion" ) . entered ( ) ;
940
- let text_document_position = params . text_document_position . clone ( ) ;
941
- let position = from_proto :: file_position ( & snap, params . text_document_position ) ?;
940
+ let mut position = from_proto :: file_position ( & snap , text_document_position ) ? ;
941
+ let line_index = snap. file_line_index ( position . file_id ) ?;
942
942
let completion_trigger_character =
943
- params . context . and_then ( |ctx| ctx. trigger_character ) . and_then ( |s| s. chars ( ) . next ( ) ) ;
943
+ context. and_then ( |ctx| ctx. trigger_character ) . and_then ( |s| s. chars ( ) . next ( ) ) ;
944
944
945
945
let source_root = snap. analysis . source_root ( position. file_id ) ?;
946
946
let completion_config = & snap. config . completion ( Some ( source_root) ) ;
947
+ // FIXME: We should fix up the position when retrying the cancelled request instead
948
+ position. offset = position. offset . min ( line_index. index . len ( ) ) ;
947
949
let items = match snap. analysis . completions (
948
950
completion_config,
949
951
position,
@@ -952,7 +954,6 @@ pub(crate) fn handle_completion(
952
954
None => return Ok ( None ) ,
953
955
Some ( items) => items,
954
956
} ;
955
- let line_index = snap. file_line_index ( position. file_id ) ?;
956
957
957
958
let items = to_proto:: completion_items (
958
959
& snap. config ,
@@ -979,16 +980,16 @@ pub(crate) fn handle_completion_resolve(
979
980
. into ( ) ) ;
980
981
}
981
982
982
- let data = match original_completion. data . take ( ) {
983
- Some ( it) => it,
984
- None => return Ok ( original_completion) ,
985
- } ;
983
+ let Some ( data) = original_completion. data . take ( ) else { return Ok ( original_completion) } ;
986
984
987
985
let resolve_data: lsp_ext:: CompletionResolveData = serde_json:: from_value ( data) ?;
988
986
989
987
let file_id = from_proto:: file_id ( & snap, & resolve_data. position . text_document . uri ) ?;
990
988
let line_index = snap. file_line_index ( file_id) ?;
991
- let offset = from_proto:: offset ( & line_index, resolve_data. position . position ) ?;
989
+ // FIXME: We should fix up the position when retrying the cancelled request instead
990
+ let Ok ( offset) = from_proto:: offset ( & line_index, resolve_data. position . position ) else {
991
+ return Ok ( original_completion) ;
992
+ } ;
992
993
let source_root = snap. analysis . source_root ( file_id) ?;
993
994
994
995
let additional_edits = snap
0 commit comments