Setting up Neovim for Gno development
Tags: neovim, web3, blockchain
Published: 2023-09-05 22:09:54

![Gno.land Logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxk0xu5zp59l1pqb4qha.png)

> 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](https://medium.com/r/?url=https%3A%2F%2Fgno.land%2Fgnolang)

---

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

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohize7768njzb00hd3ou.png"
       alt="Neovim configured for Gno">
  <figcaption>The final result</figcaption>
</figure>

For the purposes of this post, I'm going to be using the [AstroNvim](https://astronvim.com/) configuration but this isn't strictly required: as long as you have [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig) and [`nvim-treesitter`](https://github.com/nvim-treesitter/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`](https://github.com/nvim-treesitter/nvim-treesitter#modules):

```lua
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "go" }
```

## 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:

```lua
vim.cmd 'autocmd BufRead,BufNewFile *gno set filetype=gno'
vim.treesitter.language.register('go', 'gno')
```
The first line creates an autocommand to assign the `gno` filetype to all `*.gno` files. The second [registers](https://github.com/nvim-treesitter/nvim-treesitter#adding-parsers) the `gno` filetype with the Go parser.

## Step 3: Configure `gnols`

Download a binary from the [`gnols` releases page](https://github.com/jdkato/gnols/releases) and save it somewhere.

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

```lua
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,
    },
  },
}
```

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

![Neovim running gnols](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phkmkupqvefoepihn416.png)

## 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')`](https://github.com/neovim/nvim-lspconfig#suggested-configuration)) for the Gno standard library; and
- the ability to auto-format your Gno files (set to on-file-save).