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

"index out of range" when trying to go to definition of external libraries #13

Open
marcinjahn opened this issue Jun 25, 2024 · 20 comments

Comments

@marcinjahn
Copy link

I'm using LazyVim. I installed the plugin like this:

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      omnisharp = { enabled = false },
      chsarp_ls = {
        handlers = {
          ["textDocument/definition"] = function(...)
            return require("csharpls_extended").handler(...)
          end,
          ["textDocument/typeDefinition"] = function(...)
            return require("csharpls_extended").handler(...)
          end,
        },
      },
    },
  },
}

The plugin works in general, however, when I try to go to definition of any built-in .NET type (like IReadOnlyCollection) or just any type from nugets, I get an error:

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1914: index out of range
stack traceback:
[C]: in function '_str_byteindex_enc'
/usr/share/nvim/runtime/lua/vim/lsp/util.lua:1914: in function 'locations_to_items'
...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:197: in function 'handler'
/usr/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>

Any idea what might be the reason?
Is there any minimal example of neovim config with this plugin enabled? The README instructions are a bit unclear, and they refer (by mistake?) to omnisharp.

@mbwilding
Copy link

mbwilding commented Aug 20, 2024

Same issue in Neovim 10.1

@Decodetalkers
Copy link
Owner

Ok. I will try to fix it this time..

@Decodetalkers
Copy link
Owner

Emm. seems you jump from telescope.. now I have not made the plugin for telecope yet..

@Decodetalkers
Copy link
Owner

I have add support for telescope now, but a very basic one, I think I have solved it

@cagechi
Copy link

cagechi commented Oct 4, 2024

Same issue in Neovim 10.1 & csharpls-extended-lsp.nvim (commit c367733)

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 4, 2024

Same issue in Neovim 10.1 & csharpls-extended-lsp.nvim (commit c367733)

I mean with the telescope extension command . I have add an telescope extension for this project, try use that to go to definition

@cagechi
Copy link

cagechi commented Oct 4, 2024

I tried telescope but I get the same error.
The function I tried is require("telescope.builtin").lsp_definitions()
Also, when I do vim.lsp.buf.definition(), it jumps to the definition after the error occurs, but the file to jump to is displayed in the Buffer of the original file.

@Decodetalkers
Copy link
Owner

I tried telescope but I get the same error.
The function I tried is require("telescope.builtin").lsp_definitions()
Also, when I do vim.lsp.buf.definition(), it jumps to the definition after the error occurs, but the file to jump to is displayed in the Buffer of the original file.

No, the command is
Telescope csharpls_definition

@cagechi
Copy link

cagechi commented Oct 4, 2024

I am sorry.
I tried Telescope csharpls_definition, But the results were the same as before

, it jumps to the definition after the error occurs, but the file to jump to is displayed in the Buffer of the original file.

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 4, 2024

I am sorry. I tried Telescope csharpls_definition, But the results were the same as before

, it jumps to the definition after the error occurs, but the file to jump to is displayed in the Buffer of the original file.

Emm, if you use the plugin of mime, the error won't throw from the _lsp.lua of telescope I think. Can you show me the picture?

@Decodetalkers
Copy link
Owner

I tried telescope but I get the same error. The function I tried is require("telescope.builtin").lsp_definitions() Also, when I do vim.lsp.buf.definition(), it jumps to the definition after the error occurs, but the file to jump to is displayed in the Buffer of the original file.

I see, what kind of error? and can you provide me some snippets?

@cagechi
Copy link

cagechi commented Oct 4, 2024

Emm, if you use the plugin of mime, the error won't throw from the _lsp.lua of telescope I think. Can you show me the picture?

1
2

@Decodetalkers
Copy link
Owner

Emm, if you use the plugin of mime, the error won't throw from the _lsp.lua of telescope I think. Can you show me the picture?

1 2

I want this snippet.

@cagechi
Copy link

cagechi commented Oct 4, 2024

I can't show you the problematic code because it is for work. So I tried to create a minimal reproduction code, but it did not work.
(It works fine with the minimal code.)

For reference, here is a screenshot of the debugger when the problem occurred

1

The lnum and col of the fetched variable are different from the actual code definition.
By the way, what is the encoding of offset_encoding?
The encoding of the source code is utf-8 (without BOM)

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 4, 2024

I can't show you the problematic code because it is for work. So I tried to create a minimal reproduction code, but it did not work. (It works fine with the minimal code.)

For reference, here is a screenshot of the debugger when the problem occurred

1

The lnum and col of the fetched variable are different from the actual code definition. By the way, what is the encoding of offset_encoding? The encoding of the source code is utf-8 (without BOM)

https://github.com/Decodetalkers/csharpls-extended-lsp.nvim/blob/master/lua/csharpls_extended.lua#L156-L160

the encoding is from neovim.. I think it error because that file is a windows file? which contains \t\n? Emm.. can you try ignore the encoding from neovim, always utf8, will it work for you? I think maybe csharp_ls always provide the buff with utf-8.. I should not use the encoding from current buffer. but this code is copy from omnisharp_extended.nvim.. I do not quite understand the logic

update: utf16 works fine when jump to System.Console.. Emm

@cagechi
Copy link

cagechi commented Oct 5, 2024

file is a windows file? which contains \t\n?

Yes, this file is windows file. EOL code is \r\n.
However, the smallest code tested is also a windows file, but it jumped correctly.
Here is a screenshot of the Debugger at that time

1

always utf8, will it work for you?

The result is the same as before.

but this code is copy from omnisharp_extended.nvim

I tried omnisharp & omnisharp_extended.nvim and got an error.
However, the error content and the location of the error are different
The following is for your reference
2
3

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 5, 2024

file is a windows file? which contains \t\n?

Yes, this file is windows file. EOL code is \r\n. However, the smallest code tested is also a windows file, but it jumped correctly. Here is a screenshot of the Debugger at that time

1

always utf8, will it work for you?

The result is the same as before.

but this code is copy from omnisharp_extended.nvim

I tried omnisharp & omnisharp_extended.nvim and got an error. However, the error content and the location of the error are different The following is for your reference 2 3

Can you jump to the location_to_items, and get the data when it panic? I have read the code in neovim. seems the lnum and col is recaculated by neovim. and the problem is this line

      local col = M._str_byteindex_enc(line, pos.character, offset_encoding)

image

I need know then there is error, the value of line and pos.caculator.

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 5, 2024

Emm,, neovim/neovim#19237 (comment) Seems it is the issue of neovim

@cagechi
Copy link

cagechi commented Oct 6, 2024

@Decodetalkers Thank you for your cooperation.

Can you jump to the location_to_items, and get the data when it panic? I have read the code in neovim. seems the lnum and col is recaculated by neovim. and the problem is this line

The following screenshot shows the debugger when jumping to the same method

when an error occurs:
1

Normal (no use decompiler, definition jumps in the library source):
2-1

neovim/neovim#19237 (comment) Seems it is the issue of neovim

If so, does that mean there is a problem with the decompiled code?

@Decodetalkers
Copy link
Owner

Decodetalkers commented Oct 6, 2024

@Decodetalkers Thank you for your cooperation.

Can you jump to the location_to_items, and get the data when it panic? I have read the code in neovim. seems the lnum and col is recaculated by neovim. and the problem is this line

The following screenshot shows the debugger when jumping to the same method

when an error occurs: 1

Normal (no use decompiler, definition jumps in the library source): 2-1

neovim/neovim#19237 (comment) Seems it is the issue of neovim

If so, does that mean there is a problem with the decompiled code?

seems that get_lines get "", and it should panic during getting line[row]... Why there is no data in line?

maybe problem is this line:

https://github.com/Decodetalkers/csharpls-extended-lsp.nvim/blob/master/lua/csharpls_extended.lua#L53

here I should get the data and write it into the buf, I think maybe the buf is not created? or the data is empty? can step to this function and see it for me? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants