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,
},
return {
{
"neovim/nvim-lspconfig",
opts = function()
require("lspconfig").mojo.setup({ cmd = { "mojo-lsp-server", "-I", "." } })
-- Format on save using LSP
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.mojo",
callback = function()
-- Check for an active 'mojo' LSP client that supports formatting
local clients = vim.lsp.get_clients({ bufnr = 0, name = "mojo" })
if #clients > 0 and clients[1].supports_method("textDocument/formatting") then
-- Trigger formatting synchronously before the buffer is written
vim.lsp.buf.format({ async = false })
end
end,
})
end,
},
}
The LSP seems to work for tooltips because if I hit ‘K’ on a function I get a tooltip with the documentation for the fuction.
But goto definition and format on save don’t work.
Here is the LspLog for the save and goto definition calls: