@@ -934,16 +934,18 @@ pub(crate) fn handle_related_tests(
934934
935935pub ( crate ) fn handle_completion (
936936 snap : GlobalStateSnapshot ,
937- params : lsp_types:: CompletionParams ,
937+ lsp_types :: CompletionParams { text_document_position , context , .. } : lsp_types:: CompletionParams ,
938938) -> anyhow:: Result < Option < lsp_types:: CompletionResponse > > {
939939 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 ) ?;
942942 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 ( ) ) ;
944944
945945 let source_root = snap. analysis . source_root ( position. file_id ) ?;
946946 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 ( ) ) ;
947949 let items = match snap. analysis . completions (
948950 completion_config,
949951 position,
@@ -952,7 +954,6 @@ pub(crate) fn handle_completion(
952954 None => return Ok ( None ) ,
953955 Some ( items) => items,
954956 } ;
955- let line_index = snap. file_line_index ( position. file_id ) ?;
956957
957958 let items = to_proto:: completion_items (
958959 & snap. config ,
@@ -979,16 +980,16 @@ pub(crate) fn handle_completion_resolve(
979980 . into ( ) ) ;
980981 }
981982
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) } ;
986984
987985 let resolve_data: lsp_ext:: CompletionResolveData = serde_json:: from_value ( data) ?;
988986
989987 let file_id = from_proto:: file_id ( & snap, & resolve_data. position . text_document . uri ) ?;
990988 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+ } ;
992993 let source_root = snap. analysis . source_root ( file_id) ?;
993994
994995 let additional_edits = snap
0 commit comments