Skip to content

Commit

Permalink
fix: fix lsp on_attach error
Browse files Browse the repository at this point in the history
  • Loading branch information
BBboy01 committed Nov 21, 2023
1 parent 0dfb79e commit 982a309
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 26 deletions.
21 changes: 11 additions & 10 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "1f4ad8bb72bdeb60975e98652636b991a9b7475d" },
"LuaSnip": { "branch": "master", "commit": "cab667e2674881001a86a7478fff7dc7791c63f5" },
"bufferline.nvim": { "branch": "main", "commit": "9e8d2f695dd50ab6821a6a53a840c32d2067a78a" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
Expand All @@ -13,25 +12,27 @@
"gitsigns.nvim": { "branch": "main", "commit": "0ccd5fb2316b3f8d8b2f775bc31cae7bc6a77a55" },
"indentmini.nvim": { "branch": "main", "commit": "a58129ae424fd6d8e0e2e7f6ce06c0443101e370" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"lspsaga.nvim": { "branch": "main", "commit": "424503af246033f177a11c9959424bbb3640f077" },
"lspsaga.nvim": { "branch": "main", "commit": "496ea37208fdd670751f3b1b04b5d2cfdb12af91" },
"lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" },
"mini.ai": { "branch": "main", "commit": "4a2e387b121352dfb478f440c9a5313a9d97006c" },
"mini.comment": { "branch": "main", "commit": "3d9c8009615857e982f09bc5357fc95f2a2175f3" },
"mini.pairs": { "branch": "main", "commit": "71f117fd57f930da6ef4126b24f594dd398bac26" },
"mini.surround": { "branch": "main", "commit": "af8129efcabe95fc08a233e9f91569829bed031f" },
"neodev.nvim": { "branch": "main", "commit": "627b5b543f4df551fcddb99c17a8e260c453400d" },
"neogen": { "branch": "main", "commit": "70127baaff25611deaf1a29d801fc054ad9d2dc1" },
"none-ls.nvim": { "branch": "main", "commit": "fa9be1679db7bf57d44128a018db43da5488a07f" },
"nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" },
"nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" },
"nvim-lspconfig": { "branch": "master", "commit": "6516abf5ac7d017480c8c8e08c0d24066bcb8d43" },
"nvim-surround": { "branch": "main", "commit": "18016d6af52edc9f1c794dcf6665a26a2962d2ee" },
"nvim-lspconfig": { "branch": "master", "commit": "7fedba8b1f8d0080c775851c429b88fd2ed4c6f5" },
"nvim-tree.lua": { "branch": "master", "commit": "086bf310bd19a7103ee7d761eb59f89f3dd23e21" },
"nvim-treesitter": { "branch": "master", "commit": "d87629647614b779fb2aad8f0042fe2864253ea6" },
"nvim-treesitter": { "branch": "master", "commit": "1610b1aafb9b7b3a7b54c853ed45c6cb1a3d0df2" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "dbcd9388e3b119a87c785e10a00d62876077d23d" },
"nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "ead792ccdace6a9d64a8119909af243ed0105465" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "bdd2a3293340465a516b126d10894f6d5cb5213c" },
"nvim-ts-rainbow": { "branch": "master", "commit": "ef95c15a935f97c65a80e48e12fe72d49aacf9b9" },
"nvim-web-devicons": { "branch": "master", "commit": "d3cf19ef81d364af2af527d6a23ad201330ccfad" },
"nvim-web-devicons": { "branch": "master", "commit": "cdbcca210cf3655aa9b31ebf2422763ecd85ee5c" },
"playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" },
"plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" },
"schemastore.nvim": { "branch": "main", "commit": "9fb873af43568464f9a1936fc334dfa3d7a59418" },
"schemastore.nvim": { "branch": "main", "commit": "6316dc88db89d97d190f24547adddd13569fb746" },
"solarized-osaka.nvim": { "branch": "main", "commit": "aeaefec4465deb3ec36f094578e880726c8f8e24" },
"telescope-file-browser.nvim": { "branch": "master", "commit": "f41675fddb1ea9003187d07ecc627a8bf8292633" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
Expand Down
4 changes: 2 additions & 2 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ vim.api.nvim_create_autocmd('BufReadPost', {
callback = function(event)
local exclude = { 'gitcommit' }
local buf = event.buf
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].lazyvim_last_loc then
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].last_loc then
return
end
vim.b[buf].lazyvim_last_loc = true
vim.b[buf].last_loc = true
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
Expand Down
1 change: 0 additions & 1 deletion lua/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ return {
capabilities = vim.deepcopy(capabilities),
}, servers[server] or {})

vim.print(opts)
if opts.setup[server] then
if opts.setup[server](server, server_opts) then
return
Expand Down
64 changes: 64 additions & 0 deletions lua/plugins/lsp/keymaps.lua
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
24 changes: 12 additions & 12 deletions lua/plugins/lspsaga.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ return {
end,
config = function(_, opts)
require('lspsaga').setup(opts)
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<leader>dc', '<Cmd>Lspsaga show_line_diagnostics<cr>', opts)
vim.keymap.set('n', '<leader>dp', '<Cmd>Lspsaga diagnostic_jump_next<cr>', opts)
vim.keymap.set('n', '<leader>dn', '<Cmd>Lspsaga diagnostic_jump_prev<cr>', opts)
vim.keymap.set('n', '<leader>o', '<Cmd>Lspsaga outline<cr>', opts)
local opt = { noremap = true, silent = true }
vim.keymap.set('n', '<leader>dc', '<Cmd>Lspsaga show_line_diagnostics<cr>', opt)
vim.keymap.set('n', '<leader>dp', '<Cmd>Lspsaga diagnostic_jump_next<cr>', opt)
vim.keymap.set('n', '<leader>dn', '<Cmd>Lspsaga diagnostic_jump_prev<cr>', opt)
vim.keymap.set('n', '<leader>o', '<Cmd>Lspsaga outline<cr>', opt)
vim.keymap.set('n', '<Leader>ci', '<cmd>Lspsaga incoming_calls<CR>')
vim.keymap.set('n', '<Leader>co', '<cmd>Lspsaga outgoing_calls<CR>')
vim.keymap.set({ 'n', 't', 'i' }, '<C-j>', '<cmd>Lspsaga term_toggle<CR>')
vim.keymap.set('n', 'gd', '<Cmd>Lspsaga goto_definition<cr>', opts)
vim.keymap.set('n', 'gt', '<Cmd>Lspsaga goto_type_definition<cr>', opts)
vim.keymap.set('n', 'gh', '<Cmd>Lspsaga hover_doc<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>Lspsaga finder<CR>', opts)
vim.keymap.set('n', 'gp', '<Cmd>Lspsaga peek_definition<cr>', opts)
vim.keymap.set('n', 'ga', '<Cmd>Lspsaga code_action<cr>', opts)
vim.keymap.set('n', '<Leader>n', '<Cmd>Lspsaga rename<cr>', opts)
vim.keymap.set('n', 'gd', '<Cmd>Lspsaga goto_definition<cr>', opt)
vim.keymap.set('n', 'gt', '<Cmd>Lspsaga goto_type_definition<cr>', opt)
vim.keymap.set('n', 'gh', '<Cmd>Lspsaga hover_doc<cr>', opt)
vim.keymap.set('n', 'gr', '<cmd>Lspsaga finder<CR>', opt)
vim.keymap.set('n', 'gp', '<Cmd>Lspsaga peek_definition<cr>', opt)
vim.keymap.set('n', 'ga', '<Cmd>Lspsaga code_action<cr>', opt)
vim.keymap.set('n', '<Leader>n', '<Cmd>Lspsaga rename<cr>', opt)
end,
}
14 changes: 13 additions & 1 deletion lua/util/init.lua
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

0 comments on commit 982a309

Please sign in to comment.