Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when opening a file from lsp_definition with empty first line #3382

Open
pnx opened this issue Dec 8, 2024 · 0 comments
Open

Error when opening a file from lsp_definition with empty first line #3382

pnx opened this issue Dec 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@pnx
Copy link

pnx commented Dec 8, 2024

Description

You will get an error if you issue Telescope lsp_definition that resolves to the beginning of a file where the file has a empty first line.

Neovim version

NVIM v0.10.2
Build type: RelWithDebInfo
LuaJIT 2.1.1720049189

Operating system and version

Linux 6.11.8-200.fc40.x86_64

Telescope version / branch / rev

Commit 2eca9ba

checkhealth telescope

telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- WARNING nvim-treesitter not found. (Required for `:Telescope treesitter`.)

Checking external dependencies ~
- OK rg: found ripgrep 14.1.1
- OK fd: found fd 10.1.0

===== Installed extensions ===== ~

Steps to reproduce

  1. Create two files in the same directory

    file.lua

    require("hello")

    hello.lua (make sure the first line is empty, this is important)

    print("hello world")
  2. nvim -nu minimal.lua file.lua

  3. Execute :Telescope lsp_definition while the cursor
    is over the "hello" string in the require("hello") call.

Expected behavior

The file is opened without any errors

Actual behavior

You will get this error

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vi
m/lsp/util.lua:1142: Column value outside range
stack traceback:
[C]: in function 'nvim_win_set_cursor'
/usr/share/nvim/runtime/lua/vim/lsp/util.lua:1142: in function 's
how_document'
...o/plugins/telescope.nvim/lua/telescope/builtin/__lsp.lua:266:
in function 'handler'
/usr/share/nvim/runtime/lua/vim/lsp.lua:936: in function 'handler
'
/usr/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function '
'
vim/_editor.lua: in function <vim/_editor.lua:0>

if you remove the first empty line in hello.lua the error is gone.

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
    vim.fn.system {
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    {
        "nvim-telescope/telescope.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
        config = function()
            -- Start an LSP Server, lua is used here but the bug can
            -- can be reproduced with any LSP (that supports definition ofc)
            vim.api.nvim_create_autocmd("FileType", {
                pattern = {"lua"},
                callback = function ()
                    vim.lsp.start({
                        name = "luals",
                        cmd = { '/path/to/lua-language-server' },
                        root_dir = vim.fn.getcwd(),
                    })
                end
            })
            --
            require("telescope").setup {}
        end,
    },
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})
@pnx pnx added the bug Something isn't working label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant