nvimdev / guard.nvim

async fast minimalist plugin make format easy in neovim
MIT License
448 stars 24 forks source link

Range-formatting deletes lines #145

Closed kwagi closed 4 months ago

kwagi commented 7 months ago

Any feature or api that select lines want to format, and activate with custom keymap.

kwagi commented 7 months ago

Oh i just found it on "do_fmt()" in format.lua

kwagi commented 7 months ago

I don't know why but it deletes whole lines out of range.

kwagi commented 7 months ago
local nameis1        = "something"
local nameis314      = "aaaa"
local nameis44444    = "bbbbb"
local nameis15151515 = "ccccccc"

When i selected line 2 and 3 for formatting, the result is

local nameis314 = 'aaaa'
local nameis44444 = 'bbbbb'

Line 1 and 4 is gone.

kwagi commented 7 months ago

I guess it occurred with external formatter(python-black ,lua-stylua, go-gofumpt, etc..) not a "LSP-built-in".

xiaoshihou514 commented 7 months ago

Huh, that shouldn't happen, I will look into this.

xsh005 commented 7 months ago

Ah, commit f4438af broke range formatting @glepnir https://github.com/nvimdev/guard.nvim/blob/4ffdefe0f181ea7e449f60fe94ccc967220181c5/lua/guard/format.lua#L51

Sologala commented 7 months ago

Ah, commit f4438af broke range formatting @glepnir

https://github.com/nvimdev/guard.nvim/blob/4ffdefe0f181ea7e449f60fe94ccc967220181c5/lua/guard/format.lua#L51

@xsh005 Do you know how to fix it ?

xsh005 commented 7 months ago

@Sologala I think you have to pass in the line range again and update accordingly, you could check the previous commits for reference, shouldn't be too hard of a pr :)

xiaoshihou514 commented 4 months ago

149