This commit is contained in:
ksyasuda 2022-02-10 00:43:30 -08:00
parent d2499c127a
commit d25dcabc9e
5 changed files with 271 additions and 40 deletions

View File

@ -1,5 +1,5 @@
syntax enable " syntax enable
filetype plugin on " filetype plugin on
set noshowmode "disable default vim insert text at bottom set noshowmode "disable default vim insert text at bottom
set laststatus=2 set laststatus=2
set number set number
@ -63,8 +63,6 @@ Plug 'tpope/vim-surround'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' Plug 'junegunn/fzf.vim'
Plug 'itchyny/lightline.vim' Plug 'itchyny/lightline.vim'
Plug 'dense-analysis/ale'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'wakatime/vim-wakatime' Plug 'wakatime/vim-wakatime'
Plug 'voldikss/vim-floaterm' Plug 'voldikss/vim-floaterm'
Plug 'pechorin/any-jump.vim' Plug 'pechorin/any-jump.vim'
@ -75,6 +73,9 @@ Plug 'sheerun/vim-polyglot'
Plug 'maximbaz/lightline-ale' Plug 'maximbaz/lightline-ale'
Plug 'osyo-manga/vim-over' Plug 'osyo-manga/vim-over'
" Plug 'dense-analysis/ale'
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
if has('nvim') if has('nvim')
Plug 'akinsho/bufferline.nvim' Plug 'akinsho/bufferline.nvim'
" Plug 'chentau/marks.nvim' " Plug 'chentau/marks.nvim'
@ -91,6 +92,13 @@ if has('nvim')
Plug 'ray-x/lsp_signature.nvim' Plug 'ray-x/lsp_signature.nvim'
Plug 'simrat39/symbols-outline.nvim' Plug 'simrat39/symbols-outline.nvim'
Plug 'jose-elias-alvarez/null-ls.nvim' Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'onsails/lspkind-nvim'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'L3MON4D3/LuaSnip'
Plug 'NTBBloodbath/doom-one.nvim' Plug 'NTBBloodbath/doom-one.nvim'
Plug 'Mofiqul/dracula.nvim' Plug 'Mofiqul/dracula.nvim'
@ -120,10 +128,13 @@ if has('nvim')
source ~/.config/nvim/plugin-confs/treesitter.lua source ~/.config/nvim/plugin-confs/treesitter.lua
source ~/.config/nvim/plugin-confs/neogit.lua source ~/.config/nvim/plugin-confs/neogit.lua
" source ~/.config/nvim/plugin-confs/lspconfig.lua set completeopt=menu,menuone,noselect
source ~/.config/nvim/plugin-confs/lspconfig.lua
source ~/.config/nvim/plugin-confs/lsp-signature.lua source ~/.config/nvim/plugin-confs/lsp-signature.lua
source ~/.config/nvim/symbols-outline.lua source ~/.config/nvim/plugin-confs/symbols-outline.lua
" source ~/.config/nvim/null-ls.lua source ~/.config/nvim/plugin-confs/null-ls.lua
source ~/.config/nvim/plugin-confs/nvim-cmp.lua
source ~/.config/nvim/plugin-confs/lsp-kind.lua
source ~/.vim/plugin-confs/fzf.vim source ~/.vim/plugin-confs/fzf.vim
source ~/.vim/plugin-confs/vim-closetag.vim source ~/.vim/plugin-confs/vim-closetag.vim
@ -131,9 +142,6 @@ if has('nvim')
source ~/.vim/plugin-confs/lightline.vim source ~/.vim/plugin-confs/lightline.vim
source ~/.vim/plugin-confs/floaterm.vim source ~/.vim/plugin-confs/floaterm.vim
source ~/.vim/plugin-confs/ale.vim
source ~/.vim/plugin-confs/coc.vim
source ~/.config/nvim/plugin-confs/doomone.lua source ~/.config/nvim/plugin-confs/doomone.lua
source ~/.config/nvim/plugin-confs/dracula.lua source ~/.config/nvim/plugin-confs/dracula.lua
source ~/.config/nvim/plugin-confs/github-theme.lua source ~/.config/nvim/plugin-confs/github-theme.lua

View File

View File

@ -1,3 +1,63 @@
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
if client.resolved_capabilities.document_highlight then
vim.cmd [[
hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd! CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd! CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]]
end
end
vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]]
vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]
local border = {
{"🭽", "FloatBorder"},
{"", "FloatBorder"},
{"🭾", "FloatBorder"},
{"", "FloatBorder"},
{"🭿", "FloatBorder"},
{"", "FloatBorder"},
{"🭼", "FloatBorder"},
{"", "FloatBorder"},
}
local handlers = {
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border}),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {border = border }),
}
local DEFAULT_SETTINGS = { local DEFAULT_SETTINGS = {
ui = { ui = {
icons = { icons = {
@ -32,6 +92,8 @@ local DEFAULT_SETTINGS = {
-- Example: { "--proxy", "https://proxyserver" } -- Example: { "--proxy", "https://proxyserver" }
install_args = {}, install_args = {},
}, },
on_attach = on_attach,
-- handlers=handlers,
-- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
-- debugging issues with server installations. -- debugging issues with server installations.
@ -42,6 +104,40 @@ local DEFAULT_SETTINGS = {
max_concurrent_installers = 4, max_concurrent_installers = 4,
} }
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = true,
update_in_insert = false,
severity_sort = false,
})
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
function PrintDiagnostics(opts, bufnr, line_nr, client_id)
bufnr = bufnr or 0
line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1)
opts = opts or {['lnum'] = line_nr}
local line_diagnostics = vim.diagnostic.get(bufnr, opts)
if vim.tbl_isempty(line_diagnostics) then return end
local diagnostic_message = ""
for i, diagnostic in ipairs(line_diagnostics) do
diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "")
print(diagnostic_message)
if i ~= #line_diagnostics then
diagnostic_message = diagnostic_message .. "\n"
end
end
vim.api.nvim_echo({{diagnostic_message, "Normal"}}, false, {})
end
-- vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]]
local lsp_installer = require("nvim-lsp-installer") local lsp_installer = require("nvim-lsp-installer")
@ -60,3 +156,16 @@ lsp_installer.on_server_ready(function(server)
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(DEFAULT_SETTINGS) server:setup(DEFAULT_SETTINGS)
end) end)
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
-- local servers = { 'pyright', 'bashls', 'sqlls' }
-- for _, lsp in pairs(servers) do
-- require('lspconfig')[lsp].setup {
-- on_attach = on_attach,
-- flags = {
-- -- This will be the default in neovim 0.7+
-- debounce_text_changes = 150,
-- }
-- }
-- end

View File

@ -9,7 +9,20 @@ require("null-ls").setup({
require("null-ls").builtins.formatting.shfmt.with({ require("null-ls").builtins.formatting.shfmt.with({
extra_args = { "-i", "4", "-ci", "-sr" } extra_args = { "-i", "4", "-ci", "-sr" }
}), }),
require("null-ls").builtins.diagnostics.shellcheck.with({
extra_args = { "-s", "bash", "-o", "check-extra-masked-returns, check-set-e-suppressed, check-unassigned-uppercase, deprecate-which, quote-safe-variables" }
})
}, },
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
vim.cmd([[
augroup LspFormatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
augroup END
]])
end
end,
}) })
local markdownlint = { local markdownlint = {
@ -50,37 +63,37 @@ local markdownlint = {
}), }),
} }
local shellcheck = { -- local shellcheck = {
method = null_ls.methods.DIAGNOSTICS, -- method = null_ls.methods.DIAGNOSTICS,
filetypes = { "sh", "bash", "zsh", "fish" }, -- filetypes = { "sh", "bash", "zsh", "fish" },
generator = null_ls.generator({ -- generator = null_ls.generator({
command = "shellcheck", -- command = "shellcheck",
args = { "-S", "info", "-s", "bash", "-o", "all", "-e", "2250" }, -- args = { "-s", "bash", "-o", "all", "-e", "2250" },
from_stderr = true, -- from_stderr = true,
format = "line", -- format = "line",
check_exit_code = function(code, stderr) -- check_exit_code = function(code, stderr)
local success = code <= 1 -- local success = code <= 1
if not success then -- if not success then
-- can be noisy for things that run often (e.g. diagnostics), but can -- -- can be noisy for things that run often (e.g. diagnostics), but can
-- be useful for things that run on demand (e.g. formatting) -- -- be useful for things that run on demand (e.g. formatting)
print(stderr) -- print(stderr)
end -- end
return success -- return success
end, -- end,
on_output = helpers.diagnostics.from_patterns({ -- on_output = helpers.diagnostics.from_patterns({
{ -- {
pattern = [[:(%d+):(%d+) [%w-/]+ (.*)]], -- pattern = [[:(%d+):(%d+) [%w-/]+ (.*)]],
groups = { "row", "col", "message" }, -- groups = { "row", "col", "message" },
}, -- },
{ -- {
pattern = [[:(%d+) [%w-/]+ (.*)]], -- pattern = [[:(%d+) [%w-/]+ (.*)]],
groups = { "row", "message" }, -- groups = { "row", "message" },
}, -- },
}), -- }),
}), -- }),
} -- }
null_ls.register(markdownlint) null_ls.register(markdownlint)
null_ls.register(shellcheck) -- null_ls.register(shellcheck)

View File

@ -0,0 +1,101 @@
-- Setup nvim-cmp.
local cmp = require'cmp'
local lspkind = require('lspkind')
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- luasnip setup
local luasnip = require 'luasnip'
cmp.setup({
snippet = {
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
capabilities = capabilities,
-- mapping = {
-- ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
-- ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
-- ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
-- ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
-- ['<C-e>'] = cmp.mapping({
-- i = cmp.mapping.abort(),
-- c = cmp.mapping.close(),
-- }),
-- ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
-- },
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
formatting = {
format = lspkind.cmp_format({
mode = 'symbol', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
-- The function below will be called before any actual modifications from lspkind
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
-- before = function (entry, vim_item)
-- ...
-- return vim_item
-- end
})
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
{ name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Setup lspconfig.
-- local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
-- require('lspconfig')['bashls'].setup {
-- capabilities = capabilities
-- }
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local lspconfig = require('lspconfig')
local servers = { 'bashls', 'pyright', 'sqlls', 'jsonls', 'yamlls', 'vimls', 'dotls', 'dockerls' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end