sorixelle / astro-ts-mode Goto Github PK
View Code? Open in Web Editor NEWEmacs major mode for Astro templates
License: GNU General Public License v3.0
Emacs major mode for Astro templates
License: GNU General Public License v3.0
This example shows an indentation error
---
---
<!doctype html>
<html lang="en">
<head>
<BaseHead title={SITE_TITLE} description={SITE_DESCRIPTION} />
</head>
<body>
<Header />
<mainain>
<ol class="posts list">
{
page.data.map((post) => (
<li class="post">
<PostSummary {post} />
</li>
))
}
</ol
<p>Pagination {page.size}/{page.total}</p>
{page.total > 2 ? (
<Pagination
length={page.lastPage}
currentUrl={page.url.current}
currentPage={page.currentPage}
firstUrl={`/${first_path}`}
prevUrl={page.url.prev}
nextUrl={page.url.next}
lastUrl={`/${first_path}/${page.lastPage}`}
/>
) : null}
</main>
<Footer />
</body>
</html>
comment-or-uncomment-region
must generate Javascript comment in the code part.
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.
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.
Thanks for making this. I'd been using the same TS grammar as you, but had kind of hacked together my own astro-ts-mode. This is much nicer than the one I had. I wanted to pass along a tip for configuration, there's some great synergy that can be achieved with the use of treesit-auto.
Here's what my use-package statement looks like with treesit-auto and astro-ts-mode:
(use-package astro-ts-mode
:after (treesit-auto)
:config
(setq astro-ts-auto-recipe
(make-treesit-auto-recipe
:lang 'astro
:ts-mode 'astro-ts-mode
:url "https://github.com/virchau13/tree-sitter-astro"
:revision "master"
:source-dir "src"))
(add-to-list 'treesit-auto-recipe-list astro-ts-auto-recipe))
Feel free to close this, just wanted to pass this along to you. Thanks again!
Hi,
First, I'd like to thank you for making this mode.
I've just started learning Astro, and I am glad someone has already made a mode for it.
I've followed the instructions to set up Astro mode, and everything works fine, except the highlighting is a bit off for some reason.
Please see the screenshot below. And if you can point me in the right direction, I am willing to do some work contributing to this project.
Again, thanks for making this. Save me the misery of using VScode
(use-package astro-ts-mode
:config
(setq astro-ts-mode-indent-offset 4)
:init
(add-hook 'astro-ts-mode-hook (lambda () (setq indent-tabs-mode nil)))
)
When deleting a whole block of code highlighted in another language (eg. <style>
tags, <script>
tags, inline interpolations), astro-mode still tries to highlight the text that took it's place as the language that was deleted, which often isn't necessarily correct. An example:
treesit-update-ranges
calculates the new ranges for a parser that had all it's ranges removed (ie. treesit-query-range
for that parser returns nil
), treesit--merge-ranges
still returns the old range. This behavior is incorrect - since the new range no longer exists, the merged range should also be zero.
I am on emacs version 29.0.92, compiled form source form the emacs git repo. using the emacs-29 branch.
the (treesit-ready-p 'lang)
does not exist.
Had to change it to (treesit-language-available-p 'lang)
for it to work.
On lines: 177, 180, 183 and 218.
so, I don't know if this is a problem with emacs 29.3's treesit or astro-ts-mode, or what, but I'm consisitently getting this error when attempting to enable astro-ts-mode
on any astro file:
redisplay--pre-redisplay-functions: (treesit-query-error "Node type error at" 32 "(frontmatter (raw_text) @cap) (interpolation (raw_text) @cap) (script_element (raw_text) @cap)" "Debug the query with `treesit-query-validate'")
I've ruled out treesit-auto, I've ensured I'm using the same version of the treesitter grammar that I'm using in other editors, where it works fine. Any ideas?
Hi Sorixelle,
Thanks a lot for the package. I have followed your installation instructions without any errors, specifically:
treesit-install-language-grammar
When I open a .astro
file the major mode is not detected (it remains Fundamental
in the mode line) but it is activated if I do M-x astro-ts-mode
(I see the change in the mode line). However, no code is highlighted and tree-sitter throws the error below:
Any help would be really appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.