|
|
@ -55,7 +55,7 @@ M.setup = function() |
|
|
end, { desc = 'Buffer diagnostics' }) |
|
|
end, { desc = 'Buffer diagnostics' }) |
|
|
|
|
|
|
|
|
-- LSP Format |
|
|
-- LSP Format |
|
|
vim.keymap.set("n", "<leader>F", function() |
|
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>lF", function() |
|
|
vim.lsp.buf.format() |
|
|
vim.lsp.buf.format() |
|
|
end, { desc = "LSP Format" }) |
|
|
end, { desc = "LSP Format" }) |
|
|
|
|
|
|
|
|
@ -108,34 +108,6 @@ M.setup = function() |
|
|
|
|
|
|
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id) |
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id) |
|
|
|
|
|
|
|
|
if client and client:supports_method('textDocument/completion') then |
|
|
|
|
|
-- Optional: trigger autocompletion on EVERY keypress. May be slow! |
|
|
|
|
|
local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end |
|
|
|
|
|
client.server_capabilities.completionProvider.triggerCharacters = chars |
|
|
|
|
|
vim.lsp.completion.enable(true, client.id, event.buf, { |
|
|
|
|
|
autotrigger = true, |
|
|
|
|
|
-- Prevent auto-selection of first item |
|
|
|
|
|
autocomplete = false |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
-- Map Ctrl+y to select first item and accept completion |
|
|
|
|
|
vim.keymap.set('i', '<C-y>', function() |
|
|
|
|
|
if vim.fn.pumvisible() == 1 then |
|
|
|
|
|
-- If completion menu is visible, select first item if nothing selected, then accept |
|
|
|
|
|
local selected = vim.fn.complete_info({'selected'}).selected |
|
|
|
|
|
if selected == -1 then |
|
|
|
|
|
-- Nothing selected, select first item then accept |
|
|
|
|
|
return '<C-n><C-y>' |
|
|
|
|
|
else |
|
|
|
|
|
-- Something already selected, just accept |
|
|
|
|
|
return '<C-y>' |
|
|
|
|
|
end |
|
|
|
|
|
else |
|
|
|
|
|
return '<C-y>' |
|
|
|
|
|
end |
|
|
|
|
|
end, { expr = true, buffer = event.buf, desc = 'Accept completion' }) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if client and client.server_capabilities.documentHighlightProvider then |
|
|
if client and client.server_capabilities.documentHighlightProvider then |
|
|
vim.api.nvim_create_autocmd("LspDetach", { |
|
|
vim.api.nvim_create_autocmd("LspDetach", { |
|
|
group = vim.api.nvim_create_augroup("LspDetach", { clear = true }), |
|
|
group = vim.api.nvim_create_augroup("LspDetach", { clear = true }), |
|
|
@ -162,9 +134,14 @@ M.setup = function() |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- Get capabilities from blink.cmp |
|
|
|
|
|
local capabilities = require("blink.cmp").get_lsp_capabilities() |
|
|
|
|
|
|
|
|
-- Setup all servers using the new vim.lsp.config and vim.lsp.enable APIs |
|
|
-- Setup all servers using the new vim.lsp.config and vim.lsp.enable APIs |
|
|
for server_name, server in pairs(servers) do |
|
|
for server_name, server in pairs(servers) do |
|
|
vim.lsp.config(server_name, server or {}) |
|
|
|
|
|
|
|
|
local config = server or {} |
|
|
|
|
|
config.capabilities = vim.tbl_deep_extend('force', capabilities, config.capabilities or {}) |
|
|
|
|
|
vim.lsp.config(server_name, config) |
|
|
vim.lsp.enable(server_name) |
|
|
vim.lsp.enable(server_name) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|