Gno language support for NeoVim.
- Syntax highlighting (uses Go treesitter config).
- Integration with gnopls using LSP.
- Automatic format on save.
- Support for cmp-nvim-lsp (optional).
:GnoDoc
- Show documentation for a package. Optional second argument is package name.:GnoFmt
- Format current file.:GnoRoot
- Print current gnoroot.:GnoTest
- Run unit test.:GnoTest
- Test current unit test file or package.:GnoTest ./package
- Test a specific directory.
- nvim-lspconfig
- plenary.nvim
- Optional:
- Gno Language Server:
- gnoverse/gnopls - Based on gopls.
- golang/gnopls - Unstable, not recommended.
Important
Ensure that gnopls
language server is installed and available in $PATH
.
" Prerequisites
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
" The plugin
Plug 'x1unix/gno.nvim'
{
'x1unix/gno.nvim',
requires = { 'neovim/nvim-lspconfig', 'nvim-lua/plenary.nvim' },
config = function()
require('gno-nvim').setup()
end,
}
Here is a configuration example with defaults:
Note
For LSP config, please check https://neovim.io/doc/user/lsp.html#vim.lsp.config()
require('gno-nvim').setup({
-- Custom GNOROOT path. Can be string or function.
--
-- Passed into Gno commands and LSP server environment variable.
--gnoroot = function()
-- return os.getenv("GNOROOT")
--end,
-- LSP client config
lsp = {
-- Path to gnopls server binary.
cmd = { 'gnopls', 'serve' },
-- Custom environment variables.
cmd_env = {
-- GNOROOT: 'custom env variable',
},
-- By default - integrate with nvim-cmp if installed.
capabilities = require('cmp_nvim_lsp').default_capabilities()
filetypes = { 'gno' },
-- ...
},
})
GNOROOT can be configured dynamically per-project.
Note
GNOROOT for language server is set only once during LSP session startup.
Use :GnoRoot
command to get current GNOROOT
.
local utils = require("gno-nvim.utils")
local gno_fork_path = os.getenv("HOME") .. "/work/gno"
require('gno-nvim').setup({
gnoroot = function ()
local cwd = vim.fn.expand("%:p:h")
if cwd == "" then
cwd = vim.fn.getcwd()
end
-- If inside Gno work repo, use it as a GNOROOT.
if utils.has_prefix(cwd, gno_fork_path) then
return gno_fork_path
end
-- Use defaults
return nil
end,
})