Decodetalkers / csharpls-extended-lsp.nvim

decompile for csharp_ls
MIT License
55 stars 6 forks source link

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

Open marcinjahn opened 4 months ago

marcinjahn commented 4 months ago

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 commented 2 months ago

Same issue in Neovim 10.1

Decodetalkers commented 2 months ago

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

Decodetalkers commented 1 month ago

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

Decodetalkers commented 1 month ago

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

cagechi commented 1 month ago

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

Decodetalkers commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 4 weeks ago

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 commented 4 weeks ago

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 commented 4 weeks ago

Emm,, https://github.com/neovim/neovim/issues/19237#issuecomment-1176118657 Seems it is the issue of neovim

cagechi commented 4 weeks ago

@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

https://github.com/neovim/neovim/issues/19237#issuecomment-1176118657 Seems it is the issue of neovim

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

Decodetalkers commented 4 weeks ago

@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