nvim-telescope / telescope.nvim

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

Empty LSP symbol picker using `clangd` on large projects #1747

Closed cigam closed 2 years ago

cigam commented 2 years ago

Description

I have LSP with clangd configured properly on using compile_commands.json and all of the other LSP functions are working ok.

Trying to get document symbols through LSP or TreeSitter shows an empty picker, even though it seems that telescope sends it the data.

I tried debugging as further as I could but lost track when reached the window management code...

I'd be happy to continue debugging if someone can give me some guidance on where to look next

Neovim version

NVIM v0.7.0-dev+1053-g38bf52821
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by XXX

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/brew/Cellar/neovim/HEAD-38bf528/share/nvim"

Run :checkhealth for more info

Operating system and version

macOS 11.5

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.2.1

## ===== Installed extensions =====

## Telescope Extension: `fzf`
  - INFO: No healthcheck provided

Steps to reproduce

  1. Clone the llvm project: git clone https://github.com/llvm/llvm-project.git
  2. Configure it and generate compile_commands.json: cd llvm-project; mkdir build; cd build; cmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ../llvm
  3. copy the generated compile_commands.json from the build directory to the llvm directory
  4. Open a cpp source file (for example, lib/LTO/LTO.cpp) and run :Telescope lsp_document_symbols

Expected behavior

Picker with document symbols

Actual behavior

Screen Shot 2022-02-14 at 15 05 01

rpc_response.txt

Adding debug prints across telescope, I'm able to observe that the data is return and parsed correctly by telescope and is valid inside the finder construction. Dumping the table before calling setmetatable in telescope.nvim/lua/telescope/finders/async_static_finder.lua looks ok, but that's where I lost track of the code...

Added text file with RPC response

In simpler projects, clangd works ok

Minimal config

local fn = vim.fn
local execute = vim.api.nvim_command

local global = vim.g
global.mapleader = " "

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', 'https://github.com/wbthomason/packer.nvim',
        install_path
    })
    execute 'packadd packer.nvim'
end

require('packer').startup(function()
    -- Packer can manage itself
    use 'wbthomason/packer.nvim'
    -- Nvim Tree for file exploring
    use {
        'kyazdani42/nvim-tree.lua',
        requires = 'kyazdani42/nvim-web-devicons',
        config = function() require'nvim-tree'.setup {} end
    }
    -- Native LSP for neovim
    use 'neovim/nvim-lspconfig'
    use 'williamboman/nvim-lsp-installer'
    use {
        "hrsh7th/nvim-cmp",
        requires = {
            'hrsh7th/vim-vsnip',
            'L3MON4D3/LuaSnip', -- Snippets plugin
            'hrsh7th/cmp-nvim-lsp', -- Source nvim lsp
            'hrsh7th/cmp-calc',
            'hrsh7th/cmp-path',
            'hrsh7th/cmp-buffer',
            'hrsh7th/cmp-vsnip',
            'hrsh7th/cmp-nvim-lsp-signature-help', -- LSP Signature
        }
    }

    use {
      'nvim-telescope/telescope.nvim',
      requires = { {'nvim-lua/plenary.nvim'}, {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }}
    }

    use { 'alexghergh/nvim-tmux-navigation', config = function()
        require'nvim-tmux-navigation'.setup {
            disable_when_zoomed = true, -- defaults to false
        }
        end
    }
    -- Tresitter
    use 'nvim-treesitter/nvim-treesitter'
    -- Commenter
    use 'b3nj5m1n/kommentary'
    -- Git
    use {'lewis6991/gitsigns.nvim', requires = {'nvim-lua/plenary.nvim'}}

    use { "ellisonleao/gruvbox.nvim" }
end)

--No swap file
vim.cmd('set noswapfile')

--Line above scroll
vim.o.scrolloff=5

vim.wo.relativenumber = true
vim.wo.number = true

-- Smart Case
vim.o.ignorecase = true
vim.o.smartcase = true

-- Colors
vim.o.cursorline = true
vim.o.termguicolors = true

-- Indentation
vim.o.tabstop = 4
vim.o.softtabstop = 4
vim.o.shiftwidth = 4
vim.o.expandtab = true
vim.o.smartindent = true
vim.o.autoindent = true

-- Split panes position
vim.o.splitbelow = true
vim.o.splitright = true

vim.opt.termguicolors = true
vim.o.background = "dark" -- or "light" for light mode
vim.cmd([[colorscheme gruvbox]])

-- PLUGINS
--
local lsp_installer = require("nvim-lsp-installer")

-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
    local opts = {}

    -- (optional) Customize the options passed to the server
    -- if server.name == "tsserver" then
    --     opts.root_dir = function() ... end
    -- end

    -- This setup() function is exactly the same as lspconfig's setup function.
    -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
    server:setup(opts)
end)

require('kommentary.config').use_extended_mappings()

require('gitsigns').setup {
  on_attach = function(bufnr)
    local function map(mode, lhs, rhs, opts)
        opts = vim.tbl_extend('force', {noremap = true, silent = true}, opts or {})
        vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts)
    end

    -- Navigation
    map('n', ']c', "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", {expr=true})
    map('n', '[c', "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", {expr=true})

    -- Actions
    map('n', '<leader>hs', ':Gitsigns stage_hunk<CR>')
    map('v', '<leader>hs', ':Gitsigns stage_hunk<CR>')
    map('n', '<leader>hr', ':Gitsigns reset_hunk<CR>')
    map('v', '<leader>hr', ':Gitsigns reset_hunk<CR>')
    map('n', '<leader>hS', '<cmd>Gitsigns stage_buffer<CR>')
    map('n', '<leader>hu', '<cmd>Gitsigns undo_stage_hunk<CR>')
    map('n', '<leader>hR', '<cmd>Gitsigns reset_buffer<CR>')
    map('n', '<leader>hp', '<cmd>Gitsigns preview_hunk<CR>')
    map('n', '<leader>hb', '<cmd>lua require"gitsigns".blame_line{full=true}<CR>')
    map('n', '<leader>tb', '<cmd>Gitsigns toggle_current_line_blame<CR>')
    map('n', '<leader>hd', '<cmd>Gitsigns diffthis<CR>')
    map('n', '<leader>hD', '<cmd>lua require"gitsigns".diffthis("~")<CR>')
    map('n', '<leader>td', '<cmd>Gitsigns toggle_deleted<CR>')

    -- Text object
    map('o', 'ih', ':<C-U>Gitsigns select_hunk<CR>')
    map('x', 'ih', ':<C-U>Gitsigns select_hunk<CR>')
  end
}

local cmp = require 'cmp'
local capabilities = vim.lsp.protocol.make_client_capabilities()

capabilities.textDocument.completion.completionItem.documentationFormat = {
    'markdown', 'plaintext'
}
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.preselectSupport = true
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
capabilities.textDocument.completion.completionItem.commitCharactersSupport =
    true
capabilities.textDocument.completion.completionItem.tagSupport = {
    valueSet = {1}
}
capabilities.textDocument.completion.completionItem.resolveSupport = {
    properties = {'detail', 'documentation', 'additionalTextEdits'}
}

cmp.setup({
    completion = {completeopt = 'menu,menuone,noinsert'},
    snippet = {
        expand = function(args) require('luasnip').lsp_expand(args.body) end
    },
    mapping = {
        ['<C-d>'] = cmp.mapping.scroll_docs(-4),
        ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ['<C-Space>'] = cmp.mapping.complete(),
        ['<C-e>'] = cmp.mapping.close(),
        ['<CR>'] = cmp.mapping.confirm({
            behavior = cmp.ConfirmBehavior.Replace,
            select = true
        })
    },
    sources = {
        {name = 'nvim_lsp'},
        {name = 'nvim_lsp_signature_help' },
        {name = 'luasnip'},
        {name = 'path' },
        {name = 'buffer', keyword_length = 4 },
        {name = 'calc'}
    }
})

require('telescope').setup {
    extensions = {
        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"
        }
    },
    defaults = {
        file_ignore_patterns = { "node_modules", ".git" },
        color_devicons = true
    }
}
-- To get fzf loaded and working with telescope, you need to call
-- load_extension, somewhere after setup function:
require('telescope').load_extension('fzf')

-- KEYMAP
local map = vim.api.nvim_set_keymap

-- Options
noremap = {noremap = true}
local opts = {noremap = true, silent = true}

map('n', '<leader>qq', ':qall<CR>', noremap)
map('n', '<leader>QQ', ':qall!<CR>', noremap)
-- Buffer Commands
map('n', '<leader>bc', ':close<CR>', noremap)
map('n', '<leader>bx', ':bd<CR>', noremap)
map('n', '<leader>bX', ':bd!<CR>', noremap)
map('i', 'jk', '<ESC>', noremap)

-- Clear search mark
map('n', '<Leader><esc>', ':noh<cr>', noremap)

-- autoreloading config file
map('n', '<leader>ve', ':e $MYVIMRC', noremap)
map('n', '<leader>vr', ':so $MYVIMRC', noremap)

-- Nvim Tree
map('n', '<leader>nn', ':NvimTreeToggle<CR>', noremap)
map('n', '<leader>nf', ':NvimTreeFindFile<CR>', noremap)
map('n', '<leader>nr', ':NvimTreeRefresh<CR>', noremap)

-- Compe
-- map("i", "<CR>", "compe#confirm('<CR>')", { expr = true })
map('i', '<silent><expr><C-f>', 'compoe#scroll({ delta : +4 })', noremap)
map('i', '<silent><expr><C-b>', 'compoe#scroll({ delta : +4 })', noremap)

-- Telescope
map('n', '<leader>p', "<cmd>lua require('telescope.builtin').git_files()<cr>", noremap)
map('n', '<leader>P', "<cmd>lua require('telescope.builtin').find_files()<cr>", noremap)
map('n', '<leader>o', "<cmd>lua require('telescope.builtin').lsp_document_symbols()<cr>", noremap)
map('n', '<leader>O', "<cmd>lua require('telescope.builtin').lsp_dynamic_workspace_symbols()<cr>", noremap)
map('n', '<leader>r', "<cmd>lua require('telescope.builtin').buffers()<cr>", noremap)
map('n', '<leader>*', "<cmd>lua require('telescope.builtin').grep_string()<cr>", noremap)
map('n', '<leader>/', "<cmd>lua require('telescope.builtin').live_grep { debounce = 100 }<cr>", noremap)

-- Barbar
-- Move to previous/next
map('n', '<leader>bp', ':BufferPrevious<CR>', opts)
map('n', '<leader>bn', ':BufferNext<CR>', opts)
map('n', '<leader><leader>', ':b#<CR>', opts)
-- Re-order to previous/next
map('n', '<leader>bP', ':BufferMovePrevious<CR>', opts)
map('n', '<leader>bN', ' :BufferMoveNext<CR>', opts)
-- Goto buffer in position...
map('n', '<leader>b1', ':BufferGoto 1<CR>', opts)
map('n', '<leader>b2', ':BufferGoto 2<CR>', opts)
map('n', '<leader>b3', ':BufferGoto 3<CR>', opts)
map('n', '<leader>b4', ':BufferGoto 4<CR>', opts)
map('n', '<leader>b5', ':BufferGoto 5<CR>', opts)
map('n', '<leader>b6', ':BufferGoto 6<CR>', opts)
map('n', '<leader>b7', ':BufferGoto 7<CR>', opts)
map('n', '<leader>b8', ':BufferGoto 8<CR>', opts)
map('n', '<leader>b9', ':BufferGoto 9<CR>', opts)
map('n', '<leader>b0', ':BufferLast<CR>', opts)
-- Close buffer
map('n', '<leader>bc', ':BufferClose<CR>', opts)
-- Magic buffer-picking mode
map('n', '<leader>bj', ':BufferPick<CR>', opts)
-- Sort automatically by...
-- map('n', '<Space>bb', ':BufferOrderByBufferNumber<CR>', opts)
-- map('n', '<Space>bd', ':BufferOrderByDirectory<CR>', opts)
-- map('n', '<Space>bl', ':BufferOrderByLanguage<CR>', opts)

-- LSP commands
map('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
map('n', 'gd', "<cmd>lua require('telescope.builtin').lsp_definitions()<cr>", opts)
map('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
map('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
map('n', '<C-K>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
map('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
map('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
map('n', '<space>wl',
    '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>',
    opts)
map('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
map('n', '<space>R', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
map('n', '<space>C', "<cmd>lua require('telescope.builtin').lsp_code_actions()<cr>", opts)
map('n', 'gr', "<cmd>lua require('telescope.builtin').lsp_references()<cr>", opts)
map('n', '<space>e', "<cmd>lua require('telescope.builtin').diagnostics()<cr>",
    opts)
map('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
map('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
map('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
map("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
map("v", "<space>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)

-- Vim Fugitive
map("n", "<leader>gs", ":G<CR>", opts)
map("n", "<leader>gh", ":diffget //2<CR>", opts)
map("n", "<leader>gl", ":diffget //3<CR>", opts)

-- Move or create windows
map('n', "<leader>sh", ":lua WinMove('h')<cr>", { noremap = true, silent = true })
map('n', "<leader>sj", ":lua WinMove('j')<cr>", { noremap = true, silent = true })
map('n', "<leader>sk", ":lua WinMove('k')<cr>", { noremap = true, silent = true })
map('n', "<leader>sl", ":lua WinMove('l')<cr>", { noremap = true, silent = true })

-- Tmux Navigator
map('n', "<C-h>", ":lua require'nvim-tmux-navigation'.NvimTmuxNavigateLeft()<cr>", { noremap = true, silent = true })
map('n', "<C-j>", ":lua require'nvim-tmux-navigation'.NvimTmuxNavigateDown()<cr>", { noremap = true, silent = true })
map('n', "<C-k>", ":lua require'nvim-tmux-navigation'.NvimTmuxNavigateUp()<cr>", { noremap = true, silent = true })
map('n', "<C-l>", ":lua require'nvim-tmux-navigation'.NvimTmuxNavigateRight()<cr>", { noremap = true, silent = true })
Conni2461 commented 2 years ago

Okay i can't reproduce this

image

I did not try your config tho because its not really minimal. So much stuff like completion, gitsigns, isn't needed to reproduce this "bug" that you are experience.

Also your file_ignore_pattern don't look good. try file_ignore_patterns = { "node%_modules", "%.git" }, and read :help telescope.defaults.file_ignore_pattern

Conni2461 commented 2 years ago

Closing as stale and not reproducible.

Feel free to reopen if you still experience this issue