fix eslint LSP auto format on save
This commit is contained in:
parent
06c04d64e3
commit
42e571b77c
4 changed files with 29 additions and 18 deletions
|
|
@ -6,6 +6,10 @@ local M = {
|
|||
|
||||
function M.config()
|
||||
require('typescript-tools').setup({
|
||||
on_attach = function(client)
|
||||
client.server_capabilities.documentFormattingProvider = false
|
||||
client.server_capabilities.documentRangeFormattingProvider = false
|
||||
end,
|
||||
settings = {
|
||||
-- spawn additional tsserver instance to calculate diagnostics on it
|
||||
separate_diagnostic_server = true,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,21 @@ return {
|
|||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
local bufnr = args.buf
|
||||
|
||||
-- (Special case, has no 'format server_capabilities)
|
||||
-- Set eslint LSP client to format on save.
|
||||
if client.name == 'eslint' then
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
if not format_is_enabled then
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd('EslintFixAll')
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Only attach to clients that support document formatting
|
||||
if not client.server_capabilities.documentFormattingProvider then
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue