nvim: adapt config for neovim 0.6.0

This commit is contained in:
Hoang Nguyen 2021-12-01 20:49:27 +07:00
parent 1cc8d84e41
commit f71b6d1c94
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
10 changed files with 189 additions and 165 deletions

View File

@ -7,8 +7,6 @@ local opts = {noremap = true, silent = true}
-- Globally defined mappings --
-------------------------------
local normal_mappings = {
-- Better Y
Y = {'y$', 'Yank to eol'},
-- Easier start and end of line
H = {'^', 'Start of the line'},
L = {'$', 'End of the line'},

View File

@ -43,6 +43,7 @@ function M.cmp()
}
},
formatting = {
-- fields = {'kind', 'abbr', 'menu'},
format = function(entry, vim_item)
local lspkind_icons = {
Text = '',

View File

@ -17,7 +17,7 @@ function M.signature()
end
function M.saga()
require('lspsaga').init_lsp_saga {
require('lspsaga').setup {
debug = false,
use_saga_diagnostic_sign = true,
-- diagnostic sign
@ -56,7 +56,8 @@ function M.saga()
definition_preview_icon = '',
border_style = 'single',
rename_prompt_prefix = '',
server_filetype_map = {}
server_filetype_map = {},
diagnostic_prefix_format = '%d. '
}
end
@ -122,10 +123,10 @@ function M.todo_comments()
exclude = {'org'} -- list of file types to exclude highlighting
},
colors = {
error = {'LspDiagnosticsDefaultError', 'TSDanger', '#bf616a', '#e06c75'},
warning = {'LspDiagnosticsDefaultWarning', 'TSWarning', '#ebcb8b', '#e5c07b'},
info = {'LspDiagnosticsDefaultInformation', 'TSNote', '#81a1c1', '#61afef'},
hint = {'LspDiagnosticsDefaultHint', '#88c0d0', '#56b6c2'},
error = {'DiagnosticError', 'TSDanger', '#bf616a', '#e06c75'},
warning = {'DiagnosticWarn', 'TSWarning', '#ebcb8b', '#e5c07b'},
info = {'DiagnosticInfo', 'TSNote', '#81a1c1', '#61afef'},
hint = {'DiagnosticHint', '#88c0d0', '#56b6c2'},
default = {'Normal', '#d8dee9', '#abb2bf'}
},
search = {

View File

@ -4,8 +4,46 @@ local util = require('modules.lsp.util')
local on_attach = util.common_on_attach
local capabilities = util.common_capabilities()
util.setup_handlers()
local border = {
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'}
}
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
border = border,
})
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = border,
})
vim.diagnostic.config({
virtual_text = {
prefix = '',
-- source = 'always'
},
signs = {
active = true,
values = {
{name = 'DiagnosticsSignError', text = ''},
{name = 'DiagnosticsSignWarning', text = ''},
{name = 'DiagnosticsSignInformation', text = ''},
{name = 'DiagnosticsSignHint', text = ''}
}
},
update_in_insert = false,
severity_sort = true
})
-----------------------------
-- Servers' configurations --
-----------------------------
lspconf.clangd.setup {
filetypes = {'c', 'cpp'},
init_options = {

View File

@ -12,7 +12,6 @@ M['neovim/nvim-lspconfig'] = {
},
{
'tami5/lspsaga.nvim',
branch = 'nvim51',
config = conf.saga,
opt = true
},

View File

@ -151,46 +151,6 @@ function M.common_capabilities()
return capabilities
end
function M.setup_handlers()
local border = {
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'},
{'', 'FloatBorder'}
}
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
underline = false,
virtual_text = {
prefix = '',
source = 'always'
},
signs = {
active = true,
values = {
{name = 'LspDiagnosticsSignError', text = ''},
{name = 'LspDiagnosticsSignWarning', text = ''},
{name = 'LspDiagnosticsSignInformation', text = ''},
{name = 'LspDiagnosticsSignHint', text = ''}
}
},
update_in_insert = false,
severity_sort = true
})
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
border = border,
})
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = border,
})
end
function M.lua_lib_path()
local lib_path = {}

View File

@ -1,8 +1,6 @@
local M = {}
local colors = require('themes.' .. vim.g.colors_name .. '.colors')
local vi_mode_utils = require('feline.providers.vi_mode')
local lightbulb_present, lightbulb = pcall(require, 'nvim-lightbulb')
-- local gps_present, gps = pcall(require, 'nvim-gps')
local function file_osinfo()
local os = vim.bo.fileformat:upper()
@ -24,6 +22,50 @@ local function buffer_not_empty()
return false
end
local function is_lsp_attached()
return next(vim.lsp.buf_get_clients(0)) ~= nil
end
local function lsp_active_clients()
local clients = {}
-- Typical lsp clients
for _, client in pairs(vim.lsp.buf_get_clients(0)) do
if client.name ~= 'null-ls' then
table.insert(clients, client.name)
end
end
-- null-ls sources
local null_ls_methods = require('null-ls.methods')
local active_sources = require('null-ls.info').get_active_sources()
local linter_method = null_ls_methods.internal['DIAGNOSTICS']
local active_linters = active_sources[linter_method] or {}
vim.list_extend(clients, active_linters)
local formatter_method = null_ls_methods.internal['FORMATTING']
local active_formatters = active_sources[formatter_method] or {}
vim.list_extend(clients, active_formatters)
return table.concat(clients, ', ')
end
local function lsp_diagnostic_count(bufnr)
bufnr = bufnr or 0
local diagnostics = vim.diagnostic.get(bufnr)
local count = {0, 0, 0, 0}
for _, diagnostic in ipairs(diagnostics) do
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
return count[vim.diagnostic.severity.ERROR],
count[vim.diagnostic.severity.WARN],
count[vim.diagnostic.severity.INFO],
count[vim.diagnostic.severity.HINT]
end
-- Default colors for statusline --
M['normal_colors'] = {bg = colors.grey1, fg = colors.fg}
M['vi_mode_colors'] = {
@ -75,7 +117,7 @@ M['fileinfo'] = {
opts = {
file_modified_icon = '',
file_readonly_icon = '',
type = 'base-only' -- relative, unique, full-path, short-path, relative-short, unique-short
type = 'base-only'
}
},
enabled = buffer_not_empty,
@ -97,9 +139,10 @@ M['percent'] = {
-- M['gps'] = {
-- provider = function()
-- return gps.get_location()
-- return require('nvim-gps').get_location()
-- end,
-- enabled = function()
-- local gps_present, gps = pcall(require, 'nvim-gps')
-- if gps_present then
-- return gps.is_available()
-- else
@ -111,70 +154,62 @@ M['percent'] = {
M['codeact'] = {
provider = function()
return lightbulb.get_status_text()
return require('nvim-lightbulb').get_status_text()
end,
enabled = function()
local lightbulb_present, _ = pcall(require, 'nvim-lightbulb')
return lightbulb_present
end,
hl = {fg = colors.green, style = 'bold'}
}
M['diagerr'] = {
provider = 'diagnostic_errors',
provider = function()
local error, _, _, _ = lsp_diagnostic_count(0)
return error ~= 0 and tostring(error) or ''
end,
icon = '',
enabled = is_lsp_attached,
hl = {fg = colors.red},
left_sep = ' '
}
M['diagwarn'] = {
provider = 'diagnostic_warnings',
provider = function()
local _, warn, _, _ = lsp_diagnostic_count(0)
return warn ~= 0 and tostring(warn) or ''
end,
icon = '',
enabled = is_lsp_attached,
hl = {fg = colors.yellow},
left_sep = ' '
}
M['diaghint'] = {
provider = 'diagnostic_hints',
provider = function()
local _, _, _, hint = lsp_diagnostic_count(0)
return hint ~= 0 and tostring(hint) or ''
end,
icon = '',
enabled = is_lsp_attached,
hl = {fg = colors.cyan},
left_sep = ' '
}
M['diaginfo'] = {
provider = 'diagnostic_info',
provider = function()
local _, _, info, _ = lsp_diagnostic_count(0)
return info ~= 0 and tostring(info) or ''
end,
icon = '',
enabled = is_lsp_attached,
hl = {fg = colors.blue},
left_sep = ' '
}
M['lspclient'] = {
provider = function()
local clients = {}
-- Typical lsp clients
for _, client in pairs(vim.lsp.buf_get_clients(0)) do
if client.name ~= 'null-ls' then
table.insert(clients, client.name)
end
end
-- null-ls sources
local null_ls_methods = require('null-ls.methods')
local active_sources = require('null-ls.info').get_active_sources()
local linter_method = null_ls_methods.internal['DIAGNOSTICS']
local active_linters = active_sources[linter_method] or {}
vim.list_extend(clients, active_linters)
local formatter_method = null_ls_methods.internal['FORMATTING']
local active_formatters = active_sources[formatter_method] or {}
vim.list_extend(clients, active_formatters)
return table.concat(clients, ', ')
end,
enabled = function()
return next(vim.lsp.buf_get_clients(0)) ~= nil
end,
provider = lsp_active_clients,
enabled = is_lsp_attached,
icon = ' LSP:',
hl = {fg = colors.purple, style = 'bold'},
left_sep = ' '

View File

@ -163,16 +163,7 @@ function M.bufferline()
max_name_length = 16,
max_prefix_length = 13,
tab_size = 16,
diagnostics = false, -- 'nvim_lsp'
-- diagnostics_update_in_insert = false,
-- diagnostics_indicator = function(count, level, diagnostics_dict, context)
-- local s = ''
-- for e, n in pairs(diagnostics_dict) do
-- local sym = e == 'error' and 'x ' or (e == 'warning' and '! ' or (e == 'info' and 'i ' or '? '))
-- s = s .. n .. sym
-- end
-- return s
-- end,
diagnostics = false,
show_close_icon = false,
show_buffer_icons = true,
show_tab_indicators = true,
@ -187,14 +178,7 @@ function M.bufferline()
},
highlights = {
fill = {guibg = {attribute = 'bg', highlight = 'TabLineFill'}},
indicator_selected = {guifg = {attribute = 'fg', highlight = 'TabLineSel'}},
-- diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignHint', gui = 'bold,italic'}},
-- info_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignInformation', gui = 'bold,italic'}},
-- info_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultInformation', gui = 'bold,italic'}},
-- warning_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignWarning', gui = 'bold,italic'}},
-- warning_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultWarning', gui = 'bold,italic'}},
-- error_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignError', gui = 'bold,italic'}},
-- error_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultError', gui = 'bold,italic'}}
indicator_selected = {guifg = {attribute = 'fg', highlight = 'TabLineSel'}}
}
}
end
@ -268,11 +252,18 @@ function M.nvimtree()
filters = {
dotfiles = false
},
git = {
enable = true,
ignore = false,
timeout = 500
},
view = {
width = 35,
hide_root_folder = false,
side = 'left',
auto_resize = false
auto_resize = false,
number = false,
relativenumber = false
}
}
end

View File

@ -276,29 +276,30 @@ end
-- LSP groups
function M.highlight_lsp()
hi('LspDiagnosticsDefaultError', c.red, '', '', '')
hi('LspDiagnosticsSignError', c.red, '', '', '')
hi('LspDiagnosticsFloatingError', c.red, '', '', '')
hi('LspDiagnosticsVirtualTextError', c.red, '', 'italic', '')
hi('LspDiagnosticsUnderlineError', '', '', 'undercurl', c.red)
hi('DiagnosticError', c.red, '', '', '')
hi('DiagnosticWarn', c.yellow, '', '', '')
hi('DiagnosticInfo', c.blue, '', '', '')
hi('DiagnosticHint', c.cyan, '', '', '')
hi('LspDiagnosticsDefaultWarning', c.yellow, '', '', '')
hi('LspDiagnosticsSignWarning', c.yellow, '', '', '')
hi('LspDiagnosticsFloatingWarning', c.yellow, '', '', '')
hi('LspDiagnosticsVirtualTextWarning', c.yellow, '', 'italic', '')
hi('LspDiagnosticsUnderlineWarning', '', '', 'undercurl', c.yellow)
hi('DiagnisticUnderlineError', '', '', 'underline', c.red)
hi('DiagnosticUnderlineWarn', '', '', 'underline', c.yellow)
hi('DiagnosticUnderlineInfo', '', '', 'underline', c.blue)
hi('DiagnosticUnderlineHint', '', '', 'underline', c.cyan)
hi('LspDiagnosticsDefaultInformation', c.blue, '', '', '')
hi('LspDiagnosticsSignInformation', c.blue, '', '', '')
hi('LspDiagnosticsFloatingInformation', c.blue, '', '', '')
hi('LspDiagnosticsVirtualTextInformation', c.blue, '', 'italic', '')
hi('LspDiagnosticsUnderlineInformation', '', '', 'undercurl', c.blue)
hi('DiagnosticVirtualTextError', c.red, '', 'italic', '')
hi('DiagnosticVirtualTextWarn', c.yellow, '', 'italic', '')
hi('DiagnosticVirualTextInfo', c.blue, '', 'italic', '')
hi('DiagnosticVirtualTextHint', c.cyan, '', 'italic', '')
hi('LspDiagnosticsDefaultHint', c.cyan, '', '', '')
hi('LspDiagnosticsSignHint', c.cyan, '', '', '')
hi('LspDiagnosticsFloatingHint', c.cyan, '', '', '')
hi('LspDiagnosticsVirtualTextHint', c.cyan, '', 'italic', '')
hi('LspDiagnosticsUnderlineHint', '', '', 'undercurl', c.cyan)
cmd('hi! link DiagnosticFloatingError DiagnosticError')
cmd('hi! link DiagnosticFloatingWarn DiagnosticWarn')
cmd('hi! link DiagnosticFloatingInfo DiagnosticInfo')
cmd('hi! link DiagnosticFloatingHint DiagnosticHint')
cmd('hi! link DiagnosticSignError DiagnosticError')
cmd('hi! link DiagnosticSignWarn DiagnosticWarn')
cmd('hi! link DiagnosticSignInfo DiagnosticInfo')
cmd('hi! link DiagnosticSignHint DiagnosticHint')
hi('LspReferenceText', c.fg, c.grey_bright, '', '')
hi('LspReferenceRead', c.fg, c.grey_bright, '', '')
@ -312,7 +313,7 @@ function M.highlight_plugins()
hi('CmpItemAbbr', c.fg, '', '', '')
hi('CmpItemAbbrMatch', c.yellow, '', '', '')
hi('CmpItemAbbrMatchFuzzy', c.yellow, '', '', '')
hi('CmpItemKind', c.green, '', '', '')
hi('CmpItemKindDefault', c.green, '', '', '')
hi('CmpItemMenu', c.blue, '', '', '')
-- LuaSnip
@ -447,17 +448,15 @@ function M.highlight_plugins()
hi('ProviderTruncateLine', c.black, '', '', '')
hi('SagaShadow', '', c.black, '', '')
hi('DiagnosticTruncateLine', c.blue, '', 'bold', '')
cmd('hi! link DiagnosticError LspDiagnosticsDefaultError')
cmd('hi! link DiagnosticWarning LspDiagnosticsDefaultWarning')
cmd('hi! link DiagnosticInformation LspDiagnosticsDefaultInformation')
cmd('hi! link DiagnosticHint LspDiagnosticsDefaultHint')
cmd('hi! link DiagnosticWarning DiagnosticWarn')
cmd('hi! link DiagnosticInformation DiagnosticInfo')
hi('LspSagaDiagnosticBorder', c.fg, '', '', '')
hi('LspSagaDiagnosticHeader', c.blue, '', 'bold', '')
hi('LspSagaDiagnosticTruncateLine', c.fg, '', '', '')
cmd('hi! link LspSagaDiagnosticFloatingError LspDiagnosticsDefaultError')
cmd('hi! link LspSagaDiagnosticFloatingWarn LspDiagnosticsDefaultWarning')
cmd('hi! link LspSagaDiagnosticFloatingInfor LspDiagnosticsDefaultInformation')
cmd('hi! link LspSagaDiagnosticFloatingHint LspDiagnosticsDefaultHint')
cmd('hi! link LspSagaDiagnosticFloatingError DiagnosticError')
cmd('hi! link LspSagaDiagnosticFloatingWarn DiagnosticWarn')
cmd('hi! link LspSagaDiagnosticFloatingInfor DiagnosticInfo')
cmd('hi! link LspSagaDiagnosticFloatingHint DiagnosticHint')
hi('LspSagaShTruncateLine', c.black, '', '', '')
hi('LspSagaDocTruncateLine', c.black, '', '', '')
hi('LspSagaCodeActionTitle', c.orange, '', 'bold', '')
@ -471,7 +470,6 @@ function M.highlight_plugins()
hi('LspSagaCodeActionBorder', c.teal, '', '', '')
hi('LspSagaAutoPreview', c.yellow, '', '', '')
hi('LspSagaDefPreviewBorder', c.teal, '', '', '')
-- hi('LspSagaLightBulb', c.green, '', '', '')
-- Telescope
hi('TelescopePromptBorder', c.cyan, '', 'bold', '')

View File

@ -1,36 +1,37 @@
local opt = vim.opt
local g, opt = vim.g, vim.opt
local M = {}
function M.disable_default_plugins()
vim.g.loaded_gzip = 1
vim.g.loaded_tar = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_zip = 1
vim.g.loaded_zipPlugin = 1
vim.g.loaded_getscript = 1
vim.g.loaded_getscriptPlugin = 1
vim.g.loaded_vimball = 1
vim.g.loaded_vimballPlugin = 1
vim.g.loaded_matchit = 1
vim.g.loaded_matchparen = 1
vim.g.loaded_2html_plugin = 1
vim.g.loaded_logiPat = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrwSettings = 1
vim.g.loaded_netrwFileHandlers = 1
vim.g.did_load_filetypes = 1 -- use filetype.nvim instead
g.loaded_gzip = 1
g.loaded_tar = 1
g.loaded_tarPlugin = 1
g.loaded_zip = 1
g.loaded_zipPlugin = 1
g.loaded_getscript = 1
g.loaded_getscriptPlugin = 1
g.loaded_vimball = 1
g.loaded_vimballPlugin = 1
g.loaded_matchit = 1
g.loaded_matchparen = 1
g.loaded_2html_plugin = 1
g.loaded_logiPat = 1
g.loaded_rrhelper = 1
g.loaded_netrw = 1
g.loaded_netrwPlugin = 1
g.loaded_netrwSettings = 1
g.loaded_netrwFileHandlers = 1
g.did_load_filetypes = 1 -- use filetype.nvim instead
end
function M.load_options()
-- This is the same as `:colorscheme nord/onedark`
vim.g.colors_name = '{{ theme }}'
-- Leader key
vim.g.mapleader = ' '
vim.g.maplocalleader = ','
-- Set colorscheme
vim.api.nvim_command('colorscheme {{ theme }}')
-- Leader keys
g.mapleader = ' '
g.maplocalleader = ','
-- Python path
vim.g.python3_host_prog = '/usr/bin/python3'
g.python3_host_prog = '/usr/bin/python3'
-- General settings
opt.termguicolors = true
@ -59,10 +60,12 @@ function M.load_options()
-- opt.ruler = true
-- opt.display = 'lastline'
-- opt.colorcolumn = '80'
-- opt.cursorline = true
-- opt.cursorcolumn = true
opt.cursorline = true
opt.cursorlineopt = 'number'
-- opt.backspace = 'indent,eol,start'
opt.showcmd = false
opt.inccommand = 'nosplit'
-- opt.inccommand = 'nosplit'
-- opt.cmdheight = 2
-- opt.cmdwinheight = 6
opt.showtabline = 2
@ -93,7 +96,7 @@ function M.load_options()
-- Searching
-- opt.incsearch = true
opt.hlsearch = false
opt.hlsearch = true
-- opt.wrapscan = true
-- Update time
@ -142,7 +145,6 @@ function M.load_options()
opt.smartindent = true
-- opt.autoindent = true
opt.shiftround = true
opt.breakindent = true
-- Trailings, line break
opt.list = true
@ -150,6 +152,7 @@ function M.load_options()
opt.showbreak = '↳ '
-- opt.linebreak = true
-- opt.breakat = [[\ \ ;:,!?]]
opt.breakindent = true
-- opt.breakindentopt = 'shift:4,min:20'
-- Undo file path