fix autoformatting on save

This commit is contained in:
Ray Elliott 2021-10-05 23:16:48 +01:00
commit b6842faf9e
4 changed files with 191 additions and 20 deletions

View file

@ -33,7 +33,7 @@ cmp.setup({
sources = {
{
name = 'nvim_lsp',
max_item_count = 20,
max_item_count = 8,
},
{ name = 'path' },
{

View file

@ -8,12 +8,12 @@ local eslint = {
formatStdin = true
}
local shellcheck = {
lintCommand = "shellcheck -f gcc -x",
lintSource = "shellcheck",
lintCommand = "shellcheck -f gcc -x",
lintSource = "shellcheck",
lintFormats = {
"%f:%l:%c: %trror: %m",
"%f:%l:%c: %tarning: %m",
"%f:%l:%c: %tote: %m",
"%f:%l:%c: %trror: %m",
"%f:%l:%c: %tarning: %m",
"%f:%l:%c: %tote: %m",
}
}
local flake8 = {
@ -40,12 +40,12 @@ local luaformat = {
}
local util = require "lspconfig".util
local on_attach_efm = function(client)
-- if client.resolved_capabilities.document_formatting then
-- vim.cmd [[augroup lsp_formatting]]
-- vim.cmd [[autocmd!]]
-- vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_seq_sync({}, 1000)]]
-- vim.cmd [[augroup END]]
-- end
if client.resolved_capabilities.document_formatting then
vim.cmd [[augroup efm_formatting]]
vim.cmd [[autocmd!]]
vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_seq_sync({}, 1000)]]
vim.cmd [[augroup END]]
end
end
require "lspconfig".efm.setup {
init_options = {documentFormatting = true},
@ -59,12 +59,12 @@ require "lspconfig".efm.setup {
rootMarkers = {".eslintrc.js", ".git/"},
languages = {
javascript = {eslint},
json = {jq, fixjson},
python = {flake8, black},
sh = {shellcheck},
lua = {luaformat}
}
}
json = {jq, fixjson},
python = {flake8, black},
sh = {shellcheck},
lua = {luaformat}
}
}
}

View file

@ -14,8 +14,6 @@ local servers = {
'phpactor',
-- npm install -g pyright
'pyright',
-- npm i -g stylelint-lsp
'stylelint_lsp',
-- https://github.com/neovim/nvim-lspconfig/wiki
-- 'tailwindcss',
-- npm install -g typescript typescript-language-server
@ -55,9 +53,17 @@ local on_attach = function(client, bufnr)
-- buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
if client.resolved_capabilities.document_formatting then
vim.cmd [[augroup lsp_formatting]]
vim.cmd [[autocmd!]]
vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_seq_sync({}, 1000)]]
vim.cmd [[augroup END]]
end
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
capabilities.textDocument.completion.completionItem.snippetSupport = true
for _, lsp in ipairs(servers) do
@ -69,3 +75,19 @@ for _, lsp in ipairs(servers) do
}
}
end
-- npm i -g stylelint-lsp
nvim_lsp.stylelint_lsp.setup {
on_attach = on_attach,
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
filetypes = {'css', 'scss', 'less'},
settings = {
stylelintplus = {
autoFixOnSave = true,
autoFixOnFormat = true,
}
}
}