diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-05-29 21:21:11 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-29 21:21:11 +1000 |
commit | bbefceddb97c2eb7d8cd191dc15f3dc23ed5f6de (patch) | |
tree | 1daefc539d0c5f72346e403f29dff9f07517ec6c /cli/lsp/language_server.rs | |
parent | 5f92f35beed4e2670ef684e8c0561f4d64d19c92 (diff) |
fix(#10765): lsp import fixes include extensions (#10778)
Fixes #10765
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index d86ccefd5..ebcb6b9e3 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -29,6 +29,7 @@ use std::sync::Arc; use tokio::fs; use super::analysis; +use super::analysis::fix_ts_import_changes; use super::analysis::ts_changes_to_edit; use super::analysis::CodeActionCollection; use super::analysis::CodeActionData; @@ -964,7 +965,7 @@ impl Inner { }; for action in actions { code_actions - .add_ts_fix_action(&action, diagnostic, self) + .add_ts_fix_action(&specifier, &action, diagnostic, self) .await .map_err(|err| { error!("Unable to convert fix: {}", err); @@ -1009,7 +1010,7 @@ impl Inner { LspError::invalid_params("The CodeAction's data is invalid.") })?; let req = tsc::RequestMethod::GetCombinedCodeFix(( - code_action_data.specifier, + code_action_data.specifier.clone(), json!(code_action_data.fix_id.clone()), )); let combined_code_actions: tsc::CombinedCodeActions = self @@ -1024,14 +1025,25 @@ impl Inner { error!("Deno does not support code actions with commands."); Err(LspError::invalid_request()) } else { + let changes = if code_action_data.fix_id == "fixMissingImport" { + fix_ts_import_changes( + &code_action_data.specifier, + &combined_code_actions.changes, + self, + ) + .map_err(|err| { + error!("Unable to remap changes: {}", err); + LspError::internal_error() + })? + } else { + combined_code_actions.changes.clone() + }; let mut code_action = params.clone(); code_action.edit = - ts_changes_to_edit(&combined_code_actions.changes, self) - .await - .map_err(|err| { - error!("Unable to convert changes to edits: {}", err); - LspError::internal_error() - })?; + ts_changes_to_edit(&changes, self).await.map_err(|err| { + error!("Unable to convert changes to edits: {}", err); + LspError::internal_error() + })?; Ok(code_action) } } else { |