Bojan Wilytsch

Setting up Astro inside NeoVim

  • neovim
  • IDE
  • astro
  • typescript
  • dotfiles

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.

sh

npm install -g @astrojs/language-server 

plugins/lspconfig.lua

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.

sh

: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

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!


Prev Numbers with Equal Width

Next Tailwind Utility: CLSX meets Tailwind-merge