nvim
This commit is contained in:
parent
baa3f83252
commit
107e108455
2 changed files with 35 additions and 26 deletions
|
@ -4,8 +4,6 @@ if not ok then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local has_lint, lint = pcall(require, "lint")
|
|
||||||
|
|
||||||
local nmap = require("my.utils").nmap
|
local nmap = require("my.utils").nmap
|
||||||
|
|
||||||
local border = {
|
local border = {
|
||||||
|
@ -44,6 +42,23 @@ local format_augroup = setmetatable({}, {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local format_saving = {}
|
||||||
|
|
||||||
|
local format_handler = function(err, result, ctx)
|
||||||
|
if not result then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||||
|
vim.lsp.util.apply_text_edits(result, ctx.bufnr, client.offset_encoding)
|
||||||
|
|
||||||
|
if ctx.bufnr == vim.api.nvim_get_current_buf() then
|
||||||
|
format_saving[ctx.bufnr] = true
|
||||||
|
vim.cmd [[update]]
|
||||||
|
format_saving[ctx.bufnr] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
nmap("<Leader>r", vim.lsp.buf.rename, "Rename", bufnr)
|
nmap("<Leader>r", vim.lsp.buf.rename, "Rename", bufnr)
|
||||||
nmap("<Leader>cf", vim.lsp.buf.format, "Format document", bufnr)
|
nmap("<Leader>cf", vim.lsp.buf.format, "Format document", bufnr)
|
||||||
|
@ -82,10 +97,20 @@ local on_attach = function(client, bufnr)
|
||||||
|
|
||||||
-- Format on save
|
-- Format on save
|
||||||
if client.server_capabilities.documentFormattingProvider then
|
if client.server_capabilities.documentFormattingProvider then
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
vim.lsp.handlers["textDocument/formatting"] = vim.lsp.with(format_handler, {})
|
||||||
|
vim.api.nvim_clear_autocmds {
|
||||||
|
buffer = bufnr,
|
||||||
group = format_augroup[client.id],
|
group = format_augroup[client.id],
|
||||||
|
}
|
||||||
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||||||
|
group = format_augroup[client.id],
|
||||||
|
desc = "format on save",
|
||||||
|
pattern = "<buffer>",
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.lsp.buf.format { async = false }
|
if format_saving[bufnr] == true then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.lsp.buf.format({ async = true })
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -93,29 +118,12 @@ local on_attach = function(client, bufnr)
|
||||||
if has_lsp_status then
|
if has_lsp_status then
|
||||||
lsp_status.on_attach(client)
|
lsp_status.on_attach(client)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if has_lint then
|
|
||||||
-- if vim.filetype.match({ buf = bufnr }) == "php" then
|
|
||||||
-- lint.linters.psalm.cmd = "./vendor/bin/psalm"
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- lint.linters_by_ft = {
|
|
||||||
-- php = { "psalm" }
|
|
||||||
-- }
|
|
||||||
|
|
||||||
-- vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
|
||||||
-- pattern = { "*.php" },
|
|
||||||
-- callback = function()
|
|
||||||
-- lint.try_lint()
|
|
||||||
-- end
|
|
||||||
-- })
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local servers = {
|
local servers = {
|
||||||
gopls = {},
|
gopls = {},
|
||||||
phpactor = {},
|
-- phpactor = {},
|
||||||
pylsp = {},
|
-- pylsp = {},
|
||||||
rust_analyzer = {
|
rust_analyzer = {
|
||||||
assist = {
|
assist = {
|
||||||
importGranularity = "module",
|
importGranularity = "module",
|
||||||
|
@ -148,8 +156,9 @@ local servers = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
denols = {},
|
ocamllsp = {},
|
||||||
svelte = {},
|
-- denols = {},
|
||||||
|
-- svelte = {},
|
||||||
-- tailwindcss = {
|
-- tailwindcss = {
|
||||||
-- root_dir = lspconfig.util.root_pattern("tailwind.config.js", "tailwind.config.ts", "tailwind.config.cjs"),
|
-- root_dir = lspconfig.util.root_pattern("tailwind.config.js", "tailwind.config.ts", "tailwind.config.cjs"),
|
||||||
-- },
|
-- },
|
||||||
|
|
|
@ -23,7 +23,7 @@ local get_new_position = function(node, direction)
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_wrapped = function()
|
local is_wrapped = function()
|
||||||
local text = vim.treesitter.query.get_node_text(node, 0)
|
local text = vim.treesitter.get_node_text(node, 0)
|
||||||
local first = string.sub(text, 1, 1)
|
local first = string.sub(text, 1, 1)
|
||||||
local last = string.sub(text, -1)
|
local last = string.sub(text, -1)
|
||||||
return pairs[first] == last
|
return pairs[first] == last
|
||||||
|
|
Loading…
Reference in a new issue