From fa5e61d6666dd3b786e149035012340d39fef247 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 29 Feb 2024 14:00:12 +0000 Subject: [PATCH] lsp: remove definitions from the nix store --- lua/opdavies/lsp/handlers.lua | 21 +++++++++++++++++++++ lua/opdavies/lsp/init.lua | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lua/opdavies/lsp/handlers.lua diff --git a/lua/opdavies/lsp/handlers.lua b/lua/opdavies/lsp/handlers.lua new file mode 100644 index 0000000..e496257 --- /dev/null +++ b/lua/opdavies/lsp/handlers.lua @@ -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 diff --git a/lua/opdavies/lsp/init.lua b/lua/opdavies/lsp/init.lua index a2bdfc8..a21511f 100644 --- a/lua/opdavies/lsp/init.lua +++ b/lua/opdavies/lsp/init.lua @@ -28,6 +28,8 @@ local custom_init = function(client) client.config.flags.allow_incremental_sync = true end +local handlers = require "opdavies.lsp.handlers" + local custom_attach = function(client) 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_next } 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 { "gT", vim.lsp.buf.type_definition }