Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing this plugin breaks neovims automatic background detection #210

Open
uloco opened this issue Jun 3, 2024 · 12 comments · May be fixed by #213
Open

Installing this plugin breaks neovims automatic background detection #210

uloco opened this issue Jun 3, 2024 · 12 comments · May be fixed by #213

Comments

@uloco
Copy link

uloco commented Jun 3, 2024

I have no idea how this is related but I am on nvim 0.10.0 and this is my used config in packer:

  use {
    'nvim-telescope/telescope-frecency.nvim',
    config = function()
      require 'telescope'.load_extension('frecency')
    end,
    requires = { 'kkharji/sqlite.lua' }
  }

When I enable this plugin and my terminal background is light, neovim accidentally sets background to dark. I removed all other plugins to test this and it is only causing the issue when installed.

@delphinus
Copy link
Contributor

  1. At first, packer.nvim already have been deprecated and does not support Neovim 0.10.
  2. This plugin doesn't need sqlite.lua now.

I recommend you to try with lazy.nvim and a minimal config.

@uloco
Copy link
Author

uloco commented Jun 4, 2024

@delphinus How is the my package manager related to this issue? All other plugins I am using don't cause any problems.

@delphinus
Copy link
Contributor

I can't support envs with deprecated products. Especially, plugin managers are the fundamental product that can cause various problems. I cannot debug them because I'm not the author of packer.nvim.

@uloco
Copy link
Author

uloco commented Jun 4, 2024

I created a minimal config with lazy.nvim, still the same issue. Reproduction steps are there in the readme. https://github.com/uloco/repro-frecency-background-issue

@delphinus
Copy link
Contributor

Oh, yes. Thank you. I could reproduce it with macOS and Wezterm. I will look into further.

@delphinus
Copy link
Contributor

Hmm... I found this diff below can solve this. But why……

diff --git a/lua/frecency/database.lua b/lua/frecency/database.lua
index 27c5bf4..af24a4e 100644
--- a/lua/frecency/database.lua
+++ b/lua/frecency/database.lua
@@ -30,6 +30,7 @@ Database.new = function(fs)
     tbl = Table.new(version),
     version = version,
   }, { __index = Database })
+  self.tbl:set()
   self.filename = (function()
     -- NOTE: for backward compatibility
     -- If the user does not set db_root specifically, search DB in

@delphinus
Copy link
Contributor

Maybe, vim.wait causes this, I think.

diff --git a/lua/frecency/database.lua b/lua/frecency/database.lua
index 27c5bf4..79c197e 100644
--- a/lua/frecency/database.lua
+++ b/lua/frecency/database.lua
@@ -70,7 +70,7 @@ end
 
 ---@return boolean
 function Database:has_entry()
-  return not vim.tbl_isempty(self.tbl.records)
+  return not vim.tbl_isempty(self.tbl and self.tbl.records or {})
 end
 
 ---@param paths string[]
@@ -80,7 +80,9 @@ function Database:insert_files(paths)
     return
   end
   for _, path in ipairs(paths) do
-    self.tbl.records[path] = { count = 1, timestamps = { 0 } }
+    if self.tbl and self.tbl.records then
+      self.tbl.records[path] = { count = 1, timestamps = { 0 } }
+    end
   end
   self.tx.send "save"
 end
@@ -88,7 +90,7 @@ end
 ---@return string[]
 function Database:unlinked_entries()
   local paths = {}
-  for file in pairs(self.tbl.records) do
+  for file in pairs(self.tbl.records or {}) do
     if not self.fs:is_valid_path(file) then
       table.insert(paths, file)
     end
diff --git a/lua/frecency/database/table.lua b/lua/frecency/database/table.lua
index 79a4945..34ed094 100644
--- a/lua/frecency/database/table.lua
+++ b/lua/frecency/database/table.lua
@@ -48,7 +48,8 @@ end
 ---@return nil
 function Table:wait_ready()
   vim.wait(2000, function()
-    return rawget(self, "is_ready")
+    -- return rawget(self, "is_ready")
+    return true
   end)
 end
 

@delphinus
Copy link
Contributor

@uloco FYI

I still have been inquiring, but a stopgap measure exists for this.

This problem is caused by calling telescope.load_extension "frecency" in startup. In fact, this is not needed for calling frecency by commands, such as :Telescope frecency.

require("lazy").setup({
  "nvim-lua/plenary.nvim",
  "nvim-telescope/telescope.nvim",
  "nvim-telescope/telescope-frecency.nvim",
})

vim.keymap.set("n", ",tf", "<CMD>Telescope frecency<CR>")

With this setup, you can call :Telescope frecency with no errors. But you want to call by Lua code, such as code below, then you need load_extension before that.

local loaded
vim.keymap.set("n", ",tf", function()
  local telescope = require "telescope"
  if not loaded then
    telescope.load_extension "frecency"
    loaded = true
  end
  telescope.extensions.frecency.frecency {}
end)

@delphinus
Copy link
Contributor

I found #213 can solve this. But I can't understand the reason. 🤔 🤔 🤔

@uloco
Copy link
Author

uloco commented Jun 19, 2024

I think nvim introduced changes regarding the detection when they introduced the default theme. On my phone right now, I can post more later.

@uloco
Copy link
Author

uloco commented Jun 19, 2024

I unfortunately can't find the changes anymore.... But I think they set some default background when it takes too long to load a plugin or so. Can't remember sorry.

@uloco
Copy link
Author

uloco commented Jun 27, 2024

Could this PR, change be the reason?
https://github.com/neovim/neovim/pull/28676/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants