nvim-telescope / telescope.nvim

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

LSP document symbols would appear and disappear very quickly #1651

Open AgentCosmic opened 2 years ago

AgentCosmic commented 2 years ago

Description

I'll call this command :Telescope lsp_document_symbols. The window would open, and for a split second I can see some results showing in the window. But it would very quickly disappear and there would be nothing to select. I've noticed this on js, tsx, and py files so far.

Neovim version

NVIM v0.6.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az152-703

Operating system and version

Windows 10

checkhealth telescope

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

## Checking external dependencies
  - OK: rg: found ripgrep 0.10.0 (rev 8a7db1a918)
  - WARNING: fd: not found. Install [sharkdp/fd](https://github.com/sharkdp/fd) for extended capabilities

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

Steps to reproduce

  1. :Telescope lsp_document_symbols or just :Telescope followed by lsp_document_symbols

Expected behavior

Results should not disappear.

Actual behavior

See description.

Minimal config

" This is the folder where we'll store all the files
" set environment variable $env:XDG_CONFIG_HOME="D:/Applications/Neovim"
let $ROOT = expand('D:/Applications/Neovim/nvim')
set runtimepath+=$ROOT
" we reset $HOME directory here so plugins won't dirty our real home directory
let $HOME = $ROOT . '/home'

runtime mswin.vim

call plug#begin('$HOME/plugged')
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/nvim-cmp'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/popup.nvim' " telescope
Plug 'nvim-lua/plenary.nvim' " telescope
Plug 'nvim-telescope/telescope.nvim'
call plug#end()

" LSP
lua << EOF
local nvim_lsp = require('lspconfig')

-- Use an on_attach function to only map the following keys after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
end

-- this is where we install all the language servers
local lsp_bins = vim.api.nvim_eval("$ROOT . '\\lsp'")

-- nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

-- npm i  typescript-language-server
nvim_lsp.tsserver.setup{
    on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false    
        on_attach(client, bufnr)
    end,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\typescript-language-server.cmd', '--stdio' }
}

-- npm i vscode-langservers-extracted
nvim_lsp.cssls.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\vscode-css-language-server.cmd', '--stdio' },
    settings = {
        css = {
            validate = false,
        }
    }
}
nvim_lsp.html.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\vscode-html-language-server.cmd', '--stdio' },
}
nvim_lsp.jsonls.setup{
    on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false    
        on_attach(client, bufnr)
    end,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\vscode-json-language-server.cmd', '--stdio' },
}

-- go get github.com/mattn/efm-langserver
-- npm install eslint_d prettier
-- pip install black isort
local eslint = {
    lintCommand = lsp_bins .. '\\node_modules\\.bin\\eslint_d -f unix --stdin --stdin-filename ${INPUT}',
    lintStdin = true,
    lintFormats = {'%f:%l:%c: %m'},
    lintIgnoreExitCode = true,
    formatCommand = 'eslint_d --fix-to-stdout --stdin --stdin-filename=${INPUT}',
    formatStdin = true
}
local prettier_path = '.\\node_modules\\.bin\\prettier.cmd' -- default to local
local prettier_config = ' --config-precedence file-override --no-semi --use-tabs --single-quote'
-- use our own if project doesn't have
if vim.fn.executable(prettier_path) ~= 1 then
    prettier_path = lsp_bins .. '\\node_modules\\.bin\\prettier.cmd'
end
prettier_cmd = prettier_path .. prettier_config
nvim_lsp.efm.setup {
    on_attach = on_attach,
    capabilities = capabilities,
    init_options = {
        documentFormatting = true,
        hover = true,
        documentSymbol = true,
        codeAction = true,
    },
    filetypes = {'typescript', 'typescriptreact', 'javascript', 'javascriptreact', 'css', 'html', 'json', 'python', 'yaml'},
    settings = {
        rootMarkers = {'.git/', 'node_modules/'},
        languages = {
            typescript = {
                {formatCommand = prettier_cmd .. ' --parser typescript', formatStdin = true},
                eslint,
            },
            typescriptreact = {
                {formatCommand = prettier_cmd .. ' --parser typescript', formatStdin = true},
                eslint,
            },
            javascript = {
                {formatCommand = prettier_cmd .. ' --parser babel', formatStdin = true},
                eslint,
            },
            javascriptreact = {
                {formatCommand = prettier_cmd .. ' --parser babel', formatStdin = true},
                eslint,
            },
            css = {
                {formatCommand = prettier_cmd .. ' --parser css', formatStdin = true},
            },
            html = {
                {formatCommand = prettier_cmd .. ' --parser html', formatStdin = true},
            },
            json = {
                {formatCommand = prettier_cmd .. ' --parser json', formatStdin = true},
            },
            python = {
                {formatCommand = lsp_bins .. '\\.venv\\Scripts\\black.exe --quiet -', formatStdin = true},
                {formatCommand = lsp_bins .. '\\.venv\\Scripts\\isort.exe --quiet -', formatStdin = true},
            },
            yaml = {
                {formatCommand = prettier_cmd .. ' --parser yaml', formatStdin = true},
            },
        }
    }
}

-- npm i pyright
nvim_lsp.pyright.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\pyright-langserver.cmd', '--stdio' }
}

-- npm i yaml-language-server
nvim_lsp.yamlls.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\node_modules\\.bin\\yaml-language-server.cmd', '--stdio' },
}

-- https://solang.readthedocs.io/en/latest/installing.html
nvim_lsp.solang.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { lsp_bins .. '\\solang.exe', '--language-server', '--target', 'ewasm' },
}

-- https://github.com/eclipse/eclipse.jdt.ls
-- using v0.57 because we're using java 8
nvim_lsp.jdtls.setup{
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { 'java.exe', '-jar', lsp_bins .. '\\jdtls\\plugins\\org.eclipse.equinox.launcher_1.5.700.v20200207-2156.jar', '-Declipse.application=org.eclipse.jdt.ls.core.id1', '-Dosgi.bundles.defaultStartLevel=4', '-Declipse.product=org.eclipse.jdt.ls.core.product', '-Dlog.protocol=true', '-Dlog.level=ALL', '-Xms1g', '-Xmx2G', '--add-modules=ALL-SYSTEM', '--add-opens', 'java.base/java.util=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED', '-configuration', lsp_bins .. '\\jdtls\\config_win', '-data', lsp_bins .. '\\jdtls\\workspace' }
}
EOF
l-kershaw commented 2 years ago

I can't reproduce this (though I'm not using any of the same servers as you).

Can you upgrade Neovim to 0.6.1? That release had some changes to how LSP and diagnostics work, so could be causing this.

AgentCosmic commented 2 years ago

Doesn't seems to help. It could be a related to language servers cos I tried with java and it was fine. I also use cssls and html, but those depend on tsserver I think.

calvinchoy commented 2 years ago

I think I noticed a similar thing while editing some lua files. After language server loads I see lsp icons, then it disappears. When I go to the lines and enter insert mode the diagnostics show up again.