neovimIDEastrotypescriptdotfiles

Setting up Astro inside NeoVim

January 27, 2024|1 min read


LSP

I am using lazy in combination with lspconfig and mason, which makes it very easy for me to setup the @astrojs/language-server.

You can also install it manually by running this command anywhere on the command line.

npm install -g @astrojs/language-server 
plugins/lspconfig.lua
local lspconfig = require('lspconfig')
-- ...
lspconfig.astro.setup({})

Treesitter

In my dotfiles I listed astro under my ensured_installs, but you can also install it (when treesitter is installed) by running this command inside NeoVim.

:TSInstall Astro

At the time of writing treesitter & LSP will have issues picking up *.astro and *.mdx files correctly.

A quick workaround for me was to add the following lines to my init.lua.

init.lua
vim.api.nvim_exec(
    [[
        autocmd BufNewFile,BufRead *.mdx set filetype=markdown.mdx
    ]],
    false
),
 
vim.api.nvim_exec(
    [[
        autocmd BufNewFile,BufRead *.astro set filetype=astro
    ]],
    false
),

This covered most of the basics for me. In case you are interested in a more thorough setup including Devicons by Joshua, who wrote an in-depth article about it on their blog.

Thanks for reading!