Rail's Neovim setup

I use AstroNvim as my neovim distro.

The up to date config can be found in my dotfiles repo.

The config uses AstroNvim abstraction, but it can be translated into regular neovim config by assigning the variables and functions to their neovim counterparts.

Some snippet are described below.

Use GOPACKAGESDRIVER to speedup gopls.

The following LSP config makes gopls use GOPACKAGESDRIVER to use Bazel (rules_go) to expose package data.

local lsp = { settings = { gopls = { env = { -- TODO: make GOPACKAGESDRIVER project-specific GOPACKAGESDRIVER = "./build/bazelutil/gopackagesdriver.sh", }, directoryFilters = { "-_bazel", "-inflight_trace_dump", }, }, }, }

Use crlfmt to format Go files.

Make sure to install crlfmt to make the following section work. This plugin creates :Format and :FormatSave commands, which use crlfmt to format the Go buffers. Note that gopls also runs gofumpt.

-- Lazy plugin snippet { "mhartington/formatter.nvim", cmd = { "FormatWrite", "Format" }, opts = { filetype = { go = { -- Defines `crlfmt` as a formatter for Go files. -- It will be run as a part of :Format or FormatSave function() return { exe = "crlfmt", stdin = true, } end, }, }, }, }

 

This function creates an auto command to run when files are saved. The function is called from polish() (AstroNvim’s function called on load).

-- Run crlfmt on save local crlfmt_save = function() vim.api.nvim_create_augroup("__formatter__", { clear = true }) vim.api.nvim_create_autocmd("BufWritePost", { pattern = "*.go", group = "__formatter__", command = ":FormatWrite", }) end

Copyright (C) Cockroach Labs.
Attention: This documentation is provided on an "as is" basis, without warranties or conditions of any kind, either express or implied, including, without limitation, any warranties or conditions of title, non-infringement, merchantability, or fitness for a particular purpose.