Sorixelle / astro-ts-mode

Emacs major mode for Astro templates
GNU General Public License v3.0
13 stars 1 forks source link

CSS syntax highlighting applied across whole file if no `<style>` tag is present #1

Closed Sorixelle closed 1 year ago

Sorixelle commented 1 year ago

Currently, if there's no <style> tags in the file, astro-mode attempts to syntax highlight everything outside the frontmatter as if it were CSS.

I've done some digging and I think this is an Emacs bug (unless I'm misunderstanding how I'm supposed to use treesit-range-settings). Will need to come up with a workaround.

Technical explanation When there's no style_element nodes in the document, treesit-parser-included-ranges returns nil for the CSS range, which makes sense. However, treesit-parser-root-node doesn't seem to return the correct node in this case. I'd expect that it would just return nil, since if there's a nil range (ie. no CSS content in the document), there shouldn't be a root node, but it instead returns a stylesheet node spanning the full range of the document, which doesn't seem correct. Because treesit's font locking applies to the whole root node, it ends up applying CSS highlighting to the whole document.