Neovim support for the MoonBit language.
- Tree-sitter support
- Highlights
- Folds
- Indents (#9)
- Build system support
- Compiler plugin
-
Diagnostics through nvim-lintRemoved b/c LSP
- JSON Schema
- Language server
- Neotest support (#10)
First you need to have the MoonBit toolchain installed. You can follow the instruction on the Download Page of the MoonBit language.
{
'moonbit-community/moonbit.nvim',
ft = { 'moonbit' },
opts = {
mooncakes = {
virtual_text = true, -- virtual text showing suggestions
use_local = true, -- recommended, use index under ~/.moon
},
-- optionally disable the treesitter integration
treesitter = {
enabled = true,
-- Set false to disable automatic installation and updating of parsers.
auto_install = true
},
-- configure the language server integration
-- set `lsp = false` to disable the language server integration
lsp = {
-- set to false to use the legacy language server
native = true,
-- provide an `on_attach` function to run when the language server starts
on_attach = function(client, bufnr) end,
-- provide client capabilities to pass to the language server
capabilities = vim.lsp.protocol.make_client_capabilities(),
},
-- configure jsonls schema integration (enabled by default)
-- set `jsonls = false` to disable
jsonls = {
-- optional extra jsonls settings to merge
settings = {},
},
},
}moonbit.nvim provides a neotest adapter. Below is an minimal example config using lazy.nvim:
{
"nvim-neotest/neotest",
dependencies = {
"moonbit-community/moonbit.nvim",
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-moonbit"),
},
})
end,
}According to the lazy.nvim docs, setting the config property in an override spec might accidentally overwrite that of an existing parent spec. On the other hand, the opts property is guaranteed to be merged with that of the parent spec. Therefore, we recommend the following settings:
{
"nvim-neotest/neotest",
dependencies = {
"moonbit-community/moonbit.nvim",
},
opts = function(_, opts)
if not opts.adapters then opts.adapters = {} end
table.insert(opts.adapters, require("neotest-moonbit"))
end,
}The neotest adapter recognizes package config from moon.pkg and moon.pkg.json (prefers moon.pkg when both are present).
moonbit.nvim provides package name completion in moon.mod.json and moon.pkg.
Version hints and version upgrades are available in moon.mod.json.
blink.cmp setup:
{
"saghen/blink.cmp",
opts = {
sources = {
-- add mooncake to your completion providers
default = { "mooncake", "lsp", "path", "snippets", "buffer" },
providers = {
mooncake = {
name = 'Mooncakes',
module = 'moonbit.mooncakes.completion.blink',
opts = { max_items = 100 },
},
},
},
},
}nvim-cmp setup:
{
"hrsh7th/nvim-cmp",
dependencies = {
"moonbit-community/moonbit.nvim",
},
opts = function(_, opts)
opts.sources = require("cmp").config.sources(opts.sources or {}, {
{ name = "mooncake", option = { max_items = 100 } },
})
end,
}A command :MooncakeActions is also available to open package docs in moon.pkg, and to update dependency versions in moon.mod.json.
moonbit.nvim registers local JSON schemas for moon.mod.json and
moon.pkg.json with jsonls automatically. (moon.pkg is a DSL file, not JSON.) To disable:
{
'moonbit-community/moonbit.nvim',
opts = {
jsonls = false,
},
}