2021-03-18 05:24:49 +01:00
-- Example configuations here: https://github.com/mattn/efm-langserver
2021-03-27 22:21:52 +01:00
-- TODO this file needs to be refactored eache lang should be it's own file
2021-03-19 04:47:03 +01:00
-- python
2021-03-27 22:21:52 +01:00
local python_arguments = { }
-- TODO replace with path argument
2021-03-19 04:47:03 +01:00
local flake8 = {
LintCommand = " flake8 --ignore=E501 --stdin-display-name ${INPUT} - " ,
lintStdin = true ,
lintFormats = { " %f:%l:%c: %m " }
}
2021-03-27 22:21:52 +01:00
2021-03-19 04:47:03 +01:00
local isort = { formatCommand = " isort --quiet - " , formatStdin = true }
2021-03-27 22:21:52 +01:00
2021-03-19 04:47:03 +01:00
local yapf = { formatCommand = " yapf --quiet " , formatStdin = true }
2021-04-18 00:42:51 +02:00
local black = { formatCommand = " black --quiet - " , formatStdin = true }
2021-03-27 22:21:52 +01:00
2021-03-29 22:24:03 +02:00
if O.python . linter == ' flake8 ' then table.insert ( python_arguments , flake8 ) end
if O.python . isort then table.insert ( python_arguments , isort ) end
2021-03-27 22:21:52 +01:00
if O.python . formatter == ' yapf ' then
2021-03-29 22:24:03 +02:00
table.insert ( python_arguments , yapf )
2021-03-28 20:49:56 +02:00
elseif O.python . formatter == ' black ' then
table.insert ( python_arguments , black )
2021-03-27 22:21:52 +01:00
end
2021-03-19 04:47:03 +01:00
-- lua
2021-03-27 22:21:52 +01:00
local lua_arguments = { }
2021-04-18 00:42:51 +02:00
2021-03-19 04:47:03 +01:00
local luaFormat = {
2021-06-27 21:31:33 +02:00
formatCommand = " lua-format -i --no-keep-simple-function-one-line --column-limit=80 " ,
2021-03-19 04:47:03 +01:00
formatStdin = true
}
2021-04-18 00:42:51 +02:00
local lua_fmt = {
formatCommand = " luafmt --indent-count 2 --line-width 120 --stdin " ,
formatStdin = true
}
if O.lua . formatter == ' lua-format ' then
table.insert ( lua_arguments , luaFormat )
elseif O.lua . formatter == ' lua-fmt ' then
table.insert ( lua_arguments , lua_fmt )
end
2021-03-27 22:21:52 +01:00
-- sh
local sh_arguments = { }
local shfmt = { formatCommand = ' shfmt -ci -s -bn ' , formatStdin = true }
local shellcheck = {
LintCommand = ' shellcheck -f gcc -x ' ,
lintFormats = { ' %f:%l:%c: %trror: %m ' , ' %f:%l:%c: %tarning: %m ' , ' %f:%l:%c: %tote: %m ' }
}
2021-03-29 22:24:03 +02:00
if O.sh . formatter == ' shfmt ' then table.insert ( sh_arguments , shfmt ) end
2021-03-27 22:21:52 +01:00
2021-03-29 22:24:03 +02:00
if O.sh . linter == ' shellcheck ' then table.insert ( sh_arguments , shellcheck ) end
2021-03-27 22:21:52 +01:00
-- tsserver/web javascript react, vue, json, html, css, yaml
local prettier = { formatCommand = " prettier --stdin-filepath ${INPUT} " , formatStdin = true }
-- You can look for project scope Prettier and Eslint with e.g. vim.fn.glob("node_modules/.bin/prettier") etc. If it is not found revert to global Prettier where needed.
-- local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
2021-03-19 07:37:02 +01:00
2021-03-19 04:47:03 +01:00
local eslint = {
lintCommand = " ./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT} " ,
lintIgnoreExitCode = true ,
lintStdin = true ,
lintFormats = { " %f:%l:%c: %m " } ,
formatCommand = " ./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT} " ,
formatStdin = true
}
2021-03-27 22:21:52 +01:00
local tsserver_args = { }
2021-03-19 05:10:21 +01:00
2021-03-29 22:24:03 +02:00
if O.tsserver . formatter == ' prettier ' then table.insert ( tsserver_args , prettier ) end
2021-03-19 05:10:21 +01:00
2021-03-29 22:24:03 +02:00
if O.tsserver . linter == ' eslint ' then table.insert ( tsserver_args , eslint ) end
2021-03-27 22:21:52 +01:00
-- local markdownlint = {
-- -- TODO default to global lintrc
-- -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
-- lintCommand = 'markdownlint -s',
-- lintStdin = true,
-- lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'}
-- }
2021-03-20 22:22:44 +01:00
2021-03-23 06:44:13 +01:00
local markdownPandocFormat = { formatCommand = ' pandoc -f markdown -t gfm -sp --tab-stop=2 ' , formatStdin = true }
2021-03-19 06:08:11 +01:00
2021-03-17 19:15:20 +01:00
require " lspconfig " . efm.setup {
2021-03-19 04:47:03 +01:00
-- init_options = {initializationOptions},
2021-03-27 22:21:52 +01:00
cmd = { DATA_PATH .. " /lspinstall/efm/efm-langserver " } ,
2021-03-19 04:47:03 +01:00
init_options = { documentFormatting = true , codeAction = false } ,
2021-04-29 08:01:37 +02:00
filetypes = { " lua " , " python " , " javascriptreact " , " javascript " , " typescript " , " typescriptreact " , " sh " , " html " , " css " , " json " , " yaml " , " markdown " , " vue " } ,
2021-03-17 19:15:20 +01:00
settings = {
rootMarkers = { " .git/ " } ,
languages = {
2021-03-27 22:21:52 +01:00
python = python_arguments ,
lua = lua_arguments ,
2021-03-29 22:24:03 +02:00
sh = sh_arguments ,
2021-03-27 22:21:52 +01:00
javascript = tsserver_args ,
javascriptreact = tsserver_args ,
2021-04-29 08:01:37 +02:00
typescript = tsserver_args ,
typescriptreact = tsserver_args ,
2021-03-27 22:21:52 +01:00
html = { prettier } ,
css = { prettier } ,
json = { prettier } ,
yaml = { prettier } ,
markdown = { markdownPandocFormat }
2021-03-22 04:14:11 +01:00
-- javascriptreact = {prettier, eslint},
-- javascript = {prettier, eslint},
2021-03-20 22:22:44 +01:00
-- markdown = {markdownPandocFormat, markdownlint},
2021-03-17 19:15:20 +01:00
}
}
}
2021-03-17 20:48:52 +01:00
2021-03-18 05:24:49 +01:00
-- Also find way to toggle format on save
-- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim