nvim-neorg / neorg-telescope

Telescope.nvim integration for Neorg
GNU General Public License v3.0
187 stars 24 forks source link

search_headings crashing #21

Closed VPerrollaz closed 1 year ago

VPerrollaz commented 2 years ago

Hi,

when trying :Telescope neorg search_headings

I get this error

Error executing Lua callback: ...cope/lua/telescope/_extensions/neorg/search_headings.lua:68: attempt to index local 'query' (a
 nil value)
stack traceback:
        ...cope/lua/telescope/_extensions/neorg/search_headings.lua:68: in function <...cope/lua/telescope/_extensions/neorg/se
arch_headings.lua:21>
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:183: in function 'run_command'
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
        ...te/pack/packer/start/telescope.nvim/plugin/telescope.lua:109: in function <...te/pack/packer/start/telescope.nvim/pl
ugin/telescope.lua:108>

after looking into the code of search_heading.lua I found that the variable filetype was set to the empty string.

The error got removed when I placed the lines

local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
local bufnr = vim.api.nvim_get_current_buf()
local filename = vim.fn.expand(vim.api.nvim_buf_get_name(bufnr))
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")

inside the function being returned.

This makes more sense to me in any case otherwise it seems that when you have multiple norg buffers opened only the original one is searched.

However I then got a second error

Error executing Lua callback: ...cope/lua/telescope/_extensions/neorg/search_headings.lua:99: attempt to get length of a nil va
lue
stack traceback:
        ...cope/lua/telescope/_extensions/neorg/search_headings.lua:99: in function <...cope/lua/telescope/_extensions/neorg/se
arch_headings.lua:14>
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:183: in function 'run_command'
        ...ck/packer/start/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
        ...te/pack/packer/start/telescope.nvim/plugin/telescope.lua:109: in function <...te/pack/packer/start/telescope.nvim/pl
ugin/telescope.lua:108>

It seems to come from the block

while row < row2 + 1 do
            row = row + 1

            for index = 0, #lines[row] do
              line_highlights[row][index] = hl
            end
          end

By making the loop condition row < row2 the error got removed and now the function works well on my end. Given how little experience I have I could totally have missed something however.

TornaxO7 commented 1 year ago

I'm getting this error as well

max397574 commented 1 year ago

after some changes this should be fixed reopen if it isn't

VPerrollaz commented 1 year ago

I don't have this issue anymore. However I will probably have to open another one because while

:Telescope neorg search_headings

indexes the headings correctly, the previewer and the jumps point toward wrong places when multiple buffers are opened.

max397574 commented 1 year ago

I see the problem yes you should open a new issues for that

max397574 commented 1 year ago

@VPerrollaz the other issue should be fixed now as well (it is on my end) can you confirm?

VPerrollaz commented 1 year ago

@max397574 Yes it seems to be fine on my side also. Thank you.