fixed format on save

master
Rostyslav Hnatyshyn 2 years ago
parent 75eaf01659
commit 57ab6006cd
  1. 42
      nvim/init.lua

@ -72,7 +72,7 @@ end
-- <leader> is leader key; default is \ -- <leader> is leader key; default is \
nmap("<leader>v", "<cmd>NvimTreeToggle<cr>") nmap("<leader>v", "<cmd>NvimTreeToggle<cr>")
nmap("<leader>ec", "<cmd>e ~/.config/nvim/init.lua<cr>") nmap("<leader>ec", "<cmd>e ~/.config/nvim/init.lua<cr>")
nmap("<leader>sc", "<cmd>source ~/.config/nvim/init.lua<cr>") nmap("<leader>sc", "<cmd>source ~/.config/nvim/init.lua<cr><cmd>PackerSync<cr>")
-- buffer commands -- buffer commands
nmap("<leader>b", "<cmd>BufferLineCyclePrev<cr>") nmap("<leader>b", "<cmd>BufferLineCyclePrev<cr>")
@ -84,6 +84,8 @@ nmap("<leader>f", "<cmd>Telescope live_grep<cr>")
nmap("<leader>t", "<cmd>FloatermToggle<cr>") nmap("<leader>t", "<cmd>FloatermToggle<cr>")
map("t", "<leader>t", "<cmd>FloatermToggle<cr>") map("t", "<leader>t", "<cmd>FloatermToggle<cr>")
local augroup = vim.api.nvim_create_augroup("Lspformatting", {})
-- lsp on_attach mappings -- lsp on_attach mappings
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
if (not bufnr) then if (not bufnr) then
@ -113,10 +115,9 @@ local on_attach = function(client, bufnr)
require "coq".lsp_ensure_capabilities {} require "coq".lsp_ensure_capabilities {}
require 'illuminate'.on_attach(client) require 'illuminate'.on_attach(client)
require 'lsp-format'.on_attach(client)
-- format on save does not work for python for some reason -- 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_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", { vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup, group = augroup,
@ -125,15 +126,14 @@ local on_attach = function(client, bufnr)
vim.lsp.buf.format({ bufnr = bufnr }) vim.lsp.buf.format({ bufnr = bufnr })
end end
}) })
end ]] end
--
end end
-- lsp config setup
local lsp = require "lspconfig" local lsp = require "lspconfig"
lsp.hls.setup { on_attach = on_attach } -- haskell language server lsp.hls.setup { on_attach = on_attach } -- haskell language server
lsp.ccls.setup { on_attach = on_attach } lsp.ccls.setup { on_attach = on_attach }
lsp.pyright.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.tsserver.setup { on_attach = on_attach }
lsp.marksman.setup { on_attach = on_attach } lsp.marksman.setup { on_attach = on_attach }
lsp.rust_analyzer.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 }) install_path })
end 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) return require('packer').startup(function(use)
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
use 'nvim-lua/plenary.nvim' use 'nvim-lua/plenary.nvim'
use { "lukas-reineke/lsp-format.nvim", --[[use { "lukas-reineke/lsp-format.nvim",
config = function() config = function()
require("lsp-format").setup { require("lsp-format").setup {
python = { python = {
sync = true,
force = true,
exclude = { "pyright" }, exclude = { "pyright" },
}, },
javascript = { javascript = {
exclude = { "tsserver" } exclude = { "tsserver" }
} }
} }
end end,
} requires = { 'neovim/nvim-lspconfig' }
}]]
--
use 'neovim/nvim-lspconfig' use 'neovim/nvim-lspconfig'
use { use {
'ms-jpq/coq_nvim', 'ms-jpq/coq_nvim',
@ -240,9 +258,7 @@ return require('packer').startup(function(use)
local gitsigns = null_ls.builtins.code_actions.gitsigns local gitsigns = null_ls.builtins.code_actions.gitsigns
null_ls.setup { null_ls.setup {
debug = true,
on_attach = on_attach, on_attach = on_attach,
log_level = "debug"
} }
null_ls.register({ isort, black, flake8, gitsigns }) null_ls.register({ isort, black, flake8, gitsigns })
null_ls.register({ name = "eslint_d", sources = { eslint_d_code, eslint_d_diag, eslint_d_format } }) null_ls.register({ name = "eslint_d", sources = { eslint_d_code, eslint_d_diag, eslint_d_format } })

Loading…
Cancel
Save