ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
1.91k stars 119 forks source link

golines not working on save #400

Closed lightbluepoppy closed 4 months ago

lightbluepoppy commented 7 months ago

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?

ray-x commented 7 months ago

you may need to config goimport='golines'

lightbluepoppy commented 4 months ago

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

dimitarvp commented 3 months ago

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.)