lsp: remove definitions from the nix store

This commit is contained in:
Oliver Davies 2024-02-29 14:00:12 +00:00
parent 853f74c147
commit fa5e61d666
2 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,21 @@
local M = {}
M.definition = function()
local params = vim.lsp.util.make_position_params()
vim.lsp.buf_request(0, "textDocument/definition", params, function(err, result, ctx, config)
local new_result = vim.tbl_filter(function(v)
-- Remove any referneces to the nix store via the .direnv directory.
return not string.find(v.targetUri, ".direnv")
end, result)
if #new_result > 0 then
result = new_result
end
vim.lsp.handlers["textDocument/definition"](err, result, ctx, config)
vim.cmd [[normal! zz]]
end)
end
return M

View file

@ -28,6 +28,8 @@ local custom_init = function(client)
client.config.flags.allow_incremental_sync = true client.config.flags.allow_incremental_sync = true
end end
local handlers = require "opdavies.lsp.handlers"
local custom_attach = function(client) local custom_attach = function(client)
local filetype = vim.api.nvim_buf_get_option(0, "filetype") local filetype = vim.api.nvim_buf_get_option(0, "filetype")
@ -41,7 +43,7 @@ local custom_attach = function(client)
buf_nnoremap { "[d", vim.diagnostic.goto_prev } buf_nnoremap { "[d", vim.diagnostic.goto_prev }
buf_nnoremap { "]d", vim.diagnostic.goto_next } buf_nnoremap { "]d", vim.diagnostic.goto_next }
buf_nnoremap { "gD", vim.lsp.buf.declaration } buf_nnoremap { "gD", vim.lsp.buf.declaration }
buf_nnoremap { "gd", vim.lsp.buf.definition } buf_nnoremap { "gd", handlers.definition }
buf_nnoremap { "gi", vim.lsp.buf.implementation } buf_nnoremap { "gi", vim.lsp.buf.implementation }
buf_nnoremap { "gT", vim.lsp.buf.type_definition } buf_nnoremap { "gT", vim.lsp.buf.type_definition }