feat: Add better terminal

This commit is contained in:
Fabio Lenherr / DashieTM 2023-10-22 16:12:38 +02:00
parent 7cacef1705
commit 8633e56645
11 changed files with 107 additions and 95 deletions

View file

@ -6,7 +6,7 @@ M._keys = nil
---@return (LazyKeys|{has?:string})[]
function M.get()
local format = function()
require("lazyvim.plugins.lsp.format").format({ force = true })
require("lazyvim.util").format({ force = true })
end
if not M._keys then
---@class PluginLspKeys
@ -89,7 +89,7 @@ end
---@param method string
function M.has(buffer, method)
method = method:find("/") and method or "textDocument/" .. method
local clients = vim.lsp.get_active_clients({ bufnr = buffer })
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
if client.supports_method(method) then
return true
@ -98,45 +98,33 @@ function M.has(buffer, method)
return false
end
---@return (LazyKeys|{has?:string})[]
function M.resolve(buffer)
local Keys = require("lazy.core.handler.keys")
local keymaps = {} ---@type table<string,LazyKeys|{has?:string}>
local function add(keymap)
local keys = Keys.parse(keymap)
if keys[2] == false then
keymaps[keys.id] = nil
else
keymaps[keys.id] = keys
end
if not Keys.resolve then
return {}
end
for _, keymap in ipairs(M.get()) do
add(keymap)
end
local spec = M.get()
local opts = require("lazyvim.util").opts("nvim-lspconfig")
local clients = vim.lsp.get_active_clients({ bufnr = buffer })
local clients = require("lazyvim.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 {}
for _, keymap in ipairs(maps) do
add(keymap)
end
vim.list_extend(spec, maps)
end
return keymaps
return Keys.resolve(spec)
end
function M.on_attach(client, buffer)
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)
---@diagnostic disable-next-line: no-unknown
opts.has = nil
opts.silent = opts.silent ~= false
opts.buffer = buffer
vim.keymap.set(keys.mode or "n", keys[1], keys[2], opts)
vim.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
end
end
end