Closed dharmx closed 2 years ago
I haven't looked at the config closely, but this error
E5108: Error executing lua ...nvim/site/pack/packer/opt/nvim-gps/lua/nvim-gps/init.lua:358: bad argument #1 to 'pairs' (table expected, got string)
stack traceback:
will occur only when the get_location
function is called when is_available
is false.
But the problem with the above snippet is that it throws error for filetypes that do not have a treesitter parser.
You could try replacing the call to get_location
with a custom function like this
local functionl my_gps()
if gps.is_available() then
return gps.get_location()
else
return ""
end
end
This is so embarassing! I wish I could delete this issue!!! This is the code now... so much shorter.
function M.treesitter()
local fallback = "%%#StatusLineScopesOFF#%s%%#StatusLineScopes#%%#StatusLineScopesReverse#%s%%#Statusline#"
local available = "%%#StatusLineScopesON#%s%%#StatusLineScopes#%s%%#StatusLineScopesReverse#%s%%#Statusline#"
if packer_plugins and packer_plugins["nvim-gps"].loaded then
local scopes = require "nvim-gps"
return scopes.is_available()
and string.format(available, config.enabled_icon, scopes.get_location(), config.style.left)
or string.format(fallback, config.disabled_icon, config.style.left)
end
return "%#Statusline#"
end
Thanks for the quick response by the way! Closing...
Haha no worries 😄
I was trying to integrate this to my custom statusline and at first it was working perfectly fine:
But the problem with the above snippet is that it throws error for filetypes that do not have a treesitter parser.
I used a workaround to get through this by the way:
Now everything was fine for a solid 3 days, until I opened a markdown file. Now, it again threw that same error. So, I verified if a parser was installed, and it was. To workaround this I excluded mardown completely.
Additional Information
Neovim version
Lazy loading treesitter using packer
GPS Config
Other Information
My statusline configuration here
Video demo
https://user-images.githubusercontent.com/80379926/159715051-16feec94-48cb-48cc-b1ea-f95efdbe9453.mp4
I am not really sure if this is a bug or, not so, I would love to have some insight! Maybe a treesitter API utility function that looks if the parser supports X or, not(?)