feat: Add injection.parent-layer
property
#20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was originally brought up in helix-editor/helix#13116 (review)
When injecting markdown into the documentation comments of a language, we want the default code block to be the same as the language itself.
So in this Gleam file, with
///
being documentation comments we want the default value of the code block to also have the Gleam language injection, as opposed to usually when there would not be any injection at all if there is no info string:It's possible to do this by introducing a bunch of
markdown
languages that; inherits markdown
scopes, but instead of doing that this PR allows for a more generic way of doing this.It introduces the
injection.parent-layer
property which can be set like this:This will set the injection language to be whatever is the parent layer of this language, if it's injected.
Using the
#any-of? injection.parent-layer
predicate you are also able to only allow this for specific languages:The above will have this injection effect only for the
"gleam"
and"zig"
language. This is necessary as we want to control which languages have this power. Without it, we would see the default injection for code block without info strings in Markdown be the Markdown language itself, which we want to avoid.To test this in Helix, add this query at the start of the file (before the
(info_string (language))
injection) inruntime/queries/markdown/injections.scm
:(fenced_code_block (fenced_code_block_delimiter) (block_continuation) (code_fence_content) @injection.content (fenced_code_block_delimiter) (#set! injection.language injection.parent-layer) (#set! injection.include-unnamed-children) (#any-of? injection.parent-layer "gleam"))
Example file for testing:
Note: Immediately this will be useful for Gleam in helix, and also Zig soon. Rust won't make use of this because it requires a custom language (such as injecting the
rust
language into markdown code block when the(info_string)
isedition2024
)