telescope-smart-history.nvim icon indicating copy to clipboard operation
telescope-smart-history.nvim copied to clipboard

sqlite.lua doesn't seem to work with this.

Open fireboy1919 opened this issue 2 years ago • 8 comments

NVIM v0.6.0 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Latest version of all the lua libraries.

E5108: Error executing lua ...m/site/pack/packer/start/sqlite.lua/lua/sqlite/utils.lua:252: loop or previous error loading module 'sqlite.tbl'
stack traceback:
        [C]: in function 'require'
        ...m/site/pack/packer/start/sqlite.lua/lua/sqlite/utils.lua:252: in function '__index'
        ...nvim/site/pack/packer/start/sqlite.lua/lua/sqlite/db.lua:637: in function 'tbl'
        ...history.nvim/lua/telescope/_extensions/smart_history.lua:34: in function 'init'
        ...r/start/telescope.nvim/lua/telescope/actions/history.lua:76: in function 'handler'
        ...ker/start/telescope.nvim/lua/telescope/actions/state.lua:47: in function 'get_current_history'
        ...cker/start/telescope.nvim/lua/telescope/actions/init.lua:184: in function <...cker/start/telescope.nvim/lua/telescope/actions/init.lua:183>
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:23: in function 'key_func'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:236: in function 'execute_keymap'

This is my reduced packer config:

require('packer').startup(function(use)
  -- My plugins here
  use 'wbthomason/packer.nvim'
  use 'nvim-telescope/telescope.nvim'

  use {
    "nvim-telescope/telescope-smart-history.nvim",
    config = function()
      require"telescope".load_extension("smart_history")
    end,
    requires = {"tami5/sqlite.lua"}
  }

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

Telescope setup:

require("telescope").setup {
  defaults = {
    wrap_results = true,
    history = {
      path = '~/.local/share/nvim/databases/telescope_history.sqlite3',
      limit = 100
    }
  }
}

fireboy1919 avatar Mar 10 '22 17:03 fireboy1919

🤔 that's odd, couldn't reproduce. I'm on NVIM v0.7.0-dev

kkharji avatar Mar 10 '22 17:03 kkharji

So...I was able to track it down.

If you manage to in some way install telescope-smart-history and have not yet gotten sqlite.lua working (if, for example, you don't have the sqlite binaries on your machine when you first install it), then telescope-smart-history will create a garbage sqlite file.

And from that point on, it will fail even if you get your machine set up as intended until you delete that garbage file.

fireboy1919 avatar Mar 11 '22 14:03 fireboy1919

Well done @fireboy1919, Interesting bug, any ideas to prevent it?

kkharji avatar Mar 11 '22 17:03 kkharji

BTW, I also produced this error with telescope-frecency

This seems like something that should actually be built into sqlite.lua, but I can think of two defensive approaches that would prevent this bug:

  1. If the initial attempt to create a sqlite instance fails, then the library could aggressively clean up after itself.

This would unfortunately mean specifically keeping track of the case when you are first creating a file rather than entirely treating the database API as handling all file operations itself, but even so, it's not going to affect performance very much so that's probably okay.

  1. sqlite.lua could have some sort of "clobber" option that detects if the database doesn't load and can prompt the user to recreate the database if it fails to load.

Alternatively, this problem probably doesn't need to be actually prevented since it's easy for a user to fix. It just needs to be detected. If sqlite fails to load, there should be a better error message logged somewhere informing the user that sqlite.lua couldn't load the extension.

fireboy1919 avatar Mar 11 '22 18:03 fireboy1919

Hi @fireboy1919, I got the same error, but do not know the path of the garbage file. Could you tell me its path?

thuan1412 avatar Apr 07 '22 06:04 thuan1412

In my case i needed to install libsqlite3-dev on ubuntu.

To check if its ok run inside nvim after install sqlite.lua:

:lua require "sqlite.tbl"

samuelabreu avatar Jun 02 '22 11:06 samuelabreu

I specified the path to the file in the telescope sqlite file as I showed in my config...

fireboy1919 avatar Jun 02 '22 13:06 fireboy1919

Hi @fireboy1919, I got the same error, but do not know the path of the garbage file. Could you tell me its path?

He means the one that u set in the path:

require("telescope").setup {
  defaults = {
    wrap_results = true,
    history = {
      path = '~/.local/share/nvim/databases/telescope_history.sqlite3',
      limit = 100
    }
  }
}

So just delete telescope_history.sqlite3

Tej12345 avatar Jul 05 '23 13:07 Tej12345