mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 23:07:35 +00:00
Remove some more v0.7 hacks
This commit is contained in:
parent
65f434fcb8
commit
35561b6aa5
@ -61,9 +61,12 @@ return {
|
|||||||
-- Make it easier to discover some of my keymaps
|
-- Make it easier to discover some of my keymaps
|
||||||
{
|
{
|
||||||
"https://github.com/folke/which-key.nvim",
|
"https://github.com/folke/which-key.nvim",
|
||||||
config = function()
|
opts = {
|
||||||
require("plugins.whichkey").configure()
|
triggers_blacklist = {
|
||||||
end,
|
i = { "j", "k", "`" },
|
||||||
|
v = { "j", "k" },
|
||||||
|
},
|
||||||
|
},
|
||||||
version = "1.x.x",
|
version = "1.x.x",
|
||||||
},
|
},
|
||||||
-- Better commenting
|
-- Better commenting
|
||||||
|
@ -36,55 +36,16 @@ function M.config_lsp_ui()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_server_capabilities(client)
|
|
||||||
-- HACK: Support for <0.8
|
|
||||||
if client.server_capabilities ~= nil then
|
|
||||||
return client.server_capabilities
|
|
||||||
end
|
|
||||||
|
|
||||||
local capabilities = client.resolved_capabilities
|
|
||||||
if capabilities.documentSymbolProvider == nil then
|
|
||||||
capabilities.documentSymbolProvider = capabilities.goto_definition
|
|
||||||
end
|
|
||||||
if capabilities.documentFormattingProvider == nil then
|
|
||||||
capabilities.documentFormattingProvider = capabilities.document_formatting
|
|
||||||
end
|
|
||||||
if capabilities.documentRangeFormattingProvider == nil then
|
|
||||||
capabilities.documentRangeFormattingProvider = capabilities.document_range_formatting
|
|
||||||
end
|
|
||||||
if capabilities.documentHighlightProvider == nil then
|
|
||||||
capabilities.documentHighlightProvider = capabilities.document_highlight
|
|
||||||
end
|
|
||||||
if capabilities.workspaceSymbolProvider == nil then
|
|
||||||
-- Not sure what the legacy version of this is
|
|
||||||
capabilities.workspaceSymbolProvider = capabilities.goto_definition
|
|
||||||
end
|
|
||||||
|
|
||||||
return capabilities
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_default_attach(override_capabilities)
|
local function get_default_attach(override_capabilities)
|
||||||
return function(client, bufnr)
|
return function(client, bufnr)
|
||||||
-- Allow overriding capabilities to avoid duplicate lsps with capabilities
|
-- Allow overriding capabilities to avoid duplicate lsps with capabilities
|
||||||
|
|
||||||
-- Using custom method to extract for <0.8 support
|
-- Using custom method to extract for <0.8 support
|
||||||
local server_capabilities = get_server_capabilities(client)
|
local server_capabilities = client.server_capabilities
|
||||||
if override_capabilities ~= nil then
|
if override_capabilities ~= nil then
|
||||||
server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {})
|
server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set built in features to use lsp functions (automatic in nvim-0.8)
|
|
||||||
-- HACK: Support for <0.8
|
|
||||||
if vim.fn.has("nvim-0.8") ~= 1 then
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
|
||||||
if server_capabilities.documentSymbolProvider then
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
|
|
||||||
end
|
|
||||||
if server_capabilities.documentFormattingProvider then
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr()")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Mappings
|
-- Mappings
|
||||||
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr, group_desc = "LSP" })
|
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr, group_desc = "LSP" })
|
||||||
lsp_keymap("h", vim.lsp.buf.hover, { desc = "Display hover" })
|
lsp_keymap("h", vim.lsp.buf.hover, { desc = "Display hover" })
|
||||||
@ -137,37 +98,21 @@ local function get_default_attach(override_capabilities)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Set some keybinds conditional on server capabilities
|
-- Set some keybinds conditional on server capabilities
|
||||||
if vim.fn.has("nvim-0.8") == 1 then
|
lsp_keymap("f", function()
|
||||||
lsp_keymap("f", function()
|
vim.lsp.buf.format({ async = true })
|
||||||
vim.lsp.buf.format({ async = true })
|
end, { desc = "Format code" })
|
||||||
end, { desc = "Format code" })
|
lsp_keymap("f", function()
|
||||||
lsp_keymap("f", function()
|
vim.lsp.buf.format({ async = true })
|
||||||
vim.lsp.buf.format({ async = true })
|
end, { mode = "v", desc = "Format selected code" })
|
||||||
end, { mode = "v", desc = "Format selected code" })
|
if server_capabilities.documentFormattingProvider then
|
||||||
if server_capabilities.documentFormattingProvider then
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
||||||
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
callback = function()
|
||||||
callback = function()
|
vim.lsp.buf.format({ async = false, timeout_ms = 1000 })
|
||||||
vim.lsp.buf.format({ async = false, timeout_ms = 1000 })
|
end,
|
||||||
end,
|
group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
|
||||||
group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
|
desc = "Auto format code on save",
|
||||||
desc = "Auto format code on save",
|
})
|
||||||
})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- HACK: Support for <0.8 with older formatting
|
|
||||||
lsp_keymap("f", vim.lsp.buf.formatting, { desc = "Format code" })
|
|
||||||
lsp_keymap("f", vim.lsp.buf.range_formatting, { mode = "v", desc = "Format selected code" })
|
|
||||||
if server_capabilities.documentFormattingProvider then
|
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
|
||||||
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.formatting_sync(nil, 1000)
|
|
||||||
end,
|
|
||||||
group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
|
|
||||||
desc = "Auto format code on save",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set autocommands conditional on server_capabilities
|
-- Set autocommands conditional on server_capabilities
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
function M.configure()
|
|
||||||
require("which-key").setup({
|
|
||||||
triggers_blacklist = {
|
|
||||||
i = { "j", "k", "`" },
|
|
||||||
v = { "j", "k" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
Loading…
Reference in New Issue
Block a user