uga-rosa / cmp-dictionary

A dictionary completion source for nvim-cmp
MIT License
236 stars 16 forks source link

mtime NOT NULL constrained failed #49

Closed TimManzi closed 5 months ago

TimManzi commented 1 year ago

https://github.com/uga-rosa/cmp-dictionary/blob/3a6035b34b67f4a9b6142086c02d9e2673fa4810/lua/cmp_dictionary/db.lua#L109

Possible fix is remove required?? Not quite sure tbh

uga-rosa commented 1 year ago

What's the situation when you're not getting the mtime of a file you're supposed to have read? I don't like ad hoc workarounds. If there is a problem, please report it properly.

TimManzi commented 1 year ago

Neovim throws error on startup and also :CmpDictionaryUpdate

uga-rosa commented 1 year ago

Create a stand-alone minimal init.lua that can reproduce this issue. It is difficult to fix a problem that cannot be reproduced. This would be helpful. https://github.com/hrsh7th/nvim-cmp/blob/main/utils/vimrc.vim

TimManzi commented 1 year ago
aspell -d en dump master | aspell -l en expand > ~/.local/share/nvim/cmp-dict.dict

~/.config/nvim/init.lua

local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

require("packer").startup {
  function(use)
    use { "wbthomason/packer.nvim" }
    use {
      "kkharji/sqlite.lua",
      setup = function() require("setup.sqlite") end,
    }
    use { "nvim-tree/nvim-web-devicons" }
    use {
      "hrsh7th/nvim-cmp",
      requires = {
        "hrsh7th/cmp-buffer",
        {
          "uga-rosa/cmp-dictionary",
          -- disable = true, -- TODO: for some strange reason this doesn't work anymore
          config = function()
            local dict = require("cmp_dictionary")

            dict.setup { sqlite = true, debug = true }
            dict.switcher {
              spelllang = {
                en = vim.fn.stdpath("data") .. "cmp-dict.dict"
              }
            }
          end
        },
      },
      config = function() require("config.lsp") end,
    }
    if packer_bootstrap then
      require("packer").sync()
    end
  end,
  -- startup options
  config = { git = { clone_timeout = false } }
}

Error Messages:

Error executing vim.schedule lua callback: ...nvim/sit
e/pack/packer/opt/sqlite.lua/lua/sqlite/stmt.lua:57: s
qlite.lua: couldn't finalize statement, ERRMSG: NOT NU
LL constraint failed: dictionary.mtime stmt = (insert
into dictionary (valid) values(:valid))
stack traceback:
        [C]: in function 'assert'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/stmt.lua:57: in function 'finalize'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:465: in function 'fn'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/defs.lua:664: in function 'wrap_stmts'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:459: in function 'insert'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:523: in function 'fn'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/defs.lua:664: in function 'update'
        ...ck/packer/start/cmp-dictionary/lua/cmp_dict
ionary/db.lua:109: in function 'update'
        ...ck/packer/start/cmp-dictionary/lua/cmp_dict
ionary/db.lua:138: in function 'callback'
        .../packer/start/cmp-dictionary/lua/cmp_dictio
nary/util.lua:99: in function 'cb'
        vim/_editor.lua:263: in function <vim/_editor.
lua:262>

Error executing vim.schedule lua callback: ...nvim/sit
e/pack/packer/opt/sqlite.lua/lua/sqlite/stmt.lua:57: s
qlite.lua: couldn't finalize statement, ERRMSG: NOT NU
LL constraint failed: dictionary.mtime stmt = (insert
into dictionary (valid) values(:valid))
stack traceback:
        [C]: in function 'assert'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/stmt.lua:57: in function 'finalize'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:465: in function 'fn'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/defs.lua:664: in function 'wrap_stmts'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:459: in function 'insert'
        ...e/nvim/site/pack/packer/opt/sqlite.lua/lua/
sqlite/db.lua:523: in function 'fn'
        ...nvim/site/pack/packer/opt/sqlite.lua/lua/sq
lite/defs.lua:664: in function 'update'
        ...ck/packer/start/cmp-dictionary/lua/cmp_dict
ionary/db.lua:109: in function 'update'
        ...ck/packer/start/cmp-dictionary/lua/cmp_dict
ionary/db.lua:138: in function 'callback'
        .../packer/start/cmp-dictionary/lua/cmp_dictio
nary/util.lua:99: in function 'cb'
        vim/_editor.lua:263: in function <vim/_editor.
lua:262>

Buffer sources work as you can see. Screenshot_20230623-114429~2

I've completely disabled all other plugins even telescope and frecency that require sqlite which still work btw.

And this is my config.lsp

local cmp = require("cmp")
-- local luasnip = require("luasnip")
-- local lspkind = require("lspkind")

cmp.setup {
  -- snippet = {
  --   expand = function(args)
  --     luasnip.lsp_expand(args.body)
  --   end,
  -- },
  mapping = cmp.mapping.preset.insert {
    ["<C-d>"] = cmp.mapping.scroll_docs(4),
    ["<C-u>"] = cmp.mapping.scroll_docs(-4),
    ["<C-Space>"] = cmp.mapping.complete(),
    ["<C-c>"] = cmp.mapping.abort(),
    ["<CR>"] = cmp.mapping.confirm {
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    },
    ["<Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      elseif luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      else
        fallback()
      end
    end, { "i", "s" }),
    ["<S-Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_prev_item()
      elseif luasnip.jumpable(-1) then
        luasnip.jump(-1)
      else
        fallback()
      end
    end, { "i", "s" }),
  },
  sources = cmp.config.sources({
    -- { name = "luasnip" },
    -- { name = "nvim_lsp" },
    -- { name = "nvim_lsp_signature_help" },
    -- { name = "nvim_lua" },
    -- { name = "emoji" },
  }, {
    -- TODO: failed unexptedly
    {
      name = "dictionary",
      keyword_length = 2,
    },
    {
      name = "buffer",
      keyword_length = 2
    },
    -- { name = "rg" }, -- diplay file source: linenumber and context
    -- { name = "spell" },
    -- { name = "fuzzy_path" },
  }),
  -- window = {
  --   completion = {
  --     col_offset = -3,
  --     side_padding = 0,
  --   },
  -- },
  -- formatting = {
  --   fields = { "kind", "abbr", "menu" },
  --   format = function(entry, item)
  --     local kind = lspkind.cmp_format {
  --       mode = "symbol_text",
  --       maxwidth = vim.g.termux and 24 or 48,
  --     } (entry, item)
  --
  --     local strings = vim.split(kind.kind, "%s", { trimempty = true })
  --     local menu = ({
  --       buffer = "Buffer",
  --       luasnip = "LuaSnip",
  --       nvim_lsp = "LSP",
  --       nvim_lua = "Lua",
  --     })[entry.source.name]
  --
  --     kind.kind = " " .. (strings[1] or "") .. " "
  --     kind.menu = "    (" .. (strings[2] or "") .. ((menu and ("|" .. menu)) or "") .. ")"
  --
  --     return kind
  --   end,
  -- },
}

-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline({ "/", "?" }, {
--   mapping = cmp.mapping.preset.cmdline(),
--   sources = {
--     { name = "buffer", keyword_length = 2 }
--   }
-- })
--
-- -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline(":", {
--   mapping = cmp.mapping.preset.cmdline(),
--   sources = cmp.config.sources({
--     { name = "path" }
--   }, {
--     { name = "cmdline" },
--     -- { name = "cmdline_history" },
--     -- { name = "fuzzy_path" },
--   })
-- })
uga-rosa commented 11 months ago

It does not reproduce. what is setup.sqlite? Also, the dictionary path is incorrect. vim.fn.stdpath("data") . "/cmp-dict.dict" would be correct. There is no delimiter. Also, please don't use packer because it has side effects. use vim-plug.

uga-rosa commented 11 months ago

Try deleting vim.fn.stdpath("data") .. "/cmp-dictionary.sqlite3" once.

hongxuchen commented 11 months ago

I also came across this error message:

Error executing vim.schedule lua callback: /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/stmt.lua:57: sqlite.lua: couldn't finalize statement, ERRMSG: NOT NULL constraint failed: dictionary.mtime stmt = (inse
rt into dictionary (valid) values(:valid))
stack traceback:
        [C]: in function 'assert'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/stmt.lua:57: in function 'finalize'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/db.lua:465: in function 'fn'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/defs.lua:664: in function 'wrap_stmts'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/db.lua:459: in function 'insert'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/db.lua:523: in function 'fn'
        /root/.local/share/nvim/lazy/sqlite.lua/lua/sqlite/defs.lua:664: in function 'update'
        ...share/nvim/lazy/cmp-dictionary/lua/cmp_dictionary/db.lua:109: in function 'update'
        ...share/nvim/lazy/cmp-dictionary/lua/cmp_dictionary/db.lua:138: in function 'callback'
        ...are/nvim/lazy/cmp-dictionary/lua/cmp_dictionary/util.lua:99: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
uga-rosa commented 5 months ago

v3 is released. sqlite is deprecated.