From 9c6c63a2be30252a6207f4aebb5e0f76f746b4c8 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 28 Apr 2023 03:21:34 -0600 Subject: inject language based on file extension & shebang (#3970) * inject language based on file extension Nodes can now be captured with "injection.filename". If this capture contains a valid file extension known to Helix, then the content will be highlighted as that language. * inject language by shebang Nodes can now be captured with "injection.shebang". If this capture contains a valid shebang line known to Helix, then the content will be highlighted as the language the shebang calls for. * add documentation for language injection * nix: fix highlights The `@` is now highlighted properly on either side of the function arg. Also, extending the phases with `buildPhase = prev.buildPhase + ''''` is now highlighted properly. Fix highlighting of `''$` style escapes (requires tree-sitter-nix bump) Fix `inherit` highlighting. * simplify injection_for_match Split out injection pair logic into its own method to make the overall flow easier to follow. Also transform the top-level function into a method on a HighlightConfiguration. * markdown: add shebang injection query--- helix-term/src/ui/markdown.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 87136992..fea3de78 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag}; use helix_core::{ - syntax::{self, HighlightEvent, Syntax}, + syntax::{self, HighlightEvent, InjectionLanguageMarker, Syntax}, Rope, }; use helix_view::{ @@ -47,7 +47,9 @@ pub fn highlighted_code_block<'a>( let rope = Rope::from(text.as_ref()); let syntax = config_loader - .language_configuration_for_injection_string(language) + .language_configuration_for_injection_string(&InjectionLanguageMarker::Name( + language.into(), + )) .and_then(|config| config.highlight_config(theme.scopes())) .map(|config| Syntax::new(&rope, config, Arc::clone(&config_loader))); -- cgit v1.2.3-70-g09d2