AckslD / nvim-neoclip.lua

Clipboard manager neovim plugin with telescope integration
944 stars 20 forks source link

Error inserting into sqlite DB #32

Closed timtyrrell closed 2 years ago

timtyrrell commented 2 years ago

I have searched this and the tami5/sqlite.lua repo for issues and didn't see anything. When I close neovim or run lua require('neoclip.storage').on_exit() in the command line I get the error below:

Couldn't insert in database since: ...rell/.config/nvim/plugged/sqlite.lua/lua/sqlite/stmt.lua:35: sqlite.lua: sql statement parse, , stmt: insert into neoclip () values(), err: (near ")": syntax error)

I did delete the databases folder and saw it recreated but I get the same error above.

Any idea what I could be doing wrong or have misconfigured?

version: NVIM v0.6.0-dev+624-ga2e5c2f7c but I believe I have always seen the error.

mini.vim

set nocompatible
filetype plugin indent on
syntax on
set hidden

call plug#begin('~/.config/nvim/plugged')

Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'

Plug 'tami5/sqlite.lua'
Plug 'AckslD/nvim-neoclip.lua'

call plug#end()

lua << EOF

require('telescope').setup {}

require("telescope").load_extension("neoclip")
require('neoclip').setup({
  history = 1000,
  enable_persistant_history = true,
  preview = true,
})

EOF
AckslD commented 2 years ago

Hi @timtyrrell, thanks for reporting! I haven't seen this error. Could you check that you have the latest version of both plugins and also let me know what version of sqlite you have (ie the binary, not the plugin).

I haven't upgraded nvim or sqlite in a week or so but will do that later today to see if anything changed lately.

timtyrrell commented 2 years ago

All my vim plugins are the latest, as I update them all daily. Let me know if I could provide anything else, thanks.

❯ sqlite3 --version 3.32.3 2020-06-18 14:16:19 02c344aceaea0d177dd42e62c8541e3cab4a26c757ba33b3a31a43ccc7d4aapl

I wonder if my use of vim-plug is missing something 🀷

rickprice commented 2 years ago

I'm having a problem where things aren't saving as well, although I haven't debugged it yet. I'm wondering if I have sqlite installed. Could this be the issue you are having as well?

I'm on Arch Linux with all my plugins updated as well, I'm also using the same package manager on Neovim.

Frederick

On Sat., Nov. 27, 2021, 20:20 Tim Tyrrell, @.***> wrote:

All my vim plugins are the latest, as I update them all daily. Let me know if I could provide anything else, thanks.

❯ sqlite3 --version 3.32.3 2020-06-18 14:16:19 02c344aceaea0d177dd42e62c8541e3cab4a26c757ba33b3a31a43ccc7d4aapl

I wonder if my use of vim-plug is missing something 🀷

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AckslD/nvim-neoclip.lua/issues/32#issuecomment-980818104, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHXNTSL52A5RTBHJOE6SODUOF7W5ANCNFSM5I3L5ZEA .

AckslD commented 2 years ago

@timtyrrell I'm currently on sqlite3 version 3.36.0, I wonder if that makes a difference. Maybe @tami5 knows something about this?

@rickprice Yes, you need sqlite3 installed so make sure that you can do eg sqlite3 --version in your terminal.

AckslD commented 2 years ago

Btw @timtyrrell does this also happen if you first yank something before closing neovim? I wonder if there is an issue when the current history is empty.

kkharji commented 2 years ago

hmmm I did quick test, but haven't got any errors, though, restarting neovim result in empty history, am I even using persistent?.

  require("telescope").load_extension "neoclip"
  require("neoclip").setup {
    history = 1000,
    enable_persistant_history = true,
    preview = true,
  }

From the given error it seems that maybe neoclip sent nil values to sqlite interface? damn it sqlite.lua doesn't have tracing 😭 .

@AckslD can you confirm if it works on your machine, tested on m1, NVIM v0.6.0-dev+1967-g427bac687

AckslD commented 2 years ago

Thanks for checking @tami5, it does indeed work for me without errors, I'm on v0.6.0-dev+642-g07223fae54.

timtyrrell commented 2 years ago

@AckslD Good call, if I have nothing yanked since opening neovim, that is when I get the error. If I yank, I get no error when running lua require('neoclip.storage').on_exit() or close neovim.

Although, as @tami5 mentioned, with a new session I have no yank history, so if I don't yank and close quickly or run the above command with a new neovim instance, I see the error. πŸ€”

EDIT1: using the last nightly on a Mac: NVIM v0.6.0-dev+642-g07223fae5

EDIT2: I switched my path to use sqlite version 3.36.0, same issue: 3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5

EDIT3: I do see the DB being updated when I exit neovim:

❯ ll ~/.local/share/nvim/databases
.rw-r--r-- 68 KB Sun Nov 28 16:21:05 2021 ξŸ„ neoclip.sqlite3

@AckslD do you have a minimal packer config I could try? In case it is worth ruling the plugin manager out.

timtyrrell commented 2 years ago

Last comment for now: I have been querying the DB and do see data in there but something is deleting it and I don't see the pattern yet. I generally have 2 or more neovim instances running, in case that could be helpful info.

I wonder if this table.remove is getting hit

AckslD commented 2 years ago

@timtyrrell Could you see what :lua print(vim.inspect(require('neoclip.storage').get())) gives before you close the instance?

timtyrrell commented 2 years ago

@AckslD sorry for the delay, on initial load this is returned {}

If I yank and then run it, example:

{ {
    contents = { "  return updated" },
    filetype = "typescript",
    regtype = "l"
  } }
AckslD commented 2 years ago

Thanks @timtyrrell, so it's always empty for you when opening a new session?

timtyrrell commented 2 years ago

@AckslD As far as I can tell, yes. Is there a way to see if the variables are getting set? I can shove in logging code, if needed. Again, I wonder if it is thevim-plug way I am wiring it up.

AckslD commented 2 years ago

Maybe to make sure, would you mind trying with the following packer setup?

-- vim: foldmethod=marker
local execute = vim.api.nvim_command
local fn = vim.fn

local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
  execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
end
execute 'packadd packer.nvim'

return require('packer').startup(function(use)
    use { -- neoclip {{{
        'AckslD/nvim-neoclip.lua',
        requires = {'tami5/sqlite.lua', module = 'sqlite'},
        config = function()
            require('neoclip').setup{
                history = 20,
                enable_persistant_history = true,
            }
        end
    } -- }}}
    use { -- telescope {{{
        'nvim-telescope/telescope.nvim',
        wants = {'popup.nvim', 'plenary.nvim'},
        requires = {
            {'nvim-lua/popup.nvim'},
            {'nvim-lua/plenary.nvim'},
        },
        cmd = 'Telescope',
        module = 'telescope',
        config = function()
            require('telescope').setup({
                defaults = {
                    dynamic_preview_title = true,
                },
            })
        end
    } -- }}}
end)
timtyrrell commented 2 years ago

@AckslD Using basically the same config as you have above (pasted below) when I yanked and then closed nvim and then reopened, the data did persist. So looks like the vim-plug config I am using is the culprit here.

Feel free to close this issue unless you want to figure out how to set this up in vim-plug, I can also try to do it myself. Possibly add to the README that vim-plug is not supported if you don't want to debug it πŸ‘

Thanks so much for digging in.

vim.cmd [[packadd packer.nvim]]
return require('packer').startup(function(use)
    use { -- neoclip {{{
        'AckslD/nvim-neoclip.lua',
        requires = {'tami5/sqlite.lua', module = 'sqlite'},
        config = function()
            require('neoclip').setup{
                history = 20,
                enable_persistant_history = true,
            }
        end
    } -- }}}
    use { -- telescope {{{
        'nvim-telescope/telescope.nvim',
        wants = {'popup.nvim', 'plenary.nvim'},
        requires = {
            {'nvim-lua/popup.nvim'},
            {'nvim-lua/plenary.nvim'},
        },
        cmd = 'Telescope',
        module = 'telescope',
        config = function()
            require('telescope').setup({
                defaults = {
                    dynamic_preview_title = true,
                },
            })
        end
    }
end)
AckslD commented 2 years ago

@timtyrrell no problem and thanks for trying it out! I probably won't debug at this point at least what goes wrong with vim-plug since I don't know much how to use it but I will for sure add a note in the README.

If you figure out why it doesn't work it would be great to know it :)

AckslD commented 2 years ago

I can't really understand what might be causing this, some thoughts:

  1. @timtyrrell do you know if vim-plug does any kind of lazy loading?
  2. @timtyrrell do you use sqlite in any other part of your setup? And if so, is that working as expected?
  3. @tami5 have you had any other issues with sqlite and vim-plug?
timtyrrell commented 2 years ago

@AckslD

  1. vim-plug only lazy loads if specified in the Plug command, which I am not doing
  2. I am not using sqlite elsewhere, but I can rig in https://github.com/nvim-telescope/telescope-frecency.nvim if we find it helpful

I did a little more testing and was able to discover something. If I comment out the require("telescope").load_extension("neoclip") line, then the data persists when opening and closing, although, obviously I can't use the telescope picker. I used the lua print(vim.inspect(require('neoclip.storage').get())) call to verify this.

If I run lua require('telescope').extensions.neoclip.default() during the session the picker pops up and does not clear out the data when closed and reopened. So apparently the load_extension line is having a bad side effect?

set nocompatible
filetype plugin indent on
syntax on
set hidden

call plug#begin('~/.config/nvim/plugged')

Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'

Plug 'tami5/sqlite.lua'
Plug 'AckslD/nvim-neoclip.lua'

call plug#end()

lua << EOF

require('telescope').setup {
  defaults = {
    dynamic_preview_title = true,
  }
}

--require("telescope").load_extension("neoclip")
require('neoclip').setup({
  enable_persistant_history = true,
  history = 20,
})

EOF
AckslD commented 2 years ago

Good find @timtyrrell! Does it make a difference if you load the extension after calling the setup for neoclip? If not, does it make a difference if you call it after the first yank?

timtyrrell commented 2 years ago

So the reality is, I would just map <cmd>lua require('telescope').extensions.neoclip.default() to a key. I don't need to call :Telescope neoclip and wouldn't.

AckslD commented 2 years ago

@timtyrrell I added a note about this and README so closing this now. Let me know if you have other issues :)

ranebrown commented 2 years ago

@AckslD I was seeing a similar issue where the persistent history wasn't being saved but using packer. There does seem to be a ordering dependency with telescope (neoclip needs to be loaded/setup prior to telescope). I fixed by using packer's after.

    use({
        "nvim-telescope/telescope.nvim",
        requires = { { "nvim-lua/plenary.nvim" } },
        config = [[require("config.telescope")]],
        after = "nvim-neoclip.lua",
    })
AckslD commented 2 years ago

Thanks for reporting this @ranebrown! Although I'm not sure why this would be the case. But I probably never noticed cause I have neoclip load directly but I lazy load telescope so for me that's always after.

mystilleef commented 1 year ago

@ranebrown Thank you. after fixed the persistent issue for me.