Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom preprocessors for 'vue' injections #5268

Merged

Conversation

farwyler
Copy link
Contributor

Changes the injections for Vue script and style tags to allow for custom preprocessors. Before they were hardcoded to plain javascript and css.

Vue tooling can specify a preprocessor via the lang attribute.
This only adds injections for languages that helix already supports.

e.g.

<script lang="typescript">

or very commonly used

<style lang="scss">

@kirawi kirawi added S-waiting-on-review Status: Awaiting review from a maintainer. A-language-support Area: Support for programming/text languages labels Dec 24, 2022
Comment on lines 11 to 30
; <script>
((script_element
(raw_text) @injection.content)
(#set! injection.language "javascript"))
(start_tag) @_no_lang
(raw_text) @injection.content)
(#not-match? @_no_lang "lang=")
(#set! injection.language "javascript"))

; <script lang="js|javascript">
((script_element
(start_tag (attribute (quoted_attribute_value (attribute_value) @_lang)))
(raw_text) @injection.content)
(#match? @_lang "^(js|javascript)$")
(#set! injection.language "javascript"))

; <script lang="ts|typescript">
((script_element
(start_tag (attribute (quoted_attribute_value (attribute_value) @_lang)))
(raw_text) @injection.content)
(#match? @_lang "^(ts|typescript)$")
(#set! injection.language "typescript"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be a little cleaner by matching on the attribute_name:

((script_element
   (start_tag
     (attribute
       (attribute_name) @_attr_name
       (quoted_attribute_value (attribute_value) @injection.language)))
   (raw_text) @injection.content)
 (#eq? @_attr_name "lang"))

((script_element (raw_text) @injection.content)
 (#set! injection.language "javascript"))

and similar for the style tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-mikedavis thanks! that is much better. i totally forgot about injection-regex.

i am not sure if you intended this...

((script_element (raw_text) @injection.content)
 (#set! injection.language "javascript"))

to act as a fallback for the no-lang case. that doesn't seem to work. it just overwrites the language to js because it will match any form of script tag.

i left in the no-lang query but updated the script/style matches with the lang attribute.

@the-mikedavis the-mikedavis changed the title Allows custom preprocessors for 'vue' injections Allow custom preprocessors for 'vue' injections Dec 27, 2022
@the-mikedavis the-mikedavis merged commit 1f4d277 into helix-editor:master Dec 27, 2022
hadronized pushed a commit to hadronized/helix that referenced this pull request Jan 4, 2023
freqmod pushed a commit to freqmod/helix that referenced this pull request Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants