nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.25k stars 815 forks source link

builtin.lsp_document_symbols,Executing this command caused a bug. #2456

Open fzhzhen1987 opened 1 year ago

fzhzhen1987 commented 1 year ago

Description

I am using the whichkey plugin and setting lsp_document_symbols.like this: [""] = {"lua require('telescope.builtin').lsp_document_symbols(require('telescope.themes').get_ivy())", "Find Document Symbols"}

Executing this command caused a bug.

Neovim version

NVIM v0.9.0-dev-1312+g908494889
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

archlinux

Telescope version / branch / rev

telescope tag = "0.1.1"

checkhealth telescope

3 telescope: require("telescope.health").check()                                                                                                                                       4                                                                                                                                                                                      5 Checking for required plugins                                                                                                                                                        6 - OK plenary installed.                                                                                                                                                              7 - OK nvim-treesitter installed.                                                                                                                                                      8                                                                                                                                                                                      9 Checking external dependencies                                                                                                                                                      10 - OK rg: found ripgrep 13.0.0                                                                                                                                                       11 - OK fd: found fd 8.4.0                                                                                                                                                             12                                                                                                                                                                                     13 ===== Installed extensions =====                                                                                                                                                    14                                                                                                                                                                                     15 Telescope Extension: `fzf`                                                                                                                                                          16 - OK lib working as expected                                                                                                                                                        17 - OK file_sorter correctly configured                                                                                                                                               18 - OK generic_sorter correctly configured                                                                                                                                            19                                                                                                                                                                                     20 Telescope Extension: `live_grep_args`                                                                                                                                               21 - No healthcheck provided

Steps to reproduce

  1. nvim update to v0.9.0-dev-1312+g908494889
  2. install lsp plugin
  3. In my environment, I am reading C language code.
  4. Execute command C-u.
  5. Executing this command caused a bug

Expected behavior

No response

Actual behavior

error message: E5108: Error executing lua ...acker/start/telescope.nvim/lua/telescope/builtin/lsp.lua:448: attempt to index field 'resolved_capabilities' (a nil value) stack traceback: ...acker/start/telescope.nvim/lua/telescope/builtin/lsp.lua:448: in function 'check_capabilities' ...acker/start/telescope.nvim/lua/telescope/builtin/lsp.lua:488: in function 'v' ...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:489: in function 'lsp_document_symbols' [string ":lua"]:1: in main chunk

Minimal config

local status_ok, telescope = pcall(require, "telescope")
if not status_ok then
    vim.notify("telescope not found!")
    return
end

local actions = require "telescope.actions"
--local bug_actions = require "telescope-live-grep-args.actions"

-- disable preview binaries
local previewers = require("telescope.previewers")
local Job = require("plenary.job")
local new_maker = function(filepath, bufnr, opts)
    filepath = vim.fn.expand(filepath)
    Job:new({
        command = "file",
        args = { "--mime-type", "-b", filepath },
        on_exit = function(j)
            local mime_type = vim.split(j:result()[1], "/")[1]
            if mime_type == "text" then
                previewers.buffer_previewer_maker(filepath, bufnr, opts)
            else
                -- maybe we want to write something to the buffer here
                vim.schedule(function()
                    vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" })
                end)
            end
        end
    }):sync()
end

telescope.setup {
    defaults = {
        buffer_previewer_maker = new_maker,

        prompt_prefix = " ",
        selection_caret = " ",
        path_display = {
            shorten = {
                -- e.g. for a path like
                --   `alpha/beta/gamma/delta.txt`
                -- setting `path_display.shorten = { len = 1, exclude = {1, -1} }`
                -- will give a path like:
                --   `alpha/b/g/delta.txt`
                len = 3, exclude = { 1, -1 }
            },
        },

        mappings = {
            i = {
                ["<C-n>"] = actions.move_selection_next,
                ["<C-p>"] = actions.move_selection_previous,
                ["<C-j>"] = actions.preview_scrolling_down,
                ["<C-k>"] = actions.preview_scrolling_up,
                ["<C-o>"] = actions.select_horizontal,
                ["<C-e>"] = actions.select_vertical,
                ["<C-t>"] = actions.select_tab,
                ["<CR>"] = actions.select_default,
                ["<C-q>"] = actions.close,

                ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
                ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
                ["<C-c>"] = actions.send_to_qflist + actions.open_qflist,
                ["<M-c>"] = actions.send_selected_to_qflist + actions.open_qflist,

                ["<M-n>"] = actions.cycle_history_next,
                ["<M-p>"] = actions.cycle_history_prev,

                ["<PageUp>"] = actions.results_scrolling_up,
                ["<PageDown>"] = actions.results_scrolling_down,

                ["<C-l>"] = actions.complete_tag,
                ["<C-_>"] = actions.which_key, -- keys from pressing <C-/>
            },

            n = {
                ["<C-n>"] = actions.move_selection_next,
                ["<C-p>"] = actions.move_selection_previous,
                ["<C-j>"] = actions.preview_scrolling_down,
                ["<C-k>"] = actions.preview_scrolling_up,
                ["<C-o>"] = actions.select_horizontal,
                ["<C-e>"] = actions.select_vertical,
                ["<C-t>"] = actions.select_tab,
                ["<CR>"] = actions.select_default,
                ["<C-q>"] = actions.close,

                ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
                ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
                ["<C-c>"] = actions.send_to_qflist + actions.open_qflist,
                ["<M-c>"] = actions.send_selected_to_qflist + actions.open_qflist,

                ["<M-n>"] = actions.cycle_history_next,
                ["<M-p>"] = actions.cycle_history_prev,

                ["<PageUp>"] = actions.results_scrolling_up,
                ["<PageDown>"] = actions.results_scrolling_down,

                ["<C-_>"] = actions.which_key,
            },
        },
    },
    pickers = {
        find_files = {
            theme = "dropdown",
            previewer = false,
            -- find_command = { "find", "-type", "f" },
            find_command = { "fd", "-H" , "-I"},  -- "-H" search hidden files, "-I" do not respect to gitignore
        },

        -- Default configuration for builtin pickers goes here:
        -- picker_name = {
        --   picker_config_key = value,
        --   ...
        -- }
        -- Now the picker_config_key will be applied every time you call this
        -- builtin picker
    },
    extensions = {
        -- Your extension configuration goes here:
        -- extension_name = {
        --   extension_config_key = value,
        -- }

        -- fzf syntax
        -- Token    Match type  Description
        -- sbtrkt   fuzzy-match Items that match sbtrkt
        -- 'wild'   exact-match (quoted)    Items that include wild
        -- ^music   prefix-exact-match  Items that start with music
        -- .mp3$    suffix-exact-match  Items that end with .mp3
        -- !fire    inverse-exact-match Items that do not include fire
        -- !^music  inverse-prefix-exact-match  Items that do not start with music
        -- !.mp3$   inverse-suffix-exact-match  Items that do not end with .mp3
        fzf = {
            fuzzy = true, -- false will only do exact matching
            override_generic_sorter = true, -- override the generic sorter
            override_file_sorter = true, -- override the file sorter
            case_mode = "smart_case", -- or "ignore_case" or "respect_case"
            -- the default case_mode is "smart_case"
        },
    },
}

vim.cmd "autocmd User TelescopePreviewerLoaded setlocal number"

telescope.load_extension('fzf')
telescope.load_extension("live_grep_args")
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
fzhzhen1987 commented 1 year ago

I just used the master branch. It seems you have already fixed this issue. Thank you, my respected friend.

Conni2461 commented 1 year ago

is this bug also present on the telescope 0.1.x branch? if not we should just close this bug report and i plan to release 0.1.2 in the next couple of days