nvim-telescope / telescope.nvim

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

The `show_line` option is ignored in lsp_document_symbols #1409

Closed yorickpeterse closed 2 years ago

yorickpeterse commented 2 years ago

Description

The show_line option is used to disable showing the line of an LSP symbol. According to the documentation, this option is disabled by default. However, in reality it seems this option is enabled. For example:

Screenshot from 2021-11-02 22-32-50

One part of the problem seems to be the code found here:

https://github.com/nvim-telescope/telescope.nvim/blob/9cad3a4a5d0e36b07b25c4be1db1c1306fcec945/lua/telescope/make_entry.lua#L356-L367

It seems that when ignore_filename is set to true (which is the default), the show_line option is ignored and the line is always displayed.

Another problem appears to this:

https://github.com/nvim-telescope/telescope.nvim/blob/f31ef362931907bbdd3b46cb880b34493c2d1882/lua/telescope/builtin/lsp.lua#L134

If ignore_filename is set to false, the expression evaluates to opts.ignore_filename = false or true, resulting in opts.ignore_filename = true. Unless I'm mistaken this basically makes the option useless, as it's always set to true.

Neovim version

NVIM v0.6.0-dev+547-gfa97d3485 Build type: RelWithDebInfo LuaJIT 2.0.5

Operating system and version

Arch Linux, kernel 5.14

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

Configure Telescope along the lines of the following:

require('telescope').setup({
  pickers = { lsp_document_symbols = { show_line = false } }
})

Next, open a document that has a LSP client attached, and run Telescope lsp_document_symbols.

Expected behavior

The line the symbol is defined on isn't displayed.

Actual behavior

The line is always displayed

Minimal config

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" },
                },
            },
            { "neovim/nvim-lspconfig" },
        },
        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({
        pickers = {
            lsp_document_symbols = {
                show_line = false,
            },
        },
    })

    require("telescope").load_extension("fzf")

    -- The actual language server doesn't really matter, as long as it supports
    -- the `document_symbol` capability.
    require("lspconfig").rust_analyzer.setup({})
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()]])
yorickpeterse commented 2 years ago

Actually it seems I'm slightly mistaken about the nature of this option. The documentation says the following:

if true, shows the content of the
line the tag is found on (default:
false)

However, based on the code it seems that setting this option to true adds the line and column number, similar to the treesitter option.

So if the option is supposed to show the line, it's currently not implemented correctly. If the option is supposed to show the column/line number, the documentation is incorrect.

yorickpeterse commented 2 years ago

Looking at the other pickers, it seems the treesitter picker is the only one that inserts the line/column number when show_line is enabled. Other pickers, such as builtin.tags show the actual line contents.

I'm guessing either the treesitter picker or the lsp_document_symbols picker was copied from the other, but not adjusted properly to meet the other pickers.

Conni2461 commented 2 years ago

1410 was merged in current dev branch.

More info here #1938