Closed rmoretto closed 11 months ago
Can you give an example code of what you are using? I didn't get an error when testing locally
According to the official documentation, this function is deprecated
Maybe we can just replace https://github.com/jinzhongjia/LspUI.nvim/blob/b2662a1be2fdc95299637aebf18bc1fa53d98bd8/lua/LspUI/code_action/init.lua#L54-L56
fn.line(".") - 1
with
vim.api.nvim_win_get_cursor(0)[1] - 1
I looked at the implementation of get_line_diagnostics,it just will use vim.api.nvim_win_get_cursor
and a function called diagnostic_vim_to_lsp
The following is my slightly modified diagnostic_vim_to_lsp
function(diagnostics)
return vim.tbl_map(function(diagnostic)
return vim.tbl_extend("keep", {
range = {
start = {
line = diagnostic.lnum,
character = diagnostic.col,
},
["end"] = {
line = diagnostic.end_lnum,
character = diagnostic.end_col,
},
},
severity = type(diagnostic.severity) == "string" and vim.diagnostic.severity[diagnostic.severity]
or diagnostic.severity,
message = diagnostic.message,
source = diagnostic.source,
code = diagnostic.code,
}, diagnostic.user_data and (diagnostic.user_data.lsp or {}) or {})
end, diagnostics)
end
Use this function to wrap vim.api.nvim_win_get_cursor(0)[1] - 1, I test it ok
The code I was using is a simple main function, like:
fn main() {
io::Error;
}
and I was running the code_action
with the cursor on top of the io::Error
.
Maybe we can just replace
fn.line(".") - 1
withvim.api.nvim_win_get_cursor(0)[1] - 1
Just implemented the change you proposed and the code_action
works correctly and updated the PR.
The code I was using is a simple main function, like:
fn main() { io::Error; }
and I was running the
code_action
with the cursor on top of theio::Error
.Maybe we can just replace https://github.com/jinzhongjia/LspUI.nvim/blob/b2662a1be2fdc95299637aebf18bc1fa53d98bd8/lua/LspUI/code_action/init.lua#L54-L56
fn.line(".") - 1
withvim.api.nvim_win_get_cursor(0)[1] - 1
Just implemented the change you proposed and the
code_action
works correctly and updated the PR.
Note that I re-edited this comment
I suggest you add a function called M.diagnostic_vim_to_lsp
to code_action/util.lua
, and use it like this:
local diagnostics = util.diagnostic_vim_to_lsp(vim.diagnostic.get(current_buffer, {
lnum = fn.line(".") - 1,
}))
Interestingly, I didn't get the error you meet, it's just that there is no option for lsp in code_action,your neovim version is nigthly?
If you test code_action and everything is normal, then I can merge pr Please pay attention to clearing the print information for your debugging
Note that I re-edited this comment
Sorry didn't catch the comment 😅
I suggest you add a function called
M.diagnostic_vim_to_lsp
tocode_action/util.lua
, and use it like this:
Created the new function as you suggested, and updated the PR! It worked for me.
Interestingly, I didn't get the error you meet, it's just that there is no option for lsp in code_action,your neovim version is nigthly?
I'm using the 0.9.1
version:
❯ nvim --version
NVIM v0.9.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/home/rodrigo/programations/misc/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/build/src/nvim/auto -I/home/rodrigo/programations/misc/neovim/build/include -I/home/rodrigo/programations/misc/neovim/build/cmake.config -I/home/rodrigo/programations/misc/neovim/src -I/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include -I/home/rodrigo/programations/misc/neovim/.deps/usr/include
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/share/nvim"
Run :checkhealth for more info
Everything is ok now, thanks for your PR
When using the
code_action
function with Rust LSP I got the following error message:Looking at the code I saw that the implementation of the logic to get the diagnostic from the current line was not align with the lsputil code, which use:
Changing the diagnostic fetcher logic to use the
vim.lsp.diagnostic.get_line_diagnostics(bufnr)
function fixes the problem.This PR simply changes the way that the
code_action
get the line diagnostic.