From 0da81205d57e947e82aa02206f8ba6822c624ebc Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 2 Aug 2024 15:52:48 +0200 Subject: feat(unstable/fmt): move yaml formatting behind unstable flag (#24848) This moves YAML formatting behind an unstable flag for Deno 1.46. This will make it opt-in to start and then we can remove the flag to make it on by default in version of Deno after that. This can be specified by doing `deno fmt --unstable-yaml` or by specifying the following in a deno.json file: ```json { "unstable": ["fmt-yaml"] } ``` --- cli/lsp/language_server.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cli/lsp/language_server.rs') diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 62cbd58dd..314c9ec14 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -92,6 +92,7 @@ use crate::args::CaData; use crate::args::CacheSetting; use crate::args::CliOptions; use crate::args::Flags; +use crate::args::UnstableFmtOptions; use crate::factory::CliFactory; use crate::file_fetcher::FileFetcher; use crate::graph_util; @@ -1361,6 +1362,16 @@ impl Inner { .clone(); fmt_options.use_tabs = Some(!params.options.insert_spaces); fmt_options.indent_width = Some(params.options.tab_size as u8); + let maybe_workspace = self + .config + .tree + .data_for_specifier(&specifier) + .map(|d| &d.member_dir.workspace); + let unstable_options = UnstableFmtOptions { + yaml: maybe_workspace + .map(|w| w.has_unstable("fmt-yaml")) + .unwrap_or(false), + }; let document = document.clone(); move || { let format_result = match document.maybe_parsed_source() { @@ -1378,7 +1389,12 @@ impl Inner { .map(|ext| file_path.with_extension(ext)) .unwrap_or(file_path); // it's not a js/ts file, so attempt to format its contents - format_file(&file_path, document.content(), &fmt_options) + format_file( + &file_path, + document.content(), + &fmt_options, + &unstable_options, + ) } }; match format_result { -- cgit v1.2.3