mirror of
https://github.com/d0zingcat/dotfiles.git
synced 2026-05-13 23:16:44 +00:00
use nvim-lsp-setup
This commit is contained in:
@@ -137,10 +137,10 @@ map('n', '<Leader>v', '"+p')
|
||||
map('n', '<leader>rv', ':source $MYVIMRC<CR>')
|
||||
|
||||
-- insert mode mapping
|
||||
map('i', '<c-b>', '<c-o>b')
|
||||
map('i', '<c-f>', '<c-o>l')
|
||||
map('i', '<c-j>', '<c-o>j')
|
||||
map('i', '<c-k>', '<c-o>k')
|
||||
--map('i', '<c-b>', '<c-o>b')
|
||||
--map('i', '<c-f>', '<c-o>l')
|
||||
--map('i', '<c-j>', '<c-o>j')
|
||||
--map('i', '<c-k>', '<c-o>k')
|
||||
|
||||
map('n', '<F1>', '<nop>')
|
||||
map('i', '<F1>', '<nop>')
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
return {
|
||||
filetypes = { 'yaml', 'yml' },
|
||||
settings = {
|
||||
yaml = {
|
||||
schemas = {
|
||||
['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*',
|
||||
Kubernetes = { '/*k8s.yaml', '/*k8s.yml' },
|
||||
--['https://raw.githubusercontent.com/instrumenta/kubernetes-json-schema/master/v1.18.0-standalone-strict/all.json'] = '/*.k8s.yaml',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
local lsp = vim.lsp
|
||||
local api = vim.api
|
||||
local cmd = vim.cmd
|
||||
|
||||
local lsp_installer = require('nvim-lsp-installer')
|
||||
-- Include the servers you want to have installed by default below
|
||||
local servers = {
|
||||
'bashls',
|
||||
'pylsp',
|
||||
'yamlls',
|
||||
'eslint',
|
||||
'jsonls',
|
||||
'sumneko_lua',
|
||||
'rust_analyzer',
|
||||
'clangd',
|
||||
'gopls',
|
||||
'tsserver',
|
||||
'prosemd_lsp',
|
||||
}
|
||||
|
||||
for _, name in pairs(servers) do
|
||||
local server_is_found, server = lsp_installer.get_server(name)
|
||||
if server_is_found and not server:is_installed() then
|
||||
print('Installing ' .. name)
|
||||
server:install()
|
||||
end
|
||||
end
|
||||
|
||||
-- lspconfig && lspinstaller
|
||||
local on_attach = function(client, bufnr)
|
||||
local function buf_set_keymap(...)
|
||||
api.nvim_buf_set_keymap(bufnr, ...)
|
||||
end
|
||||
local function buf_set_option(...)
|
||||
api.nvim_buf_set_option(bufnr, ...)
|
||||
end
|
||||
--require "lsp_signature".on_attach()
|
||||
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
--buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap = true, silent = true }
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
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', '<C-y>', '<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', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
buf_set_keymap('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
|
||||
buf_set_keymap('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
|
||||
buf_set_keymap('n', 'go', '<cmd>Telescope lsp_document_symbols<CR>', opts)
|
||||
buf_set_keymap('n', 'gO', '<cmd>Telescope lsp_workspace_symbols<CR>', opts)
|
||||
--buf_set_keymap("n", "<space>e", "<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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||
--buf_set_keymap('i', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||
|
||||
if client.resolved_capabilities.document_formatting then
|
||||
vim.cmd([[
|
||||
augroup Format
|
||||
au! * <buffer>
|
||||
au BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 1000)
|
||||
augroup END
|
||||
]])
|
||||
end
|
||||
end
|
||||
|
||||
local capabilities = lsp.protocol.make_client_capabilities()
|
||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
||||
|
||||
-- Register a handler that will be called for all installed servers.
|
||||
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
|
||||
lsp_installer.on_server_ready(function(server)
|
||||
local opts = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
}
|
||||
|
||||
if server.name == 'sumneko_lua' then
|
||||
local luadev = require('lua-dev').setup({
|
||||
lspconfig = {
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
opts = vim.tbl_deep_extend('force', opts, luadev)
|
||||
end
|
||||
|
||||
if server.name == 'yamlls' then
|
||||
--local yamlls_opts = {
|
||||
--settings = {
|
||||
--yaml = {
|
||||
--filetypes = { 'yaml', 'yml' },
|
||||
--schemaStore = {
|
||||
--enable = true,
|
||||
--url = 'https://www.schemastore.org/api/json/catalog.json',
|
||||
--},
|
||||
--validate = false,
|
||||
--schemas = {
|
||||
--['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*',
|
||||
--kubernetes = '/*.k8s.yaml',
|
||||
--},
|
||||
--},
|
||||
--},
|
||||
--}
|
||||
local conf = require(string.format('config.lsp_servers.%s', server.name))
|
||||
opts = vim.tbl_deep_extend('force', opts, conf)
|
||||
end
|
||||
if server.name == 'rust_analyzer' then
|
||||
-- Initialize the LSP via rust-tools instead
|
||||
require('rust-tools').setup({
|
||||
-- The "server" property provided in rust-tools setup function are the
|
||||
-- settings rust-tools will provide to lspconfig during init. --
|
||||
-- We merge the necessary settings from nvim-lsp-installer (server:get_default_options())
|
||||
-- with the user's own settings (opts).
|
||||
server = vim.tbl_deep_extend('force', server:get_default_options(), opts),
|
||||
})
|
||||
server:attach_buffers()
|
||||
-- Only if standalone support is needed
|
||||
--require('rust-tools').start_standalone_if_required()
|
||||
else
|
||||
-- (optional) Customize the options passed to the server
|
||||
-- if server.name == "tsserver" then
|
||||
-- opts.root_dir = function() ... end
|
||||
-- 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)
|
||||
end
|
||||
end)
|
||||
|
||||
local null_ls = require('null-ls')
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_ls.builtins.formatting.stylua.with({
|
||||
extra_args = { '--config-path', vim.fn.expand('~/.config/stylua.toml') },
|
||||
}),
|
||||
null_ls.builtins.formatting.shfmt,
|
||||
},
|
||||
on_attach = on_attach,
|
||||
})
|
||||
74
nvim/lua/config/nvim-lsp-setup.lua
Normal file
74
nvim/lua/config/nvim-lsp-setup.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
require('nvim-lsp-setup').setup({
|
||||
default_mappings = true,
|
||||
-- Default mappings
|
||||
-- gD = 'lua vim.lsp.buf.declaration()',
|
||||
-- gd = 'lua vim.lsp.buf.definition()',
|
||||
-- gt = 'lua vim.lsp.buf.type_definition()',
|
||||
-- gi = 'lua vim.lsp.buf.implementation()',
|
||||
-- gr = 'lua vim.lsp.buf.references()',
|
||||
-- K = 'lua vim.lsp.buf.hover()',
|
||||
-- ['<C-k>'] = 'lua vim.lsp.buf.signature_help()',
|
||||
-- ['<space>rn'] = 'lua vim.lsp.buf.rename()',
|
||||
-- ['<space>ca'] = 'lua vim.lsp.buf.code_action()',
|
||||
-- ['<space>f'] = 'lua vim.lsp.buf.formatting()',
|
||||
-- ['<space>e'] = 'lua vim.lsp.diagnostic.show_line_diagnostics()',
|
||||
-- ['[d'] = 'lua vim.lsp.diagnostic.goto_prev()',
|
||||
-- [']d'] = 'lua vim.lsp.diagnostic.goto_next()',
|
||||
mappings = {
|
||||
-- Example mappings for telescope pickers
|
||||
-- gd = 'lua require"telescope.builtin".lsp_definitions()',
|
||||
-- gi = 'lua require"telescope.builtin".lsp_implementations()',
|
||||
-- gr = 'lua require"telescope.builtin".lsp_references()',
|
||||
},
|
||||
-- Global on_attach
|
||||
-- on_attach = function(client, bufnr) {
|
||||
-- utils.format_on_save(client)
|
||||
-- },
|
||||
servers = {
|
||||
-- Automatically install lsp server
|
||||
-- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
||||
bashls = {},
|
||||
yamlls = {
|
||||
filetypes = { 'yaml', 'yml' },
|
||||
settings = {
|
||||
yaml = {
|
||||
schemas = {
|
||||
['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*',
|
||||
Kubernetes = { '/*k8s.yaml', '/*k8s.yml' },
|
||||
--['https://raw.githubusercontent.com/instrumenta/kubernetes-json-schema/master/v1.18.0-standalone-strict/all.json'] = '/*.k8s.yaml',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
eslint = {},
|
||||
jsonls = {},
|
||||
sumneko_lua = {},
|
||||
clangd = {},
|
||||
gopls = {},
|
||||
tsserver = {},
|
||||
prosemd_lsp = {},
|
||||
|
||||
pylsp = {},
|
||||
rust_analyzer = {
|
||||
settings = {
|
||||
['rust-analyzer'] = {
|
||||
cargo = {
|
||||
loadOutDirsFromCheck = true,
|
||||
},
|
||||
procMacro = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
-- Setup sumneko_lua with lua-dev
|
||||
sumneko_lua = require('lua-dev').setup({
|
||||
lspconfig = {
|
||||
on_attach = function(client, _)
|
||||
-- Disable formatting
|
||||
require('nvim-lsp-setup.utils').disable_formatting(client)
|
||||
end,
|
||||
},
|
||||
}),
|
||||
},
|
||||
})
|
||||
@@ -36,18 +36,6 @@ return require('packer').startup(function(use)
|
||||
})
|
||||
end,
|
||||
})
|
||||
--use({
|
||||
--'folke/trouble.nvim',
|
||||
--config = function()
|
||||
--require('trouble').setup({})
|
||||
--end,
|
||||
--})
|
||||
--use({
|
||||
--'sindrets/diffview.nvim',
|
||||
--config = function()
|
||||
--require('diffview').setup({})
|
||||
--end,
|
||||
--})
|
||||
use({
|
||||
'lukas-reineke/indent-blankline.nvim',
|
||||
config = function()
|
||||
@@ -175,42 +163,36 @@ return require('packer').startup(function(use)
|
||||
require('config.nvim_hop')
|
||||
end,
|
||||
})
|
||||
--use {
|
||||
--"ray-x/lsp_signature.nvim",
|
||||
--config = function()
|
||||
--require "lsp_signature".setup {
|
||||
--transpancy = 10,
|
||||
--hint_prefix = "😼",
|
||||
---- zindex = 50,
|
||||
--}
|
||||
--end
|
||||
--}
|
||||
use({
|
||||
'preservim/tagbar',
|
||||
config = function()
|
||||
require('config.tagbar')
|
||||
end,
|
||||
})
|
||||
--use {
|
||||
--"liuchengxu/vista.vim",
|
||||
--config = function()
|
||||
--require "config.vista"
|
||||
--end
|
||||
--}
|
||||
|
||||
-- LANGUAGES
|
||||
use({
|
||||
'neovim/nvim-lspconfig',
|
||||
'Junnplus/nvim-lsp-setup',
|
||||
config = function()
|
||||
require('config.nvim-lsp-setup')
|
||||
end,
|
||||
requires = {
|
||||
'neovim/nvim-lspconfig',
|
||||
'williamboman/nvim-lsp-installer',
|
||||
},
|
||||
})
|
||||
use({
|
||||
'jose-elias-alvarez/null-ls.nvim',
|
||||
})
|
||||
use({
|
||||
'williamboman/nvim-lsp-installer',
|
||||
config = function()
|
||||
require('config.nvim-lsp-installer')
|
||||
end,
|
||||
})
|
||||
--use({
|
||||
--'neovim/nvim-lspconfig',
|
||||
--})
|
||||
--use({
|
||||
--'williamboman/nvim-lsp-installer',
|
||||
--config = function()
|
||||
--require('config.nvim-lsp-installer')
|
||||
--end,
|
||||
--})
|
||||
-- k8s
|
||||
use('andrewstuart/vim-kubernetes')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user