From 94b84379628caa60abbc6c16a72a9395e8038fe9 Mon Sep 17 00:00:00 2001 From: Nikos Papadakis Date: Wed, 12 Jul 2023 12:22:46 +0300 Subject: [PATCH] nvim --- .../nvim/after/plugin/lspconfig.lua | 90 +++++++++---------- nvim/dot-config/nvim/after/plugin/null-ls.lua | 12 --- nvim/dot-config/nvim/lua/my/plugins.lua | 4 +- 3 files changed, 47 insertions(+), 59 deletions(-) delete mode 100644 nvim/dot-config/nvim/after/plugin/null-ls.lua diff --git a/nvim/dot-config/nvim/after/plugin/lspconfig.lua b/nvim/dot-config/nvim/after/plugin/lspconfig.lua index c574f63..f5c5f0e 100644 --- a/nvim/dot-config/nvim/after/plugin/lspconfig.lua +++ b/nvim/dot-config/nvim/after/plugin/lspconfig.lua @@ -32,29 +32,9 @@ if has_lsp_status then capabilities = vim.tbl_extend("keep", capabilities, lsp_status.capabilities) end -local format_augroup = setmetatable({}, { - __index = function(self, id) - local group = vim.api.nvim_create_augroup(string.format("lsp-format-%s", id), { clear = true }) - rawset(self, id, group) - return group - 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 +local has_lsp_format, lsp_format = pcall(require, "lsp-format") +if has_lsp_format then + lsp_format.setup() end local on_attach = function(client, bufnr) @@ -84,32 +64,43 @@ local on_attach = function(client, bufnr) }) end - -- Format on save - if client.server_capabilities.documentFormattingProvider then - 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 = "", - callback = function() - if format_saving[bufnr] == true then - return - end - vim.lsp.buf.format({ async = true }) - end, - }) - end - if has_lsp_status then lsp_status.on_attach(client) end + + if has_lsp_format then + lsp_format.on_attach(client) + end end +local prettier = { + formatCommand = [[prettier --stdin-filepath ${INPUT} ${--tab-width:tab_width}]], + formatStdin = true, +} + +local eslint = { + lintCommand = [[eslint_d -f visualstudio --stdin --stdin-filename ${INPUT}]], + lintIgnoreExitCode = true, + lintStdin = true, + lintFormats = { + "%f(%l,%c): %tarning %m", + "%f(%l,%c): %rror %m", + }, + lintSource = "eslint", +} + local servers = { + efm = { + filetypes = { "typescript", "typescriptreact" }, + init_options = { documentFormatting = true }, + settings = { + rootMarkers = { ".git/" }, + languages = { + typescript = { prettier, eslint }, + typescriptreact = { prettier, eslint }, + }, + }, + }, gopls = {}, pylsp = {}, rust_analyzer = { @@ -145,9 +136,18 @@ local servers = { }, }, elixirls = { - cmd = { "elixir-ls" } + cmd = { "/home/nikos/Projects/elixir-ls/release/language_server.sh" }, + settings = { + elixirLS = { + dialyzerEnabled = true, + }, + }, + }, + tsserver = { + settings = { + documentFormatting = false, + }, }, - tsserver = {}, psalm = { cmd = { "vendor/bin/psalm-language-server" }, }, diff --git a/nvim/dot-config/nvim/after/plugin/null-ls.lua b/nvim/dot-config/nvim/after/plugin/null-ls.lua deleted file mode 100644 index 976c444..0000000 --- a/nvim/dot-config/nvim/after/plugin/null-ls.lua +++ /dev/null @@ -1,12 +0,0 @@ -local ok, null = pcall(require, "null-ls") -if not ok then - return -end - -null.setup { - sources = { - null.builtins.diagnostics.eslint, - null.builtins.diagnostics.shellcheck, - null.builtins.formatting.prettierd, - } -} diff --git a/nvim/dot-config/nvim/lua/my/plugins.lua b/nvim/dot-config/nvim/lua/my/plugins.lua index 07e7bfc..1f0d5d8 100644 --- a/nvim/dot-config/nvim/lua/my/plugins.lua +++ b/nvim/dot-config/nvim/lua/my/plugins.lua @@ -28,9 +28,9 @@ require "paq" { { "nvim-telescope/telescope.nvim", branch = "0.1.x" }, { "nvim-telescope/telescope-fzf-native.nvim", run = "make" }, { "catppuccin/nvim", as = "catppuccin" }, - { "williamboman/mason.nvim", branch = "v1.0.1" }, + { "williamboman/mason.nvim", branch = "v1.6.0" }, + { "lukas-reineke/lsp-format.nvim", branch = "v2.5.1" }, "stevearc/oil.nvim", - "jose-elias-alvarez/null-ls.nvim", -- Treesitter { "nvim-treesitter/nvim-treesitter", branch = "master" },