diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-09-18 20:48:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 20:48:32 +0100 |
commit | 86c04f43e0eda139a262c4f2e106e9b11e8d7da8 (patch) | |
tree | 71e8661fdaf7ac0e677707d76d6c82d2e0d1dade /cli/lsp/tsc.rs | |
parent | f7ba7013045fc0629092ea4e07ce5c768a7ee95f (diff) |
fix(lsp): pass quote preference to tsc (#20547)
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 2c63131b6..81950f2e3 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -234,6 +234,7 @@ impl TsServer { range: Range<u32>, codes: Vec<String>, format_code_settings: FormatCodeSettings, + preferences: UserPreferences, ) -> Vec<CodeFixAction> { let req = RequestMethod::GetCodeFixes(( specifier, @@ -241,6 +242,7 @@ impl TsServer { range.end, codes, format_code_settings, + preferences, )); match self.request(snapshot, req).await { Ok(items) => items, @@ -260,6 +262,7 @@ impl TsServer { snapshot: Arc<StateSnapshot>, specifier: ModuleSpecifier, range: Range<u32>, + preferences: Option<UserPreferences>, only: String, ) -> Result<Vec<ApplicableRefactorInfo>, LspError> { let req = RequestMethod::GetApplicableRefactors(( @@ -268,6 +271,7 @@ impl TsServer { start: range.start, length: range.end - range.start, }, + preferences, only, )); self.request(snapshot, req).await.map_err(|err| { @@ -281,11 +285,13 @@ impl TsServer { snapshot: Arc<StateSnapshot>, code_action_data: &CodeActionData, format_code_settings: FormatCodeSettings, + preferences: UserPreferences, ) -> Result<CombinedCodeActions, LspError> { let req = RequestMethod::GetCombinedCodeFix(( code_action_data.specifier.clone(), json!(code_action_data.fix_id.clone()), format_code_settings, + preferences, )); self.request(snapshot, req).await.map_err(|err| { log::error!("Unable to get combined fix from TypeScript: {}", err); @@ -293,6 +299,7 @@ impl TsServer { }) } + #[allow(clippy::too_many_arguments)] pub async fn get_edits_for_refactor( &self, snapshot: Arc<StateSnapshot>, @@ -301,6 +308,7 @@ impl TsServer { range: Range<u32>, refactor_name: String, action_name: String, + preferences: Option<UserPreferences>, ) -> Result<RefactorEditInfo, LspError> { let req = RequestMethod::GetEditsForRefactor(( specifier, @@ -311,6 +319,7 @@ impl TsServer { }, refactor_name, action_name, + preferences, )); self.request(snapshot, req).await.map_err(|err| { log::error!("Failed to request to tsserver {}", err); @@ -3507,6 +3516,15 @@ pub enum QuotePreference { Single, } +impl From<&FmtOptionsConfig> for QuotePreference { + fn from(config: &FmtOptionsConfig) -> Self { + match config.single_quote { + Some(true) => QuotePreference::Single, + _ => QuotePreference::Double, + } + } +} + #[derive(Debug, Serialize)] #[serde(rename_all = "kebab-case")] #[allow(dead_code)] @@ -3765,7 +3783,9 @@ enum RequestMethod { }, GetAssets, /// Retrieve the possible refactor info for a range of a file. - GetApplicableRefactors((ModuleSpecifier, TextSpan, String)), + GetApplicableRefactors( + (ModuleSpecifier, TextSpan, Option<UserPreferences>, String), + ), /// Retrieve the refactor edit info for a range. GetEditsForRefactor( ( @@ -3774,6 +3794,7 @@ enum RequestMethod { TextSpan, String, String, + Option<UserPreferences>, ), ), /// Retrieve the refactor edit info for a range. @@ -3786,7 +3807,16 @@ enum RequestMethod { ), ), /// Retrieve code fixes for a range of a file with the provided error codes. - GetCodeFixes((ModuleSpecifier, u32, u32, Vec<String>, FormatCodeSettings)), + GetCodeFixes( + ( + ModuleSpecifier, + u32, + u32, + Vec<String>, + FormatCodeSettings, + UserPreferences, + ), + ), /// Get completion information at a given position (IntelliSense). GetCompletions( ( @@ -3799,7 +3829,9 @@ enum RequestMethod { /// Get details about a specific completion entry. GetCompletionDetails(GetCompletionDetailsArgs), /// Retrieve the combined code fixes for a fix id for a module. - GetCombinedCodeFix((ModuleSpecifier, Value, FormatCodeSettings)), + GetCombinedCodeFix( + (ModuleSpecifier, Value, FormatCodeSettings, UserPreferences), + ), /// Get declaration information for a specific position. GetDefinition((ModuleSpecifier, u32)), /// Return diagnostics for given file. @@ -3876,11 +3908,17 @@ impl RequestMethod { "id": id, "method": "getAssets", }), - RequestMethod::GetApplicableRefactors((specifier, span, kind)) => json!({ + RequestMethod::GetApplicableRefactors(( + specifier, + span, + preferences, + kind, + )) => json!({ "id": id, "method": "getApplicableRefactors", "specifier": state.denormalize_specifier(specifier), "range": { "pos": span.start, "end": span.start + span.length }, + "preferences": preferences, "kind": kind, }), RequestMethod::GetEditsForRefactor(( @@ -3889,6 +3927,7 @@ impl RequestMethod { span, refactor_name, action_name, + preferences, )) => json!({ "id": id, "method": "getEditsForRefactor", @@ -3897,6 +3936,7 @@ impl RequestMethod { "range": { "pos": span.start, "end": span.start + span.length}, "refactorName": refactor_name, "actionName": action_name, + "preferences": preferences, }), RequestMethod::GetEditsForFileRename(( old_specifier, @@ -3917,6 +3957,7 @@ impl RequestMethod { end_pos, error_codes, format_code_settings, + preferences, )) => json!({ "id": id, "method": "getCodeFixes", @@ -3925,17 +3966,20 @@ impl RequestMethod { "endPosition": end_pos, "errorCodes": error_codes, "formatCodeSettings": format_code_settings, + "preferences": preferences, }), RequestMethod::GetCombinedCodeFix(( specifier, fix_id, format_code_settings, + preferences, )) => json!({ "id": id, "method": "getCombinedCodeFix", "specifier": state.denormalize_specifier(specifier), "fixId": fix_id, "formatCodeSettings": format_code_settings, + "preferences": preferences, }), RequestMethod::GetCompletionDetails(args) => json!({ "id": id, @@ -4976,6 +5020,7 @@ mod tests { assert!(result.is_ok()); let fmt_options_config = FmtOptionsConfig { semi_colons: Some(false), + single_quote: Some(true), ..Default::default() }; let result = request( @@ -4986,6 +5031,7 @@ mod tests { position, GetCompletionsAtPositionOptions { user_preferences: UserPreferences { + quote_preference: Some((&fmt_options_config).into()), include_completions_for_module_exports: Some(true), include_completions_with_insert_text: Some(true), ..Default::default() @@ -5011,7 +5057,10 @@ mod tests { position, name: entry.name.clone(), source: entry.source.clone(), - preferences: None, + preferences: Some(UserPreferences { + quote_preference: Some((&fmt_options_config).into()), + ..Default::default() + }), format_code_settings: Some((&fmt_options_config).into()), data: entry.data.clone(), }), @@ -5029,7 +5078,7 @@ mod tests { let change = changes.text_changes.first().unwrap(); assert_eq!( change.new_text, - "import { someLongVariable } from \"./b.ts\"\n" + "import { someLongVariable } from './b.ts'\n" ); } |