mirror of
https://github.com/kogakure/dotfiles.git
synced 2026-02-03 20:25:30 +00:00
chore(vim): add Language Server Protocol plugins and configuration
This commit is contained in:
@@ -10,6 +10,9 @@ source ~/.config/nvim/plugins/dashboard.vim
|
||||
source ~/.config/nvim/plugins/gitsigns.lua
|
||||
source ~/.config/nvim/plugins/goyo.vim
|
||||
source ~/.config/nvim/plugins/harpoon.lua
|
||||
source ~/.config/nvim/plugins/lsp-config.lua
|
||||
source ~/.config/nvim/plugins/lsp-installer.lua
|
||||
source ~/.config/nvim/plugins/lspkind.lua
|
||||
source ~/.config/nvim/plugins/lualine.lua
|
||||
source ~/.config/nvim/plugins/neoscroll.lua
|
||||
source ~/.config/nvim/plugins/prettier.vim
|
||||
|
||||
@@ -16,6 +16,13 @@ Plug 'glepnir/dashboard-nvim'
|
||||
" Color Themes
|
||||
Plug 'chriskempson/base16-vim'
|
||||
|
||||
" Language Server Protocol
|
||||
Plug 'neovim/nvim-lspconfig'
|
||||
Plug 'williamboman/nvim-lsp-installer'
|
||||
Plug 'folke/trouble.nvim'
|
||||
Plug 'onsails/lspkind-nvim'
|
||||
Plug 'creativenull/diagnosticls-configs-nvim'
|
||||
|
||||
" Completion
|
||||
Plug 'SirVer/ultisnips'
|
||||
Plug 'honza/vim-snippets'
|
||||
|
||||
53
nvim/plugins/diagnosticls-configs.lua
Normal file
53
nvim/plugins/diagnosticls-configs.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
-- diagnosticls-configs-nvim
|
||||
-- https://github.com/creativenull/diagnosticls-configs-nvim#setup
|
||||
|
||||
local status, dlsconfig = pcall(require, 'diagnosticls-configs')
|
||||
if (not status) then return end
|
||||
|
||||
-- npm install -g diagnostic-languageserver eslint_d prettier_d_slim prettier
|
||||
local eslint = require('diagnosticls-configs.linters.eslint')
|
||||
local standard = require('diagnosticls-configs.linters.standard')
|
||||
local prettier = require('diagnosticls-configs.formatters.prettier')
|
||||
local prettier_standard = require('diagnosticls-configs.formatters.prettier_standard')
|
||||
|
||||
local function on_attach(client)
|
||||
print('Attached to ' .. client.name)
|
||||
end
|
||||
|
||||
dlsconfig.init({
|
||||
default_config = true,
|
||||
format = true,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
|
||||
prettier.requiredFiles = {
|
||||
'.prettierrc',
|
||||
'.prettierrc.json',
|
||||
'.prettierrc.toml',
|
||||
'.prettierrc.json',
|
||||
'.prettierrc.yml',
|
||||
'.prettierrc.yaml',
|
||||
'.prettierrc.json5',
|
||||
'.prettierrc.js',
|
||||
'.prettierrc.cjs',
|
||||
'prettier.config.js',
|
||||
'prettier.config.cjs',
|
||||
}
|
||||
|
||||
dlsconfig.setup({
|
||||
['javascript'] = {
|
||||
linter = { eslint, standard },
|
||||
formatter = { prettier, prettier_standard },
|
||||
},
|
||||
['javascriptreact'] = {
|
||||
linter = { eslint, standard },
|
||||
formatter = { prettier, prettier_standard }
|
||||
},
|
||||
['css'] = {
|
||||
formatter = prettier
|
||||
},
|
||||
['html'] = {
|
||||
formatter = prettier
|
||||
},
|
||||
})
|
||||
|
||||
23
nvim/plugins/lsp-config.lua
Normal file
23
nvim/plugins/lsp-config.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- lspconfig
|
||||
-- https://github.com/neovim/nvim-lspconfig
|
||||
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
vim.api.nvim_set_keymap('n', 'gD', [['<Cmd>lua vim.lsp.buf.declaration()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'gd', [['<Cmd>lua vim.lsp.buf.definition()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'K', [['<Cmd>lua vim.lsp.buf.hover()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'gi', [['<cmd>lua vim.lsp.buf.implementation()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<C-k>', [['<cmd>lua vim.lsp.buf.signature_help()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>wa', [['<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>wr', [['<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>wl', [['<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>D', [['<cmd>lua vim.lsp.buf.type_definition()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>rn', [['<cmd>lua vim.lsp.buf.rename()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'gr', [['<cmd>lua vim.lsp.buf.references()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>e', [['<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'Ä', [['<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'ä', [['<cmd>lua vim.lsp.diagnostic.goto_next()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', '<leader>q', [['<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>']], opts)
|
||||
vim.api.nvim_set_keymap('n', 'g0', [[<Cmd>lua vim.lsp.buf.document_symbol()<CR>]], opts)
|
||||
vim.api.nvim_set_keymap('n', 'gW', [[<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>]], opts)
|
||||
vim.api.nvim_set_keymap('n', 'ga', [[<Cmd>lua vim.lsp.buf.code_action()<CR>]], opts)
|
||||
78
nvim/plugins/lsp-installer.lua
Normal file
78
nvim/plugins/lsp-installer.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
-- nvim-lsp-installer
|
||||
-- https://github.com/williamboman/nvim-lsp-installer
|
||||
|
||||
local status, lsp_installer = pcall(require, 'nvim-lsp-installer')
|
||||
if (not status) then return end
|
||||
|
||||
local servers = {
|
||||
bashls = {},
|
||||
cssls = {},
|
||||
diagnosticls = {},
|
||||
dockerls = {},
|
||||
emmet_ls = {},
|
||||
eslint = {},
|
||||
graphql = {},
|
||||
html = {},
|
||||
jsonls = {},
|
||||
pyright = {},
|
||||
sumneko_lua = {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = {"vim"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
stylelint_lsp = {},
|
||||
svelte = {},
|
||||
tailwindcss = {},
|
||||
tsserver = {},
|
||||
vimls = {},
|
||||
vuels = {},
|
||||
yamlls = {},
|
||||
}
|
||||
|
||||
lsp_installer.settings({
|
||||
ui = {
|
||||
icons = {
|
||||
server_installed = "✓",
|
||||
server_pending = "➜",
|
||||
server_uninstalled = "✗"
|
||||
},
|
||||
},
|
||||
|
||||
max_concurrent_installers = 4,
|
||||
})
|
||||
|
||||
-- Register a handler that will be called for all installed servers.
|
||||
lsp_installer.on_server_ready(function(server)
|
||||
local opts = {
|
||||
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
}
|
||||
|
||||
if servers[server.name] then
|
||||
opts = servers[server.name]
|
||||
end
|
||||
|
||||
-- This setup() function is exactly the same as lspconfig's setup function.
|
||||
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
||||
server:setup(opts)
|
||||
|
||||
vim.cmd([[do User LspAttachBuffers]])
|
||||
end)
|
||||
|
||||
--- Global function to install servers automatically
|
||||
function _G.lsp_install_sync()
|
||||
local lsp_installer_servers = require("nvim-lsp-installer.servers")
|
||||
|
||||
local requested = {}
|
||||
for server_name, _ in pairs(servers) do
|
||||
local ok, server = lsp_installer_servers.get_server(server_name)
|
||||
if ok and not server:is_installed() then
|
||||
table.insert(requested, server_name)
|
||||
end
|
||||
end
|
||||
|
||||
lsp_installer.install_sync(requested)
|
||||
end
|
||||
7
nvim/plugins/lspkind.lua
Normal file
7
nvim/plugins/lspkind.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
-- lspkind-nvim
|
||||
-- https://github.com/onsails/lspkind-nvim
|
||||
|
||||
local status, lspkind = pcall(require, 'lspkind')
|
||||
if (not status) then return end
|
||||
|
||||
lspkind.init({})
|
||||
12
nvim/plugins/trouble.lua
Normal file
12
nvim/plugins/trouble.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- Trouble
|
||||
-- https://github.com/folke/trouble.nvim
|
||||
|
||||
local status, trouble = pcall(require, 'trouble')
|
||||
if (not status) then return end
|
||||
|
||||
trouble.setup()
|
||||
|
||||
--- Mappings
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<leader>tt', [[<Cmd>:TroubleToggle<CR>]], opts)
|
||||
Reference in New Issue
Block a user