tree-sitter-templ icon indicating copy to clipboard operation
tree-sitter-templ copied to clipboard

bug/feat?: script_element_text range

Open JonnyLoughlin opened this issue 11 months ago • 1 comments

satty-20240308-09:29:16 HTML raw_text vs Templ script_element_text AST

It seems the scanner for SCRIPT_ELEMENT_TEXT doesn't include the leading whitespace on the first element's line. I'm trying to use conform.nvim's injected language formatting, and this is seemingly what's causing issues for me. The first line doesn't get indented properly.

I can work around this by wrapping the text with brackets like so:

<script>{
  console.log("Test");
  console.log("Test");
  console.log("Test");
  console.log("Test");
}</script>

Not sure if a fix for this is entirely necessary, but I figured I'd ask about it. The grammer.js file is making sense to me, it's just been a while since I've written c, so figuring out exactly what would need to change in the scanner is tough.

JonnyLoughlin avatar Mar 08 '24 15:03 JonnyLoughlin

Hi.

sorry for not responding earlier, personal stuff has been getting in the way lately.

I'll try to look into this sometime this or next week.

vrischmann avatar Mar 19 '24 16:03 vrischmann

Hi. Super late but I took a quick look.

The scanner removes leading whitespaces here. If I comment ou this code it looks like the node script_element_text does contain the whitespaces, so this could fix your issue, however doing this breaks a lot of tests so it's not that simple.

I don't know or use conform.nvim so I'm not going to investigate further, sorry. I'm not against modifying the behaviour regarding whitespaces but someone else will have to submit a PR for this.

vrischmann avatar Oct 13 '24 12:10 vrischmann