DEV Community

Joseph Kato
Joseph Kato

Posted on

Setting up Neovim for Gno development

Gno.land Logo

Gnolang (Gno) is an interpretation of the widely-used Golang (Go) programming language for blockchain created by Cosmos co-founder Jae Kwon in 2022 to mark a new era in smart contracting. - About the Gnolang, the Gno Language


In this post, I'm going to walk through setting up a development environment for Gno in Neovim. At the end, we'll have error diagnostics, syntax highlighting, auto-formatting, and basic intellisense (autocomplete + hover information) for the Gno standard library.

Neovim configured for Gno


The final result

For the purposes of this post, I'm going to be using the AstroNvim configuration but this isn't strictly required: as long as you have nvim-lspconfig and nvim-treesitter, you should be able to follow along.

Step 1: Install tree-sitter-go

Navigate to ~/.config/nvim/lua/plugins/treesitter.lua (or equivalent) and make sure that go is listed in ensure_installed:

ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "go" }
Enter fullscreen mode Exit fullscreen mode

Step 2: Assign a syntax with Tree-sitter

Navigate to ~/.config/nvim/lua/plugins/configs/nvim-treesitter.lua (or equivalent) and add these two lines:

vim.cmd 'autocmd BufRead,BufNewFile *gno set filetype=gno'
vim.treesitter.language.register('go', 'gno')
Enter fullscreen mode Exit fullscreen mode

The first line creates an autocommand to assign the gno filetype to all *.gno files. The second registers the gno filetype with the Go parser.

Step 3: Configure gnols

Download a binary from the gnols releases page and save it somewhere.

Navigate to ~/.config/nvim/lua/user/init.lua (or equivalent; wherever you customize nvim-lspconfig) and add the following:

return {
  lsp = {
    formatting = {
      format_on_save = true,
    },
    servers = {
      "gnols",
    },
    config = {
      gnols = function()
        return {
          cmd = { "path/to/your/gnols/binary" };
          filetypes = {"gno"};
          root_dir = require("lspconfig.util").root_pattern('.git', 'gno.mod');
          settings = {
            gno = "path/to/you/gno/binary",
            precompileOnSave = true,
            buildOnSave = false,
            -- the clone location of github.com/gnolang/gno
            root = "path/to/local/clone/gno",
          };
        }
      end,
    },
  },
}
Enter fullscreen mode Exit fullscreen mode

Now, when you open a Gno file, you should see syntax highlighting and status bar indicators that gnols is active:

Neovim running gnols

Step 4: Write Gno code!

After following these steps, you'll now have:

  • Syntax highlighting for .gno files;
  • autocomplete for the Gno standard library;
  • hover information (bound to ('n', 'K')) for the Gno standard library; and
  • the ability to auto-format your Gno files (set to on-file-save).

Top comments (0)