go.nvim icon indicating copy to clipboard operation
go.nvim copied to clipboard

golines not working on save

Open lightbluepoppy opened this issue 2 years ago • 1 comments

Currently, these lines of code is not enough to run GoFmt on save which runs golines which formats long lines of code. When I run :GoFmt, golines runs and lines are being formatted.


local format_sync_grp = vim.api.nvim_create_augroup("GoImport", {})
vim.api.nvim_create_autocmd("BufWritePre", {
    pattern = "*.go",
    callback = function()
        require('go.format').goimport()
    end,
    group = format_sync_grp,
})

require('go').setup({
    max_line_len = 80, -- max line length in golines format, Target maximum line length for golines
})

How is it possible to run golines properly on save?

lightbluepoppy avatar Nov 20 '23 23:11 lightbluepoppy

you may need to config goimport='golines'

ray-x avatar Nov 21 '23 09:11 ray-x

Now I use gopls, golines and golangci_lint separetely configured on Lazy and Mason.

lightbluepoppy avatar Feb 20 '24 02:02 lightbluepoppy

I was using command = 'GoFmt' and not the callback block and also didn't have the golines configuration. I added both (and removed command = 'GoFmt') and now my Golang code gets auto-formatted on save! Thanks to both of you!

Just to help future readers: it's goimports='golines' now (plural goimports and NOT goimport).

(Also, now as in: 2024-APR-02.)

dimitarvp avatar Apr 02 '24 08:04 dimitarvp