diff --git a/crates/cli_bin/tests/apply.rs b/crates/cli_bin/tests/apply.rs index 3bdc6490e..4bb678fd3 100644 --- a/crates/cli_bin/tests/apply.rs +++ b/crates/cli_bin/tests/apply.rs @@ -871,6 +871,7 @@ fn basic_js_in_vue_apply() -> Result<()> { let output = apply_cmd.output()?; // Assert that the command executed successfully + println!("OUTPUT: {:#?}", output); assert!( output.status.success(), "Command didn't finish successfully: {}", diff --git a/crates/core/src/pattern/code_snippet.rs b/crates/core/src/pattern/code_snippet.rs index 40dedbf56..bd1f54d33 100644 --- a/crates/core/src/pattern/code_snippet.rs +++ b/crates/core/src/pattern/code_snippet.rs @@ -348,7 +348,7 @@ fn language_specific_snippet( .child_by_field_name("language") .ok_or_else(|| anyhow!("missing language of languageSpecificSnippet"))?; let lang_name = lang_node.utf8_text(src.as_bytes())?.trim().to_string(); - let _snippet_lang = TargetLanguage::from_string(&lang_name, &[]) + let _snippet_lang = TargetLanguage::from_string(&lang_name, None) .ok_or_else(|| anyhow!("invalid language: {}", lang_name))?; let snippet_node = node .child_by_field_name("snippet") diff --git a/crates/language/src/target_language.rs b/crates/language/src/target_language.rs index ee7ccacaa..11ef37d7c 100644 --- a/crates/language/src/target_language.rs +++ b/crates/language/src/target_language.rs @@ -24,7 +24,6 @@ use crate::{ }; use anyhow::Result; use enum_dispatch::enum_dispatch; -use itertools::Itertools; use std::borrow::Cow; use std::fmt; use std::hash::Hash; @@ -159,14 +158,10 @@ impl PatternLanguage { .utf8_text(src.as_bytes()) .ok()?; let lang = lang.trim(); - let mut cursor = langdecl.walk(); - let flavors = langdecl - .children_by_field_name("flavor", &mut cursor) - .filter(|f| f.is_named()) - .map(|f| f.utf8_text(src.as_bytes()).ok()) - .collect::>>>()?; - let flavors = flavors.iter().map(|s| s.as_ref()).collect_vec(); - Self::from_string(lang, &flavors) + let flavor = langdecl + .child_by_field_name("flavor") + .and_then(|f| f.utf8_text(src.as_bytes()).ok()); + Self::from_string(lang, flavor.as_deref()) } #[cfg(not(feature = "builtin-parser"))] @@ -188,12 +183,12 @@ impl PatternLanguage { Self::get_language_with_parser(&mut parser, src) } - pub fn from_string(name: &str, flavor: &[&str]) -> Option { + pub fn from_string(name: &str, flavor: Option<&str>) -> Option { match name { "js" => match flavor { - ["jsx"] => Some(Self::Tsx), - ["typescript"] => Some(Self::TypeScript), - ["js_do_not_use"] => Some(Self::JavaScript), + Some("jsx") => Some(Self::Tsx), + Some("typescript") => Some(Self::TypeScript), + Some("js_do_not_use") => Some(Self::JavaScript), _ => Some(Self::Tsx), }, "html" => Some(Self::Html), @@ -202,8 +197,8 @@ impl PatternLanguage { "java" => Some(Self::Java), "csharp" => Some(Self::CSharp), "markdown" => match flavor { - ["block"] => Some(Self::MarkdownBlock), - ["inline"] => Some(Self::MarkdownInline), + Some("block") => Some(Self::MarkdownBlock), + Some("inline") => Some(Self::MarkdownInline), _ => Some(Self::MarkdownInline), }, "python" => Some(Self::Python), @@ -580,7 +575,7 @@ impl TargetLanguage { PatternLanguage::get_language(src).map(|l| l.try_into().ok())? } - pub fn from_string(name: &str, flavor: &[&str]) -> Option { + pub fn from_string(name: &str, flavor: Option<&str>) -> Option { PatternLanguage::from_string(name, flavor).map(|l| l.try_into().ok())? } diff --git a/crates/lsp/src/server.rs b/crates/lsp/src/server.rs index 05b599665..ed39cf8f0 100644 --- a/crates/lsp/src/server.rs +++ b/crates/lsp/src/server.rs @@ -77,7 +77,7 @@ impl GritServer { })?; let range = convert_lsp_range_to_grit_range(&range, &document.text); let grit_files = get_grit_files_from_uri(document.uri.as_str(), true).await; - let language = PatternLanguage::from_string(language.as_str(), &[]).unwrap_or_default(); + let language = PatternLanguage::from_string(language.as_str(), None).unwrap_or_default(); apply_pattern_body( &document,