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

dynamic language formatting using @content #10

Closed
thenbe opened this issue Aug 5, 2023 · 2 comments · Fixed by #11
Closed

dynamic language formatting using @content #10

thenbe opened this issue Aug 5, 2023 · 2 comments · Fixed by #11

Comments

@thenbe
Copy link

thenbe commented Aug 5, 2023

Hi. After experimenting with it for a bit, I managed to get syntax highlighting to work based on the language name specified in the comment. However, formatting only works when I hardcode the language name in the injections.scm file. Is there to get formatting to work without doing that?

To illustrate, here are two methods the are close to what I'm trying to achieve, but not quiet there:

Examples

Queries were placed in: nvim/queries/ecma/injections.scm.
Testing was done against this typescript file:

const myhtml = /* html */ ` <html> <body></body> </html> `;
const mysql = /* sql */ `SELECT * FROM foo`;

const foo = `bar`;

Method 1. Hardcoding the language name: @html

  • Syntax highlighting: YES (but hardcoded to html)
  • Formatting: YES
  • However this will match every template string in the file (i.e. any string surrounded with angled brackets eg. const foo = `bar`)
; extends

; /* html */ `<html>`
(variable_declarator
	(template_string) @html (#offset! @html 0 1 0 -1)
	)

Method 2. Dynamic language name based on the preceding comment

  • Syntax highlighting: YES (dynamic)
  • Formatting: NO
; extends

; /* html */ `<html>`
; /* sql */ `SELECT * FROM foo`
(variable_declarator
  (comment) @language (#offset! @language 0 3 0 -3)
  (template_string) @content (#offset! @content 0 1 0 -1)
  )


Is there a way to get formatting to work in method 2? I couldn't figure out why syntax highlighting was working OK in both methods, but formatting would only work in method 1.

@LostNeophyte
Copy link
Owner

thanks for the detailed issue, is the problem fixed in the refactor/simplify-getting-injections branch?

@thenbe
Copy link
Author

thenbe commented Aug 5, 2023

It is! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants