diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-05-29 21:21:11 +1000 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2021-05-31 16:37:36 +0200 |
commit | 925ba8fbbf947c2c95a616b43e3f89e20cd69e93 (patch) | |
tree | e52a6ad5d248b8d492e84fcfcfe5cee8e633d46c /cli/lsp/language_server.rs | |
parent | 475bc35646bc25d796b2638768cd5a79e3a0033e (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 { |