2022-03-10 20:34:06 +01:00
|
|
|
-- autocomplete config
|
|
|
|
vim.opt.completeopt="menuone,noinsert"
|
|
|
|
vim.opt.shortmess:append("c")
|
|
|
|
|
|
|
|
require'compe'.setup {
|
|
|
|
enabled = true,
|
|
|
|
preselect = "always",
|
|
|
|
allow_prefix_unmatch = true,
|
|
|
|
source = {
|
|
|
|
path = true,
|
|
|
|
calc = true,
|
|
|
|
nvim_lsp = true,
|
|
|
|
vsnip = true,
|
|
|
|
},
|
|
|
|
}
|
2020-09-26 23:54:07 +02:00
|
|
|
|
2021-08-04 22:21:44 +02:00
|
|
|
local pid = vim.fn.getpid()
|
|
|
|
|
|
|
|
-- lightbulb
|
|
|
|
vim.cmd [[autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()]]
|
|
|
|
|
|
|
|
local on_attach = function(_, bufnr)
|
|
|
|
-- codelens
|
|
|
|
vim.api.nvim_command [[autocmd CursorHold,CursorHoldI,InsertLeave <buffer> lua vim.lsp.codelens.refresh()]]
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>l", "<Cmd>lua vim.lsp.codelens.run()<CR>", {silent = true;})
|
|
|
|
end
|
|
|
|
|
2020-09-26 23:54:07 +02:00
|
|
|
-- format on save
|
|
|
|
local diagnosticls_on_attach = function(_, bufnr)
|
2021-08-04 22:21:44 +02:00
|
|
|
on_attach(_, bufnr)
|
2021-05-05 00:05:37 +02:00
|
|
|
vim.api.nvim_command(
|
|
|
|
"au BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync(nil, nil, { 'tsserver', 'diagnosticls' })")
|
2020-09-26 23:54:07 +02:00
|
|
|
end
|
|
|
|
|
2021-11-13 04:23:32 +01:00
|
|
|
require('lspfuzzy').setup {}
|
|
|
|
|
2021-08-04 22:21:44 +02:00
|
|
|
-- enable lsp snippets for nvim-compe
|
2022-03-10 20:34:06 +01:00
|
|
|
|
|
|
|
local config = require'lspconfig'
|
2021-08-04 22:21:44 +02:00
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
|
|
|
local servers = {
|
|
|
|
"bashls",
|
|
|
|
"jsonls",
|
|
|
|
"yamlls",
|
|
|
|
"html",
|
|
|
|
"cssls",
|
|
|
|
"dockerls",
|
|
|
|
"rnix",
|
|
|
|
"tsserver",
|
2022-03-10 20:34:06 +01:00
|
|
|
"graphql",
|
2021-08-04 22:21:44 +02:00
|
|
|
"pylsp",
|
|
|
|
"terraformls",
|
|
|
|
"hls",
|
|
|
|
"rust_analyzer",
|
2022-03-10 15:03:17 +01:00
|
|
|
"vimls",
|
2021-08-04 22:21:44 +02:00
|
|
|
}
|
|
|
|
for _, lsp in ipairs(servers) do
|
|
|
|
config[lsp].setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
}
|
|
|
|
end
|
2020-11-28 16:21:07 +01:00
|
|
|
|
|
|
|
config.omnisharp.setup{
|
2021-08-04 22:21:44 +02:00
|
|
|
capabilities = capabilities,
|
2021-05-05 00:05:37 +02:00
|
|
|
cmd = {"omnisharp", "--languageserver", "--hostPID", tostring(pid)},
|
2020-09-26 23:54:07 +02:00
|
|
|
}
|
|
|
|
|
2022-03-10 15:04:02 +01:00
|
|
|
local runtime_path = vim.split(package.path, ';')
|
|
|
|
table.insert(runtime_path, "lua/?.lua")
|
|
|
|
table.insert(runtime_path, "lua/?/init.lua")
|
|
|
|
|
|
|
|
config.sumneko_lua.setup {
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
path = runtime_path,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = {"vim"},
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.diagnosticls.setup {
|
2021-05-05 00:05:37 +02:00
|
|
|
on_attach = diagnosticls_on_attach,
|
|
|
|
filetypes = {
|
|
|
|
"javascript",
|
|
|
|
"javascript.jsx",
|
|
|
|
"javascriptreact",
|
|
|
|
"typescript",
|
|
|
|
"typescript.jsx",
|
|
|
|
"typescriptreact",
|
|
|
|
"json",
|
|
|
|
"yaml",
|
|
|
|
"markdown",
|
2021-11-27 21:16:31 +01:00
|
|
|
"nix",
|
2021-05-05 00:05:37 +02:00
|
|
|
"html",
|
|
|
|
"css"
|
|
|
|
},
|
|
|
|
init_options = {
|
|
|
|
linters = {
|
|
|
|
eslint = {
|
|
|
|
command = "eslint_d",
|
|
|
|
args = {
|
|
|
|
"--cache",
|
|
|
|
"--stdin",
|
|
|
|
"--stdin-filename",
|
|
|
|
"%filepath",
|
|
|
|
"--format",
|
|
|
|
"json"
|
|
|
|
},
|
|
|
|
rootPatterns = {".eslintrc.js", ".eslintrc.json", ".git"},
|
|
|
|
debounce = 50,
|
|
|
|
sourceName = "eslint",
|
|
|
|
parseJson = {
|
|
|
|
errorsRoot = "[0].messages",
|
|
|
|
line = "line",
|
|
|
|
column = "column",
|
|
|
|
endLine = "endLine",
|
|
|
|
endColumn = "endColumn",
|
|
|
|
message = "${message} [${ruleId}]",
|
|
|
|
security = "severity"
|
|
|
|
},
|
|
|
|
securities = {
|
|
|
|
["2"] = "error",
|
|
|
|
["1"] = "warning"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
stylelint = {
|
|
|
|
command = "stylelint",
|
|
|
|
args = {
|
|
|
|
"--stdin",
|
|
|
|
"--formatter",
|
|
|
|
"json",
|
|
|
|
"--file",
|
|
|
|
"%filepath"
|
|
|
|
},
|
|
|
|
rootPatterns = {".git"},
|
|
|
|
debounce = 50,
|
|
|
|
sourceName = "stylelint",
|
|
|
|
parseJson = {
|
|
|
|
errorsRoot = "[0].warnings",
|
|
|
|
line = "line",
|
|
|
|
column = "column",
|
|
|
|
message = "${text}",
|
|
|
|
security = "severity",
|
|
|
|
},
|
|
|
|
securities = {
|
|
|
|
error = "error",
|
|
|
|
warning = "warning",
|
|
|
|
},
|
|
|
|
},
|
2021-11-27 21:16:31 +01:00
|
|
|
["nix-linter"] = {
|
|
|
|
-- TODO uses custom script until json support is fixed
|
|
|
|
command = "nix-linter",
|
|
|
|
sourceName = "nix-linter",
|
|
|
|
debounce = 50,
|
|
|
|
parseJson = {
|
|
|
|
line = "pos.spanBegin.sourceLine",
|
|
|
|
column = "pos.spanBegin.sourceColumn",
|
|
|
|
endLine = "pos.spanEnd.sourceLine",
|
|
|
|
endColumn = "pos.spanEnd.sourceColumn",
|
|
|
|
message = "${description}",
|
|
|
|
},
|
|
|
|
},
|
2021-05-05 00:05:37 +02:00
|
|
|
},
|
|
|
|
filetypes = {
|
|
|
|
javascript = {"eslint"},
|
|
|
|
["javascript.jsx"] = {"eslint"},
|
|
|
|
javascriptreact = {"eslint"},
|
|
|
|
typescript = {"eslint"},
|
|
|
|
["typescript.jsx"] = {"eslint"},
|
|
|
|
typescriptreact = {"eslint"},
|
|
|
|
css = {"stylelint"},
|
2021-11-27 21:16:31 +01:00
|
|
|
nix = {"nix-linter"},
|
2021-05-05 00:05:37 +02:00
|
|
|
},
|
|
|
|
formatters = {
|
|
|
|
eslint = {
|
|
|
|
command = "eslint_d",
|
|
|
|
args = {
|
|
|
|
"--cache",
|
2021-05-05 13:49:41 +02:00
|
|
|
"--fix-to-stdout",
|
|
|
|
"--stdin",
|
|
|
|
"--stdin-filename",
|
2021-05-05 00:05:37 +02:00
|
|
|
"%filepath"
|
|
|
|
},
|
|
|
|
debounce = 50,
|
|
|
|
rootPatterns = {".eslintrc.js", ".eslintrc.json", ".git"},
|
|
|
|
},
|
|
|
|
stylelint = {
|
|
|
|
command = "stylelint",
|
|
|
|
args = {
|
|
|
|
"--stdin",
|
|
|
|
"--fix",
|
|
|
|
"--file",
|
|
|
|
"%filepath"
|
|
|
|
},
|
|
|
|
rootPatterns = {".stylelintrc.json", ".git"},
|
|
|
|
},
|
|
|
|
prettier = {
|
|
|
|
command = "prettier",
|
|
|
|
args = {
|
|
|
|
"--stdin",
|
|
|
|
"--stdin-filepath",
|
|
|
|
"%filepath"
|
|
|
|
},
|
|
|
|
rootPatterns = {".prettierrc.json", ".git"},
|
|
|
|
},
|
2021-11-27 21:16:31 +01:00
|
|
|
nixfmt = {
|
|
|
|
command = "nixfmt",
|
|
|
|
},
|
2021-05-05 00:05:37 +02:00
|
|
|
},
|
|
|
|
formatFiletypes = {
|
|
|
|
javascript = {"eslint"},
|
|
|
|
["javascript.jsx"] = {"eslint"},
|
|
|
|
javascriptreact = {"eslint"},
|
|
|
|
typescript = {"eslint"},
|
|
|
|
["typescript.jsx"] = {"eslint"},
|
|
|
|
typescriptreact = {"eslint"},
|
|
|
|
json = {"prettier"},
|
|
|
|
yaml = {"prettier"},
|
|
|
|
markdown = {"prettier"},
|
2021-08-04 22:21:44 +02:00
|
|
|
nix = {"nixfmt"},
|
2021-05-05 00:05:37 +02:00
|
|
|
html = {"prettier"},
|
|
|
|
css = {"stylelint"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-08-04 22:21:44 +02:00
|
|
|
|
|
|
|
-- nvim-autoclose & nvim-compe compatibility
|
2022-03-10 20:34:06 +01:00
|
|
|
local map = vim.api.nvim_set_keymap
|
2021-08-04 22:21:44 +02:00
|
|
|
local npairs = require('nvim-autopairs')
|
|
|
|
|
|
|
|
npairs.setup({
|
|
|
|
check_ts = true,
|
|
|
|
})
|
|
|
|
|
|
|
|
_G.MUtils= {}
|
|
|
|
|
|
|
|
vim.g.completion_confirm_key = ""
|
|
|
|
MUtils.completion_confirm=function()
|
|
|
|
if vim.fn.pumvisible() ~= 0 then
|
|
|
|
if vim.fn.complete_info()["selected"] ~= -1 then
|
|
|
|
return vim.fn["compe#confirm"](npairs.esc("<cr>"))
|
|
|
|
else
|
|
|
|
return npairs.esc("<cr>")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return npairs.autopairs_cr()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-10 20:34:06 +01:00
|
|
|
map('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
|