added more user options

This commit is contained in:
Chris 2021-03-27 17:21:52 -04:00
parent 2c5d18ebbc
commit 56798ec142
6 changed files with 122 additions and 44 deletions

View file

@ -1,21 +1,64 @@
-- Example configuations here: https://github.com/mattn/efm-langserver -- Example configuations here: https://github.com/mattn/efm-langserver
-- TODO this file needs to be refactored eache lang should be it's own file
-- python -- python
local python_arguments = {}
-- TODO replace with path argument
local flake8 = { local flake8 = {
LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -", LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
lintStdin = true, lintStdin = true,
lintFormats = {"%f:%l:%c: %m"} lintFormats = {"%f:%l:%c: %m"}
} }
local isort = {formatCommand = "isort --quiet -", formatStdin = true} local isort = {formatCommand = "isort --quiet -", formatStdin = true}
local yapf = {formatCommand = "yapf --quiet", formatStdin = true} local yapf = {formatCommand = "yapf --quiet", formatStdin = true}
if O.python.linter == 'flake8' then
table.insert(python_arguments, flake8)
end
if O.python.formatter == 'yapf' then
table.insert(python_arguments, yapf)
end
if O.python.isort then
table.insert(python_arguments, isort)
end
-- lua -- lua
local lua_arguments = {}
local luaFormat = { local luaFormat = {
formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120", formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120",
formatStdin = true formatStdin = true
} }
-- JavaScript/React/TypeScript
local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
local prettier_global = {formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true} if O.lua.formatter == 'lua-format' then
table.insert(lua_arguments, luaFormat)
end
-- 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'}
}
if O.sh.formatter == 'shfmt' then
table.insert(sh_arguments, shfmt)
end
if O.sh.linter == 'shellcheck' then
table.insert(sh_arguments, shellcheck)
end
-- 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}
local eslint = { local eslint = {
lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}", lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
@ -26,44 +69,48 @@ local eslint = {
formatStdin = true formatStdin = true
} }
local shellcheck = { local tsserver_args = {}
LintCommand = 'shellcheck -f gcc -x',
lintFormats = {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'}
}
local shfmt = {formatCommand = 'shfmt -ci -s -bn', formatStdin = true} if O.tsserver.formatter == 'prettier' then
table.insert(tsserver_args, prettier)
end
local markdownlint = { if O.tsserver.linter == 'eslint' then
-- TODO default to global lintrc table.insert(tsserver_args, eslint)
-- lintcommand = 'markdownlint -s -c ./markdownlintrc', end
lintCommand = 'markdownlint -s',
lintStdin = true,
lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'} -- 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'}
-- }
local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true} local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true}
require"lspconfig".efm.setup { require"lspconfig".efm.setup {
-- init_options = {initializationOptions}, -- init_options = {initializationOptions},
cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" }, cmd = {DATA_PATH .. "/lspinstall/efm/efm-langserver"},
init_options = {documentFormatting = true, codeAction = false}, init_options = {documentFormatting = true, codeAction = false},
filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml", "markdown"}, filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml", "markdown"},
settings = { settings = {
rootMarkers = {".git/"}, rootMarkers = {".git/"},
languages = { languages = {
lua = {luaFormat}, python = python_arguments,
python = {isort, yapf}, lua = lua_arguments,
sh = sh_arguments,
javascript = tsserver_args,
javascriptreact = tsserver_args,
html = {prettier},
css = {prettier},
json = {prettier},
yaml = {prettier},
markdown = {markdownPandocFormat}
-- javascriptreact = {prettier, eslint}, -- javascriptreact = {prettier, eslint},
-- javascript = {prettier, eslint}, -- javascript = {prettier, eslint},
javascriptreact = {prettier},
javascript = {prettier_global},
sh = {shellcheck, shfmt},
html = {prettier_global},
css = {prettier_global},
json = {prettier_global},
yaml = {prettier_global},
-- markdown = {markdownPandocFormat, markdownlint}, -- markdown = {markdownPandocFormat, markdownlint},
markdown = {markdownPandocFormat}
} }
} }
} }

View file

@ -15,5 +15,14 @@ require'lspconfig'.tsserver.setup {
-- This makes sure tsserver is not used for formatting (I prefer prettier) -- This makes sure tsserver is not used for formatting (I prefer prettier)
-- on_attach = require'lsp'.common_on_attach, -- on_attach = require'lsp'.common_on_attach,
root_dir = require('lspconfig/util').root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), root_dir = require('lspconfig/util').root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"),
settings = {documentFormatting = false} settings = {documentFormatting = false},
handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = O.tsserver.diagnostics.virtual_text,
signs = O.tsserver.diagnostics.signs,
underline = O.tsserver.diagnostics.underline,
update_in_insert = true
})
}
} }

View file

@ -6,14 +6,24 @@ O = {
linter = '', linter = '',
formatter = '', formatter = '',
autoformat = false, autoformat = false,
isort = false,
diagnostics = {virtual_text = true, signs = true, underline = true} diagnostics = {virtual_text = true, signs = true, underline = true}
}, },
javascript = {linter = '', formatter = '', autoformat = false, virtual_text = true},
javascriptreact = {linter = '', formatter = '', autoformat = false, virtual_text = true},
lua = {formatter = '', autoformat = false, virtual_text = true}, lua = {formatter = '', autoformat = false, virtual_text = true},
bash = {linter = '', formatter = '', autoformat = false, virtual_text = true}, sh = {
css = {formatter = '', autoformat = false, virtual_text = true}, linter = '',
json = {formatter = '', autoformat = false, virtual_text = true} formatter = '',
autoformat = false,
diagnostics = {virtual_text = true, signs = true, underline = true}
},
tsserver = {
linter = '',
formatter = '',
autoformat = false,
diagnostics = {virtual_text = true, signs = true, underline = true}
},
-- css = {formatter = '', autoformat = false, virtual_text = true},
-- json = {formatter = '', autoformat = false, virtual_text = true}
} }

View file

@ -1,13 +1,11 @@
require'nvim-treesitter.configs'.setup { require'nvim-treesitter.configs'.setup {
ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
-- TODO seems to be broken -- TODO seems to be broken
ignore_install = { "haskell" }, ignore_install = {"haskell"},
highlight = { highlight = {
enable = true, -- false will disable the whole extension enable = true -- false will disable the whole extension
}, },
indent = { indent = {enable = true},
enable = true
},
playground = { playground = {
enable = true, enable = true,
disable = {}, disable = {},
@ -15,7 +13,8 @@ require'nvim-treesitter.configs'.setup {
persist_queries = false -- Whether the query persists across vim sessions persist_queries = false -- Whether the query persists across vim sessions
}, },
autotag = {enable = true}, autotag = {enable = true},
rainbow = {enable = true} rainbow = {enable = true},
context_commentstring = {enable = true, config = {javascriptreact = {style_element = '{/*%s*/}'}}}
-- refactor = {highlight_definitions = {enable = true}} -- refactor = {highlight_definitions = {enable = true}}
} }

View file

@ -53,6 +53,7 @@ return require('packer').startup(function(use)
use 'nvim-treesitter/playground' use 'nvim-treesitter/playground'
use 'p00f/nvim-ts-rainbow' use 'p00f/nvim-ts-rainbow'
use {'lukas-reineke/indent-blankline.nvim', branch = 'lua'} use {'lukas-reineke/indent-blankline.nvim', branch = 'lua'}
use 'JoosepAlviste/nvim-ts-context-commentstring'
-- Icons -- Icons
use 'kyazdani42/nvim-web-devicons' use 'kyazdani42/nvim-web-devicons'

View file

@ -8,14 +8,26 @@ an executable
]] ]]
O.auto_complete = false -- general
O.auto_complete = true
O.colorscheme = 'nvcode' O.colorscheme = 'nvcode'
-- python
-- add things like O.python.formatter.yapf.exec_path
-- add things like O.python.linter.flake8.exec_path
-- add things like O.python.formatter.isort.exec_path
O.python.formatter = 'yapf' O.python.formatter = 'yapf'
O.python.linter = nil O.python.linter = 'flake8'
O.python.isort = true
O.python.autoformat = false O.python.autoformat = false
O.python.diagnostics.virtual_text = false O.python.diagnostics.virtual_text = true
O.python.diagnostics.signs = false O.python.diagnostics.signs = true
O.python.diagnostics.underline = false O.python.diagnostics.underline = true
-- lua
O.lua.formatter = 'lua-format'
-- javascript
O.tsserver.formatter = 'prettier'
O.tsserver.linter = nil
O.tsserver.autoformat = false