Just for reference setting up the Mojo Language Server in LazyVim is as trivial as creating a file in the lua/plugins folder, for example mojo,lua, with the following content
-- Load the LSP.
require("lspconfig").mojo.setup({})
It turns out you can also pass cli arguments. In the mini projects I’ve used so far the LSP was not doing well in tests but passing the current working directory as an include dir solved the problem.
With LazyVim I have a mojo.lua file in the nvim/lua/plugins/ directory of my configuration. I’m using this snippet to set up the LSP to do formatting:
{
"neovim/nvim-lspconfig",
opts = function()
-- Format on save using LSP
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.mojo",
callback = function()
local clients = vim.lsp.get_clients({ bufnr = 0, name = "mojo" })
if #clients > 0 and clients[1].supports_method("textDocument/formatting") then
vim.lsp.buf.format({ async = false })
end
end,
})
end,
},