-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,66 @@ | ||
local M = {} | ||
|
||
---@type LazyKeysLspSpec[]|nil | ||
M._keys = nil | ||
|
||
---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string} | ||
---@alias LazyKeysLsp LazyKeys|{has?:string} | ||
|
||
---@return LazyKeysLspSpec[] | ||
function M.get() | ||
if M._keys then | ||
return M._keys | ||
end | ||
-- stylua: ignore | ||
M._keys = { | ||
{ "gD", vim.lsp.buf.declaration, desc = "Goto Declaration" }, | ||
{ "gi", function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, desc = "Goto Implementation" }, | ||
{ "gK", vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" }, | ||
} | ||
return M._keys | ||
end | ||
|
||
---@param method string | ||
function M.has(buffer, method) | ||
method = method:find('/') and method or 'textDocument/' .. method | ||
local clients = require('util.lsp').get_clients({ bufnr = buffer }) | ||
for _, client in ipairs(clients) do | ||
if client.supports_method(method) then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
---@return (LazyKeys|{has?:string})[] | ||
function M.resolve(buffer) | ||
local Keys = require('lazy.core.handler.keys') | ||
if not Keys.resolve then | ||
return {} | ||
end | ||
local spec = M.get() | ||
local opts = require('util').opts('nvim-lspconfig') | ||
local clients = require('util.lsp').get_clients({ bufnr = buffer }) | ||
for _, client in ipairs(clients) do | ||
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {} | ||
vim.list_extend(spec, maps) | ||
end | ||
return Keys.resolve(spec) | ||
end | ||
|
||
function M.on_attach(_, buffer) | ||
local Keys = require('lazy.core.handler.keys') | ||
local keymaps = M.resolve(buffer) | ||
|
||
for _, keys in pairs(keymaps) do | ||
if not keys.has or M.has(buffer, keys.has) then | ||
local opts = Keys.opts(keys) | ||
opts.has = nil | ||
opts.silent = opts.silent ~= false | ||
opts.buffer = buffer | ||
vim.keymap.set(keys.mode or 'n', keys.lhs, keys.rhs, opts) | ||
end | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
return {} | ||
local M = {} | ||
|
||
---@param name string | ||
function M.opts(name) | ||
local plugin = require('lazy.core.config').plugins[name] | ||
if not plugin then | ||
return {} | ||
end | ||
local Plugin = require('lazy.core.plugin') | ||
return Plugin.values(plugin, 'opts', false) | ||
end | ||
|
||
return M |