kndndrj / nvim-dbee

Interactive database client for neovim
GNU General Public License v3.0
758 stars 51 forks source link

CSV yanks only part of the data #52

Closed oleksandr-oksenenko closed 9 months ago

oleksandr-oksenenko commented 10 months ago

When yanking a reasonable amount of results (i had 200+) using a CSV formatter only parts of the data appear in the register.

I assume it happens because Go CSV writer uses a buffered writer, which flushes buffered data whenever it reaches a certain threshold (4096 bytes i think), which in turn triggers setreg call on each flush.

I managed to workaround it with a local copy of a plugin using a bytes.Buffer instead of a register as a io.Writer and writing resulting bytes to the register:

func (yo *YankRegisterOutput) Write(result models.Result) error {
    writer := new(bytes.Buffer)

    err := yo.formatter.Format(result, writer)
    if err != nil {
        return err
    }

    reg := newRegister(yo.vim)
    _, err = reg.Write(writer.Bytes())

    return err
}

I'm nowhere near a proficient level in Go though, so maybe there's a better solution to this :)

P.S.: Really loving this plugin! Let me know if I can help with anything.

kndndrj commented 9 months ago

Hi @oleksandr-oksenenko thanks for the observation and a possible fix.

The I'll look into it. I guess something like this might also be the case in other yanked formats

oleksandr-oksenenko commented 9 months ago

I guess something like this might also be the case in other yanked formats

From my observations it's not, but would be great to double-check anyway. Thanks!