diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index b7e5d0d..09f2153 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -183,7 +183,7 @@ local client_custom_cleanup = function(client, bufnr) end end -local on_attach = function(client, bufnr) +local on_attach = function(client_id, client, bufnr) vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') if client.config.flags then @@ -207,11 +207,18 @@ local on_attach = function(client, bufnr) group = lsp_augroup_id, buffer = bufnr, callback = function() - -- Taken from https://github.com/neovim/nvim-lspconfig/wiki/Code-Actions - local context = { diagnostics = vim.diagnostic.get(bufnr) } - local params = lsp_util.make_range_params() - params.context = context - vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config) + -- Adapted from https://github.com/neovim/nvim-lspconfig/wiki/Code-Actions + -- Copied from deprecated vim.lsp.diagnostic.get_line_diagnostics() + local diag_opts = {} --- @type vim.diagnostic.GetOpts + diag_opts.namespace = vim.lsp.diagnostic.get_namespace(client_id) + diag_opts.lnum = vim.api.nvim_win_get_cursor(0)[1] - 1 + + local lsp_diagnostics = vim.lsp.diagnostic.from(vim.diagnostic.get(bufnr, diag_opts)) + local context = { diagnostics = lsp_diagnostics } + local params = lsp_util.make_range_params() + params.context = context + + vim.lsp.buf_request(bufnr, 'textDocument/codeAction', params, function(err, result, ctx, config) if result and not vim.tbl_isempty(result) then local line = params.range.start.line code_action_update_sign(vim.b.code_action_line, line + 1, bufnr) @@ -268,7 +275,7 @@ vim.api.nvim_create_autocmd("LspAttach", { end end - on_attach(client, bufnr) + on_attach(args.data.client_id, client, bufnr) end, })