From 57ab6006cd75cad33776030d19c889e71378a0fc Mon Sep 17 00:00:00 2001 From: Rostyslav Hnatyshyn Date: Tue, 18 Apr 2023 19:24:20 -0700 Subject: [PATCH] fixed format on save --- nvim/init.lua | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index b0b0551..e0ff486 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -72,7 +72,7 @@ end -- is leader key; default is \ nmap("v", "NvimTreeToggle") nmap("ec", "e ~/.config/nvim/init.lua") -nmap("sc", "source ~/.config/nvim/init.lua") +nmap("sc", "source ~/.config/nvim/init.luaPackerSync") -- buffer commands nmap("b", "BufferLineCyclePrev") @@ -84,6 +84,8 @@ nmap("f", "Telescope live_grep") nmap("t", "FloatermToggle") map("t", "t", "FloatermToggle") +local augroup = vim.api.nvim_create_augroup("Lspformatting", {}) + -- lsp on_attach mappings local on_attach = function(client, bufnr) if (not bufnr) then @@ -113,10 +115,9 @@ local on_attach = function(client, bufnr) require "coq".lsp_ensure_capabilities {} require 'illuminate'.on_attach(client) - require 'lsp-format'.on_attach(client) -- format on save does not work for python for some reason - --[[if client.supports_method("textDocument/formatting") then + if client.supports_method("textDocument/formatting") then vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_create_autocmd("BufWritePre", { group = augroup, @@ -125,15 +126,14 @@ local on_attach = function(client, bufnr) vim.lsp.buf.format({ bufnr = bufnr }) end }) - end ]] - -- + end end --- lsp config setup local lsp = require "lspconfig" lsp.hls.setup { on_attach = on_attach } -- haskell language server lsp.ccls.setup { on_attach = on_attach } lsp.pyright.setup { on_attach = on_attach } +-- https://github.com/denoland/deno - maybe switch? lsp.tsserver.setup { on_attach = on_attach } lsp.marksman.setup { on_attach = on_attach } lsp.rust_analyzer.setup { on_attach = on_attach } @@ -163,23 +163,41 @@ if fn.empty(fn.glob(install_path)) > 0 then install_path }) end +-- add code actions listeners? +--lua/code_action_utils.lua +--[[local M = {} + +local lsp_util = vim.lsp.util + +function M.code_action_listener() + local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() } + local params = lsp_util.make_range_params() + params.context = context + vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config) + -- do something with result - e.g. check if empty and show some indication such as a sign + end) +end + +return M]] +-- + return require('packer').startup(function(use) use 'wbthomason/packer.nvim' use 'nvim-lua/plenary.nvim' - use { "lukas-reineke/lsp-format.nvim", + --[[use { "lukas-reineke/lsp-format.nvim", config = function() require("lsp-format").setup { python = { - sync = true, - force = true, exclude = { "pyright" }, }, javascript = { exclude = { "tsserver" } } } - end - } + end, + requires = { 'neovim/nvim-lspconfig' } + }]] + -- use 'neovim/nvim-lspconfig' use { 'ms-jpq/coq_nvim', @@ -240,9 +258,7 @@ return require('packer').startup(function(use) local gitsigns = null_ls.builtins.code_actions.gitsigns null_ls.setup { - debug = true, on_attach = on_attach, - log_level = "debug" } null_ls.register({ isort, black, flake8, gitsigns }) null_ls.register({ name = "eslint_d", sources = { eslint_d_code, eslint_d_diag, eslint_d_format } })