This commit is contained in:
Nikos Papadakis 2023-04-25 20:23:42 +03:00
parent baa3f83252
commit 107e108455
Signed by untrusted user who does not match committer: nikos
GPG key ID: 78871F9905ADFF02
2 changed files with 35 additions and 26 deletions

View file

@ -4,8 +4,6 @@ if not ok then
return
end
-- local has_lint, lint = pcall(require, "lint")
local nmap = require("my.utils").nmap
local border = {
@ -44,6 +42,23 @@ local format_augroup = setmetatable({}, {
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)
nmap("<Leader>r", vim.lsp.buf.rename, "Rename", bufnr)
nmap("<Leader>cf", vim.lsp.buf.format, "Format document", bufnr)
@ -82,10 +97,20 @@ local on_attach = function(client, bufnr)
-- Format on save
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],
}
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
group = format_augroup[client.id],
desc = "format on save",
pattern = "<buffer>",
callback = function()
vim.lsp.buf.format { async = false }
if format_saving[bufnr] == true then
return
end
vim.lsp.buf.format({ async = true })
end,
})
end
@ -93,29 +118,12 @@ local on_attach = function(client, bufnr)
if has_lsp_status then
lsp_status.on_attach(client)
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
local servers = {
gopls = {},
phpactor = {},
pylsp = {},
-- phpactor = {},
-- pylsp = {},
rust_analyzer = {
assist = {
importGranularity = "module",
@ -148,8 +156,9 @@ local servers = {
},
},
},
denols = {},
svelte = {},
ocamllsp = {},
-- denols = {},
-- svelte = {},
-- tailwindcss = {
-- root_dir = lspconfig.util.root_pattern("tailwind.config.js", "tailwind.config.ts", "tailwind.config.cjs"),
-- },

View file

@ -23,7 +23,7 @@ local get_new_position = function(node, direction)
end
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 last = string.sub(text, -1)
return pairs[first] == last