nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.47k stars 288 forks source link

[Bug Report] Lspsaga preview_definition: nothing happened #447

Closed kohane27 closed 2 years ago

kohane27 commented 2 years ago

Hello there. Hope you're doing well.

https://user-images.githubusercontent.com/57322459/185334799-642e61b7-0c05-4d86-b4a2-e923347263f9.mp4

To reproduce:

  1. generic gd to make sure I can jump to definition
  2. go back and issue command: Lspsaga preview_definition
  3. no response

Environment

❯ nvim --version
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Operating system: Linux lspsaga commit: eec313a

Any input is much appreciated. Thank you:)

glepnir commented 2 years ago

@kohane27 provide some react code that can reproduce will be useful

glepnir commented 2 years ago

images

kohane27 commented 2 years ago

Hello @glepnir

Thank you for looking into this issue. I appreciate it.

What's strange is that other commands (Lspsaga code_action, Lspsaga hover_doc) work. Only Lspsaga preview_definition doesn't work.

  1. npx create-react-app my-typescript-app --typescript
  2. cd my-typescript-app
  3. npm start
  4. open index.js
  5. go to line 5 (import reportWebVitals from './reportWebVitals';) and put cursor to reportWebVitals
  6. :Lspsaga preview_definition

https://user-images.githubusercontent.com/57322459/185415885-07ed8b10-5920-4795-833f-7c0848489984.mp4

As you can see, the command Lspsaga preview_definition doesn't result in anything. But gd works to jump to definition.

Thank you again!

glepnir commented 2 years ago

maybe that's mean there is no response from server . test it later

glepnir commented 2 years ago

if you use typescript in react .I don't think there can have a index.js file

kohane27 commented 2 years ago

2022-08-22-18-07-49

Hello @glepnir . I tested again on a lua file and it's working! js/ts is a hit or miss however. Not sure why but I guess it's nothing to do with lspsaga. Thanks again!

glepnir commented 2 years ago

hmm you can test the lua vim.lsp.buf.definition() in that file . if this work then lspsaga definition still have some bug in that file. also you cancheck the lspsaga lsp_finder it also show definition

kohane27 commented 2 years ago

@glepnir

Thank you for getting back to me. I appreciate it.

https://user-images.githubusercontent.com/57322459/185908834-d6d06f79-b3db-4b26-baaa-0e05ffec8b3f.mp4

As you can see, lua vim.lsp.buf.definition() work but Lspsaga preview_definition doesn't. Is there any suggestion as how I could debug this?

I'm on nvim v0.7.2 so I can't use and test lsp_finder.

glepnir commented 2 years ago

lsp_finder work on 0.7 . preview definition works on my local

image

kohane27 commented 2 years ago

@glepnir Lspsaga lsp_finder works perfeclty but Lspsaga preview_definition still doesn't.

https://user-images.githubusercontent.com/57322459/185910593-d0320d35-e1c1-49ff-b161-3f248525551b.mp4

glepnir commented 2 years ago

when you press command it show a diagnostic window? this window not belong the lspsaga

kohane27 commented 2 years ago

The hover window is from the following code:

vim.cmd([[
" show line diagnostics automatically in hover window
autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, { focus = false })
]])

I commented it out and tested again:

https://user-images.githubusercontent.com/57322459/185932217-308bac64-52e5-4442-8fe4-93705c332ada.mp4

Given it works on the lua file I suspect it's js/jsx related. Thank you anyway!

glepnir commented 2 years ago

which server typescript-language-server ? I had test in 0.7 preview definition works fine.

JRS-Developer commented 2 years ago

Lspsaga preview_definition doesn't work for me on React files. I'm using neovim 0.7.2.

glepnir commented 2 years ago

I will add a message in preview definition then you can report it in there. I can't reproduce this issue on my local .so need more useful information Thanks . reopen.

kohane27 commented 2 years ago

Thanks for reopening it. I'll report more info when I can.

glepnir commented 2 years ago

I had add a notify in preview definition so you can try it and if there has messages post it in there.

kohane27 commented 2 years ago

Great news! With the log I figured it out.

It's the LSP attach order:

2022-08-24-19-20-59

Once I change the order to attach tsserver first, preview_definition is working:

 Client: tsserver (id: 2, pid: 193872, bufnr: [14, 13, 20])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx
    autostart:       true
    root directory:  /home/username/my-app
    cmd:             typescript-language-server --stdio

 Client: cssmodules_ls (id: 3, pid: 193873, bufnr: [14, 13, 20])
    filetypes:       javascript, javascriptreact, typescript, typescriptreact
    autostart:       true
    root directory:  /home/username/my-app
    cmd:             cssmodules-language-server

2022-08-24-19-25-34

Thank you again!

glepnir commented 2 years ago

Okay found problem because there has multiple servers that both support definition method . fix it later

kohane27 commented 2 years ago

Confirmed it's working even with the following lsp attached order:

 Client: cssmodules_ls (id: 3, pid: 193873, bufnr: [14, 13, 20])
    filetypes:       javascript, javascriptreact, typescript, typescriptreact
    autostart:       true
    root directory:  /home/username/my-app
    cmd:             cssmodules-language-server
 Client: tsserver (id: 2, pid: 193872, bufnr: [14, 13, 20])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx
    autostart:       true
    root directory:  /home/username/my-app
    cmd:             typescript-language-server --stdio

Thank you!