mirror of
https://github.com/kogakure/dotfiles.git
synced 2026-02-03 20:25:30 +00:00
fix(nvim): migrate formatting settings to Neovim 0.8 API
This commit is contained in:
@@ -116,14 +116,14 @@ local mappings = {
|
||||
},
|
||||
L = {
|
||||
name = "LSP",
|
||||
c = { "<CMD>vim.lsp.buf.code_action()<CR>", "Code Action" },
|
||||
f = { "<CMD>vim.lsp.buf.formatting()<CR>", "Formatting" },
|
||||
l = { "<CMD>vim.diagnostic.setloclist<CR>", "Set Loclist" },
|
||||
r = { "<CMD>vim.lsp.buf.rename()<CR>", "Rename" },
|
||||
t = { "<CMD>vim.lsp.buf.type_definition()<CR>", "Type Definition" },
|
||||
c = { "<CMD>lua vim.lsp.buf.code_action()<CR>", "Code Action" },
|
||||
f = { "<CMD>lua vim.lsp.buf.format()<CR>", "Formatting" },
|
||||
l = { "<CMD>lua vim.diagnostic.setloclist<CR>", "Set Loclist" },
|
||||
r = { "<CMD>lua vim.lsp.buf.rename()<CR>", "Rename" },
|
||||
t = { "<CMD>lua vim.lsp.buf.type_definition()<CR>", "Type Definition" },
|
||||
w = { "<CMD>function() print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", "List Workspace Folder" },
|
||||
a = { "<CMD>vim.lsp.buf.add_workspace_folder()<CR>", "Add Workspace" },
|
||||
v = { "<CMD>vim.lsp.buf.remove_workspace_folder()<CR>", "Remove Workspace" },
|
||||
a = { "<CMD>lua vim.lsp.buf.add_workspace_folder()<CR>", "Add Workspace" },
|
||||
v = { "<CMD>lua vim.lsp.buf.remove_workspace_folder()<CR>", "Remove Workspace" },
|
||||
},
|
||||
P = {
|
||||
name = "Packer",
|
||||
|
||||
@@ -109,6 +109,6 @@ vim.cmd([[
|
||||
|
||||
augroup _lsp
|
||||
autocmd!
|
||||
autocmd BufWritePre * lua vim.lsp.buf.formatting()
|
||||
autocmd BufWritePre * lua vim.lsp.buf.format()
|
||||
augroup end
|
||||
]])
|
||||
|
||||
@@ -147,4 +147,4 @@ keymap("o", "al", ":<c-u>normal! $v0<CR>", opts)
|
||||
keymap("x", "al", ":<c-u>normal! $v0<CR>", opts)
|
||||
|
||||
-- LSP formatting
|
||||
keymap("n", "<leader>o", "<cmd>lua vim.lsp.buf.formatting_sync()<CR>", opts)
|
||||
keymap("n", "<leader>o", "<cmd>lua vim.lsp.buf.format()<CR>", opts)
|
||||
|
||||
@@ -41,19 +41,23 @@ M.setup = function()
|
||||
})
|
||||
end
|
||||
|
||||
local function lsp_highlight_document(client)
|
||||
local function lsp_highlight_document(client, bufnr)
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]],
|
||||
false
|
||||
)
|
||||
if client.server_capabilities.documentHighlightProvider then
|
||||
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||
vim.api.nvim_clear_autocmds({ buffer = bufnr, group = "lsp_document_highlight" })
|
||||
vim.api.nvim_create_autocmd("CursorHold", {
|
||||
callback = vim.lsp.buf.document_highlight,
|
||||
buffer = bufnr,
|
||||
group = "lsp_document_highlight",
|
||||
desc = "Document Highlight",
|
||||
})
|
||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||
callback = vim.lsp.buf.clear_references,
|
||||
buffer = bufnr,
|
||||
group = "lsp_document_highlight",
|
||||
desc = "Clear All the References",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,11 +80,9 @@ local function lsp_keymaps(bufnr)
|
||||
keymap(bufnr, "n", "ä", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
|
||||
end
|
||||
|
||||
-- TODO: Neovim 0.8 https://github.com/jose-elias-alvarez/null-ls.nvim/wiki/Avoiding-LSP-formatting-conflicts
|
||||
-- https://github.com/jose-elias-alvarez/null-ls.nvim/wiki/Formatting-on-save
|
||||
local lsp_formatting = function(bufnr)
|
||||
-- vim.lsp.buf.format({})
|
||||
vim.lsp.buf.formatting_sync({
|
||||
vim.lsp.buf.format({
|
||||
bufnr = bufnr,
|
||||
filter = function(client)
|
||||
return client.name == "null-ls"
|
||||
@@ -105,47 +107,47 @@ M.on_attach = function(client, bufnr)
|
||||
|
||||
-- TypeScript
|
||||
if client.name == "tsserver" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- HTML
|
||||
if client.name == "html" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- Stylelint
|
||||
if client.name == "stylelint_lsp" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- JSON
|
||||
if client.name == "jsonls" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- Lua
|
||||
if client.name == "sumneko_lua" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.resolved_capabilities.document_range_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
client.server_capabilities.documentRangeFormattingProvider = false
|
||||
end
|
||||
|
||||
-- Rust
|
||||
if client.name == "rust_analyzer" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- Astro
|
||||
if client.name == "astro" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
-- Diagnostic
|
||||
if client.name == "diagnosticls" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
end
|
||||
|
||||
lsp_keymaps(bufnr)
|
||||
lsp_highlight_document(client)
|
||||
lsp_highlight_document(client, bufnr)
|
||||
end
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
Reference in New Issue
Block a user