mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-12-12 17:18:22 -05:00
239 lines
8.1 KiB
Lua
239 lines
8.1 KiB
Lua
local M = {}
|
|
|
|
function M.lsp_conf()
|
|
local lspconf = require('lspconfig')
|
|
|
|
local on_attach = function(client, bufnr)
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
local function buf_set_keymap(...)
|
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
end
|
|
|
|
local opts = {noremap = true, silent = true}
|
|
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>lx', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>la', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>lr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>lw', '<Cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
buf_set_keymap('n', '<leader>ld', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>ln', '<Cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
buf_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>le', '<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
|
buf_set_keymap('n', '[d', '<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
|
buf_set_keymap('n', ']d', '<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
|
buf_set_keymap('n', '<leader>ll', '<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
|
|
|
if client.resolved_capabilities.document_formatting then
|
|
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
elseif client.resolved_capabilities.document_range_formatting then
|
|
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})<CR>', opts)
|
|
end
|
|
|
|
-- Attach lsp_signature.nvim
|
|
require('lsp_signature').on_attach({
|
|
bind = true, -- This is mandatory, otherwise border config doesn't work
|
|
floating_window = true,
|
|
fix_pos = true,
|
|
hint_prefix = '🐬 ',
|
|
transpancy = 5,
|
|
handler_opts = {border = 'none'},
|
|
zindex = 50, -- set to 200 to make the float window on top of others
|
|
toggle_key = '<M-x>'
|
|
}, bufnr)
|
|
end
|
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities.textDocument.completion.completionItem.documentationFormat = {'markdown', 'plaintext'}
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
|
capabilities.textDocument.completion.completionItem.preselectSupport = true
|
|
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
|
|
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
|
|
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
|
|
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
|
|
capabilities.textDocument.completion.completionItem.tagSupport = {valueSet = {1}}
|
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
|
properties = {
|
|
'documentation',
|
|
'detail',
|
|
'additionalTextEdits',
|
|
},
|
|
}
|
|
|
|
---------------------------
|
|
-- Server configurations --
|
|
---------------------------
|
|
-- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
|
|
|
|
-- C/C++
|
|
lspconf.clangd.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
filetypes = {'c', 'cpp'},
|
|
cmd = {
|
|
'clangd',
|
|
'-j=2',
|
|
'--background-index',
|
|
'--clang-tidy',
|
|
'--completion-style=detailed',
|
|
'--pch-storage=memory',
|
|
'--header-insertion=iwyu',
|
|
'--header-insertion=decorators'
|
|
}
|
|
}
|
|
|
|
-- Lua
|
|
local runtime_path = vim.split(package.path, ';')
|
|
table.insert(runtime_path, 'lua/?.lua')
|
|
table.insert(runtime_path, 'lua/?/init.lua')
|
|
|
|
lspconf.sumneko_lua.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = {
|
|
vim.fn.stdpath('data') .. '/lsp/lua-language-server/bin/Linux/lua-language-server',
|
|
'-E',
|
|
vim.fn.stdpath('data') .. '/lsp/lua-language-server/main.lua'
|
|
},
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = {
|
|
globals = {'vim'}
|
|
},
|
|
runtime = {
|
|
version = 'LuaJIT',
|
|
path = runtime_path
|
|
},
|
|
workspace = {
|
|
library = vim.api.nvim_get_runtime_file('', true),
|
|
maxPreload = 100000,
|
|
preloadFileSize = 100000
|
|
},
|
|
telemetry = {
|
|
enable = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
-- Go
|
|
lspconf.gopls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = {'gopls', '--remote=auto'},
|
|
init_options = {
|
|
usePlaceholders = true,
|
|
completeUnimported = true
|
|
}
|
|
}
|
|
|
|
-- Emmet
|
|
if not lspconf.emmet_ls then
|
|
require('lspconfig/configs').emmet_ls = {
|
|
default_config = {
|
|
cmd = {'emmet-ls', '--stdio'},
|
|
filetypes = {'html', 'css'},
|
|
root_dir = function(fname)
|
|
return vim.loop.cwd()
|
|
end,
|
|
settings = {}
|
|
}
|
|
}
|
|
end
|
|
lspconf.emmet_ls.setup {capabilities = capabilities}
|
|
|
|
-- Others
|
|
local servers = {
|
|
'dockerls',
|
|
'bashls',
|
|
'pyright',
|
|
'tsserver',
|
|
'html',
|
|
'jsonls',
|
|
'cmake',
|
|
'sqls',
|
|
'rust_analyzer'
|
|
}
|
|
for _, server in ipairs(servers) do
|
|
lspconf[server].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities
|
|
}
|
|
end
|
|
|
|
-- Replace the default lsp diagnostic letters with prettier symbols
|
|
vim.fn.sign_define('LspDiagnosticsSignError', {text = ''})
|
|
vim.fn.sign_define('LspDiagnosticsSignWarning', {text = ''})
|
|
vim.fn.sign_define('LspDiagnosticsSignInformation', {text = ''})
|
|
vim.fn.sign_define('LspDiagnosticsSignHint', {text = ''})
|
|
end
|
|
|
|
function M.sqls_conf()
|
|
require('sqls').setup {
|
|
picker = 'telescope'
|
|
}
|
|
end
|
|
|
|
function M.trouble_conf()
|
|
require('trouble').setup {
|
|
mode = 'lsp_workspace_diagnostics',
|
|
fold_open = ' ',
|
|
fold_closed = '',
|
|
action_keys = {
|
|
open_split = {'<c-h>'},
|
|
open_vsplit = {'<c-v>'},
|
|
open_tab = {'<c-t>'}
|
|
},
|
|
signs = {
|
|
error = '',
|
|
warning = '',
|
|
hint = '',
|
|
information = '',
|
|
other = ''
|
|
}
|
|
}
|
|
end
|
|
|
|
function M.outline_conf()
|
|
vim.g.symbols_outline = {
|
|
highlight_hovered_item = false,
|
|
show_guides = false
|
|
}
|
|
end
|
|
|
|
function M.lint_conf()
|
|
require('lint').linters_by_ft = {
|
|
markdown = {'vale', 'markdownlint', 'languagetool'},
|
|
tex = {'vale', 'languagetool'},
|
|
vim = {'vint'},
|
|
-- lua = {'luacheck'},
|
|
c = {'clangtidy', 'cppcheck'},
|
|
cpp = {'clangtidy', 'clazy', 'cppcheck'},
|
|
python = {'pylint', 'flake8', 'pycodestyle'},
|
|
go = {'revive', 'golangcilint'},
|
|
sh = {'shellcheck'},
|
|
bash = {'shellcheck'},
|
|
zsh = {'shellcheck'},
|
|
html = {'tidy', 'stylelint'},
|
|
css = {'stylelint'},
|
|
scss = {'stylelint'},
|
|
sass = {'stylelint'},
|
|
javascript = {'eslint', 'stylelint'}
|
|
}
|
|
-- TODO: custom cmds for linters installed with pip (using virtualenv)
|
|
-- vint, pylint, flake8, pycodestyle, codespell
|
|
vim.cmd [[ au BufRead,BufWritePost * lua require('lint').try_lint() ]]
|
|
end
|
|
|
|
function M.dap_conf()
|
|
end
|
|
|
|
function M.dapui_conf()
|
|
end
|
|
|
|
return M
|