1- use crate :: { adapters:: get_cursor_position, session:: Session } ;
1+ use crate :: {
2+ adapters:: { self , get_cursor_position} ,
3+ diagnostics:: LspError ,
4+ session:: Session ,
5+ } ;
26use anyhow:: Result ;
37use pgt_workspace:: { WorkspaceError , features:: completions:: GetCompletionsParams } ;
4- use tower_lsp:: lsp_types:: { self , CompletionItem , CompletionItemLabelDetails } ;
8+ use tower_lsp:: lsp_types:: { self , CompletionItem , CompletionItemLabelDetails , TextEdit } ;
59
610#[ tracing:: instrument( level = "debug" , skip( session) , err) ]
711pub fn get_completions (
812 session : & Session ,
913 params : lsp_types:: CompletionParams ,
10- ) -> Result < lsp_types:: CompletionResponse > {
14+ ) -> Result < lsp_types:: CompletionResponse , LspError > {
1115 let url = params. text_document_position . text_document . uri ;
1216 let path = session. file_path ( & url) ?;
1317
18+ let doc = session. document ( & url) ?;
19+ let encoding = adapters:: negotiated_encoding ( session. client_capabilities ( ) . unwrap ( ) ) ;
20+
1421 let completion_result = match session. workspace . get_completions ( GetCompletionsParams {
1522 path,
1623 position : get_cursor_position ( session, & url, params. text_document_position . position ) ?,
@@ -36,6 +43,12 @@ pub fn get_completions(
3643 } ) ,
3744 preselect : Some ( i. preselected ) ,
3845 sort_text : Some ( i. sort_text ) ,
46+ text_edit : i. completion_text . map ( |c| {
47+ lsp_types:: CompletionTextEdit :: Edit ( TextEdit {
48+ new_text : c. text ,
49+ range : adapters:: to_lsp:: range ( & doc. line_index , c. range , encoding) . unwrap ( ) ,
50+ } )
51+ } ) ,
3952 kind : Some ( to_lsp_types_completion_item_kind ( i. kind ) ) ,
4053 ..CompletionItem :: default ( )
4154 } )
0 commit comments