@@ -6,7 +6,6 @@ use std::sync::Arc;
66use deno_core:: anyhow:: anyhow;
77use deno_core:: error:: AnyError ;
88use deno_core:: futures:: future:: Shared ;
9- use deno_core:: serde_json:: json;
109use deno_resolver:: deno_json:: CompilerOptionsKey ;
1110use indexmap:: IndexMap ;
1211use indexmap:: IndexSet ;
@@ -269,7 +268,7 @@ impl TsServer {
269268 let code_lenses = crate :: lsp:: code_lens:: collect_tsc (
270269 & module. uri ,
271270 settings,
272- module. line_index . clone ( ) ,
271+ & module. line_index ,
273272 & navigation_tree,
274273 token,
275274 ) ?;
@@ -310,7 +309,7 @@ impl TsServer {
310309 return Err ( anyhow ! ( "request cancelled" ) ) ;
311310 }
312311 item. collect_document_symbols (
313- module. line_index . clone ( ) ,
312+ & module. line_index ,
314313 & mut document_symbols,
315314 ) ;
316315 }
@@ -492,40 +491,35 @@ impl TsServer {
492491 o. contains ( & lsp:: CodeActionKind :: SOURCE_ORGANIZE_IMPORTS )
493492 } )
494493 {
495- let document_has_errors = context. diagnostics . iter ( ) . any ( |d| {
496- // Assume diagnostics without a severity are errors
497- d. severity
498- . is_none_or ( |s| s == lsp:: DiagnosticSeverity :: ERROR )
499- } ) ;
500494 let organize_imports_edit = ts_server
501- . organize_imports (
502- snapshot. clone ( ) ,
503- module,
504- document_has_errors,
505- token,
506- )
495+ . organize_imports ( snapshot. clone ( ) , module, token)
507496 . await
508497 . map_err ( |err| {
509498 anyhow ! (
510499 "Unable to get organize imports edit from TypeScript: {:#}" ,
511500 err
512501 )
513502 } ) ?;
514- if ! organize_imports_edit. is_empty ( ) {
515- let changes_with_modules = organize_imports_edit
503+ let text_edits = organize_imports_edit. first ( ) . map ( |c| {
504+ c . text_changes
516505 . iter ( )
517- . map ( |c| ( c, module) )
518- . collect :: < IndexMap < _ , _ > > ( ) ;
506+ . map ( |c| c. as_text_edit ( & module. line_index ) )
507+ . collect :: < Vec < _ > > ( )
508+ } ) ;
509+ if let Some ( text_edits) = text_edits
510+ && !text_edits. is_empty ( )
511+ {
519512 actions. push ( lsp:: CodeActionOrCommand :: CodeAction (
520513 lsp:: CodeAction {
521- title : "Organize imports " . to_string ( ) ,
514+ title : "Organize Imports " . to_string ( ) ,
522515 kind : Some ( lsp:: CodeActionKind :: SOURCE_ORGANIZE_IMPORTS ) ,
523- edit : file_text_changes_to_workspace_edit (
524- changes_with_modules,
525- & snapshot,
526- token,
527- ) ?,
528- data : Some ( json ! ( { "uri" : & module. uri} ) ) ,
516+ edit : Some ( lsp:: WorkspaceEdit {
517+ changes : Some (
518+ std:: iter:: once ( ( module. uri . as_ref ( ) . clone ( ) , text_edits) )
519+ . collect ( ) ,
520+ ) ,
521+ ..Default :: default ( )
522+ } ) ,
529523 ..Default :: default ( )
530524 } ,
531525 ) ) ;
@@ -564,11 +558,9 @@ impl TsServer {
564558 highlights
565559 . into_iter ( )
566560 . map ( |dh| {
567- dh. to_highlight ( module. line_index . clone ( ) , token) . map_err (
568- |err| {
569- anyhow ! ( "Unable to convert document highlights: {:#}" , err)
570- } ,
571- )
561+ dh. to_highlight ( & module. line_index , token) . map_err ( |err| {
562+ anyhow ! ( "Unable to convert document highlights: {:#}" , err)
563+ } )
572564 } )
573565 . collect :: < Result < Vec < _ > , _ > > ( )
574566 . map ( |s| s. into_iter ( ) . flatten ( ) . collect ( ) )
@@ -691,7 +683,7 @@ impl TsServer {
691683 . map ( |completion_info| {
692684 completion_info
693685 . as_completion_response (
694- module. line_index . clone ( ) ,
686+ & module. line_index ,
695687 & snapshot
696688 . config
697689 . language_settings_for_specifier ( & module. specifier )
@@ -860,7 +852,7 @@ impl TsServer {
860852 return Err ( anyhow ! ( "request cancelled" ) ) ;
861853 }
862854 Ok ( span. to_folding_range (
863- module. line_index . clone ( ) ,
855+ & module. line_index ,
864856 module. text . as_bytes ( ) ,
865857 snapshot. config . line_folding_only_capable ( ) ,
866858 ) )
@@ -1112,9 +1104,8 @@ impl TsServer {
11121104 token,
11131105 )
11141106 . await ?;
1115- selection_ranges. push (
1116- selection_range. to_selection_range ( module. line_index . clone ( ) ) ,
1117- ) ;
1107+ selection_ranges
1108+ . push ( selection_range. to_selection_range ( & module. line_index ) ) ;
11181109 }
11191110 Ok ( Some ( selection_ranges) )
11201111 }
@@ -1144,7 +1135,7 @@ impl TsServer {
11441135 token,
11451136 )
11461137 . await ?
1147- . to_semantic_tokens ( module. line_index . clone ( ) , token) ,
1138+ . to_semantic_tokens ( & module. line_index , token) ,
11481139 // TODO(nayeemrmn): Fix when tsgo supports semantic tokens.
11491140 Self :: Go ( _) => Ok ( Default :: default ( ) ) ,
11501141 }
@@ -1184,7 +1175,7 @@ impl TsServer {
11841175 token,
11851176 )
11861177 . await ?
1187- . to_semantic_tokens ( module. line_index . clone ( ) , token) ?,
1178+ . to_semantic_tokens ( & module. line_index , token) ?,
11881179 // TODO(nayeemrmn): Fix when tsgo supports semantic tokens.
11891180 Self :: Go ( _) => Default :: default ( ) ,
11901181 } ;
@@ -1325,12 +1316,10 @@ impl TsServer {
13251316 ) -> Result < Option < Vec < lsp:: InlayHint > > , AnyError > {
13261317 match self {
13271318 Self :: Js ( ts_server) => {
1328- let text_span =
1329- tsc:: TextSpan :: from_range ( range, module. line_index . clone ( ) ) . map_err (
1330- |err| {
1331- anyhow ! ( "Failed to convert range to tsc text span: {:#}" , err)
1332- } ,
1333- ) ?;
1319+ let text_span = tsc:: TextSpan :: from_range ( range, & module. line_index )
1320+ . map_err ( |err| {
1321+ anyhow ! ( "Failed to convert range to tsc text span: {:#}" , err)
1322+ } ) ?;
13341323 let mut inlay_hints = ts_server
13351324 . provide_inlay_hints ( snapshot. clone ( ) , module, text_span, token)
13361325 . await ;
0 commit comments