-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
vim.lsp.buf.code_action should get diagnostics at cursor, not line #21985
Comments
i am not sure what design of there . but i think you can do it at local . get diagnostic at cursor and pass it to context. I am not test these code . write in github :) local function get_diagnostic_at_cursor()
local cur_buf = api.nvim_get_current_buf()
local line, col = unpack(api.nvim_win_get_cursor(0))
local entrys = diagnostic.get(cur_buf, { lnum = line - 1 })
local res = {}
for _, v in pairs(entrys) do
if v.col <= col and v.end_col >= col then
table.insert(res, {
code = v.code,
message = v.message,
range = {
['start'] = {
character = v.col,
line = v.lnum,
},
['end'] = {
character = v.end_col,
line = v.end_lnum,
},
},
severity = v.severity,
source = v.source or nil,
})
end
end
return res
end
vim.lsp.buf.code_action({
context = {
diagnostics = get_diagnostic_at_cursor()
}}) |
This code work well |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I messed around and wrote a patch to incorporate this function into vim.buf.lsp and call it by default, but, in a current version, I am unable to reproduce: column based behaviour is present by default. attaching a minimal repro env dockerfile: FROM debian:bookworm
WORKDIR '/test'
RUN apt update
RUN apt install -y git ninja-build gettext libtool-bin cmake g++ pkg-config unzip curl npm nodejs gnutls-bin
RUN npm install -g typescript-language-server typescript
RUN git clone https://github.com/neovim/neovim.git
RUN bash -c "pushd neovim; make"
ADD ./nvim-mnml /root/.config/nvim
ADD ./test.ts /test/test.ts nvim-mnml/init.lua: vim.lsp.start({
name = 'tsserver',
cmd = {'typescript-language-server', '--stdio'},
root_dir = vim.fs.dirname(),
})
vim.keymap.set('n', '<Leader>a', function()vim.lsp.buf_attach_client(0,1)end)
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
vim.keymap.set('n', '<Leader>a', vim.lsp.buf.code_action, { buffer = args.buf })
end,
}) test.ts: function a(x/**cursor here**/) {
console.log(x)
}
export const b = 1 I'm less sure -why- it currently works correctly, but, it does. edit: i can naturally push the patch if that's useful, lmao, but, seems inadvisable second edit: i guess it could be a wsl thing somehow? that seems bonkers tho, and not worth fixing nvim side |
followup: the current |
Seems like it should get diagnostics not only exactly at cursor position, but also diagnostics which "cover" cursor position, if diagnostic is multiline |
Instead of using diagnostics from the entire cursor line to find available code actions, only consider diagnostics whose range overlaps the current cursor position. This will also code actions for diagnostics that span multiple lines. Fixes: neovim#21985
Instead of using diagnostics from the entire cursor line to find available code actions, only consider diagnostics whose range overlaps the current cursor position. This will also code actions for diagnostics that span multiple lines. Fixes: neovim#21985
Describe the bug
Use
typescript-language-server
andvim.lsp.buf.code_action
returns wrong code actionsI think
vim.lsp.buf.code_action
parameter diagnostics should be filtered by col.The related code is:
https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/buf.lua#L765
Steps to reproduce
Remove unused declaration for: 'x'
Expected behavior
the code action list has not
Remove unused declaration for: 'x'
Neovim version (nvim -v)
NVIM v0.9.0-dev-7ef5e363d-dirty
Vim (not Nvim) behaves the same?
no
Operating system/version
windows wsl2
Terminal name/version
window terminal 1.15
$TERM environment variable
xterm-256color
Installation
build from repo
The text was updated successfully, but these errors were encountered: