From 71a04af8d770235eb5369cd4a3749054a453f6af Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 2 Jul 2021 22:39:21 +0300 Subject: [PATCH] [nvim] crank up visual customizations of coc.nvim --- .../airline/extensions/dotfiles_coclist.vim | 126 ++++++++++++++++++ nvim/colors/dotfiles.vim | 23 +++- nvim/plugin/completion.vim | 1 + nvim/plugin/editing.vim | 1 + nvim/plugin/interface.vim | 1 + 5 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 nvim/autoload/airline/extensions/dotfiles_coclist.vim diff --git a/nvim/autoload/airline/extensions/dotfiles_coclist.vim b/nvim/autoload/airline/extensions/dotfiles_coclist.vim new file mode 100644 index 0000000..0e355ae --- /dev/null +++ b/nvim/autoload/airline/extensions/dotfiles_coclist.vim @@ -0,0 +1,126 @@ +if !exists('g:did_coc_loaded') + finish +endif + +function! airline#extensions#dotfiles_coclist#init(ext) abort + let g:coc_user_config['list.statusLineSegments'] = v:null + + call a:ext.add_statusline_func('airline#extensions#dotfiles_coclist#apply') + call a:ext.add_inactive_statusline_func('airline#extensions#dotfiles_coclist#apply') + + call airline#parts#define('dotfiles_coclist_mode', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_mode', + \ 'accent': 'bold', + \ }) + call airline#parts#define('dotfiles_coclist_args', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_args', + \ }) + call airline#parts#define('dotfiles_coclist_name', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_name', + \ }) + call airline#parts#define('dotfiles_coclist_cwd', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_cwd', + \ }) + call airline#parts#define('dotfiles_coclist_loading', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_loading', + \ }) + call airline#parts#define('dotfiles_coclist_total', { + \ 'function': 'airline#extensions#dotfiles_coclist#part_total', + \ }) + + " Default airline section setup: + " + " Beware that whitespaces in function expansions can cause some weirdness: + " + let s:section_a = airline#section#create_left(['dotfiles_coclist_mode']) + let s:section_b = airline#section#create(['dotfiles_coclist_name']) + let s:section_c = airline#section#create(['%<', 'dotfiles_coclist_args', ' ', 'dotfiles_coclist_loading']) + let s:section_x = airline#section#create(['dotfiles_coclist_cwd']) + let s:section_y = airline#section#create(['#%L/', 'dotfiles_coclist_total']) + let s:section_z = airline#section#create(['%p%%', 'linenr', 'maxlinenr']) +endfunction + +function! airline#extensions#dotfiles_coclist#statusline() abort + let context = { 'winnr': winnr(), 'active': 1, 'bufnr': bufnr() } + let builder = airline#builder#new(context) + call airline#extensions#dotfiles_coclist#apply(builder, context) + return builder.build() +endfunction + +function! airline#extensions#dotfiles_coclist#apply(builder, context) abort + if getbufvar(a:context.bufnr, '&filetype', '') !=# 'list' | return 0 | endif + let list_status = getbufvar(a:context.bufnr, 'list_status', 0) + if type(list_status) !=# v:t_dict | return 0 | endif + + " How b:list_status is populated: + " + " How the list buffer is created: + " + " The default statusline: + " + " How airline generates its actual statuslines: + " + " + " + + let spc = g:airline_symbols.space + if a:context.active || (!a:context.active && !g:airline_inactive_collapse) + call a:builder.add_section('airline_a', s:get_section('a')) + call a:builder.add_section('airline_b', s:get_section('b')) + endif + call a:builder.add_section('airline_c', s:get_section('c')) + call a:builder.split() + call a:builder.add_section('airline_x', s:get_section('x')) + call a:builder.add_section('airline_y', s:get_section('y')) + call a:builder.add_section('airline_z', s:get_section('z')) + + return 1 +endfunction + +" Copied from +let s:section_truncate_width = get(g:, 'airline#extensions#default#section_truncate_width', { +\ 'b': 79, +\ 'x': 60, +\ 'y': 88, +\ 'z': 45, +\ }) + +function! s:get_section(key) abort + if has_key(s:section_truncate_width, a:key) && airline#util#winwidth() < s:section_truncate_width[a:key] + return '' + endif + let spc = g:airline_symbols.space + let text = s:section_{a:key} + if empty(text) | return '' | endif + return '%(' . spc . text . spc . '%)' +endfunction + +" TODO: Is recoloring of the section A based on `b:list_status.mode` possible? +function! airline#extensions#dotfiles_coclist#part_mode() abort + if get(w:, 'airline_active', 1) + " + return airline#util#shorten(get(b:list_status, 'mode', ''), 79, 1) + else + return get(g:airline_mode_map, '__') + else +endfunction + +function! airline#extensions#dotfiles_coclist#part_args() abort + return get(b:list_status, 'args', '') +endfunction + +function! airline#extensions#dotfiles_coclist#part_name() abort + return get(b:list_status, 'name', '') +endfunction + +function! airline#extensions#dotfiles_coclist#part_loading() abort + return get(b:list_status, 'loading', '') +endfunction + +function! airline#extensions#dotfiles_coclist#part_total() abort + return get(b:list_status, 'total', '') +endfunction + +function! airline#extensions#dotfiles_coclist#part_cwd() abort + return pathshorten(fnamemodify(get(b:list_status, 'cwd', ''), ':~:.')) +endfunction diff --git a/nvim/colors/dotfiles.vim b/nvim/colors/dotfiles.vim index a181605..03db6bd 100644 --- a/nvim/colors/dotfiles.vim +++ b/nvim/colors/dotfiles.vim @@ -62,6 +62,7 @@ call s:hi('Title', 0xD, '', '', '') hi! link Directory Title call s:hi('Conceal', 0xC, '', '', '') + call s:hi('IndentLine', 0x2, '', '', '') call s:hi('NonText', 0x3, '', '', '') hi! link SpecialKey Special call s:hi('MatchParen', 'fg', 0x3, '', '') @@ -107,12 +108,22 @@ call s:hi('WarningMsg', 0x9, '', '', '') call s:hi('TooLong', 0x8, '', '', '') call s:hi('Debug', 0x8, '', '', '') - hi! link CocErrorSign Error - call s:hi('CocWarningSign', 'bg', 0xA, '', '') - call s:hi('CocInfoSign', 'bg', 0xD, '', '') - hi! link CocHintSign CocInfoSign - call s:hi('CocFadeOut', 0x3, '', '', '') - hi! link CocMarkdownLink Underlined + + call s:hi('CocErrorSign', 'bg', 0x8, '', '') + call s:hi('CocWarningSign', 'bg', 0xA, '', '') + call s:hi('CocInfoSign', 'bg', 0xD, '', '') + hi! link CocHintSign CocInfoSign + call s:hi('CocSelectedText', 0xE, 0x1, 'bold', '') + call s:hi('CocCodeLens', 0x4, '', '', '') + call s:hi('CocFadeOut', 0x3, '', '', '') + call s:hi('CocStrikeThrough', '', '', 'strikethrough', '') + hi! link CocMarkdownLink Underlined + hi! link CocDiagnosticsFile Directory + hi! link CocOutlineName NONE + hi! link CocExtensionsLoaded NONE + hi! link CocSymbolsName NONE + hi! link CocOutlineIndentLine IndentLine + hi! link CocSymbolsFile Directory call s:hi('FoldColumn', 0xC, 0x1, '', '') call s:hi('Folded', 0x3, 0x1, '', '') diff --git a/nvim/plugin/completion.vim b/nvim/plugin/completion.vim index 894e52c..bec2c0f 100644 --- a/nvim/plugin/completion.vim +++ b/nvim/plugin/completion.vim @@ -90,6 +90,7 @@ endif \ } let g:coc_user_config['suggest.floatEnable'] = v:false let g:coc_user_config['workspace.progressTarget'] = "statusline" + let g:coc_user_config['list.selectedSignText'] = '> ' runtime! coc-languages/*.vim diff --git a/nvim/plugin/editing.vim b/nvim/plugin/editing.vim index de0e614..658adf4 100644 --- a/nvim/plugin/editing.vim +++ b/nvim/plugin/editing.vim @@ -30,6 +30,7 @@ set commentstring=//%s let g:indentLine_first_char = g:indentLine_char let g:indentLine_showFirstIndentLevel = 1 let g:indentLine_fileTypeExclude = ['text', 'help', 'tutor', 'man'] + let g:indentLine_defaultGroup = 'IndentLine' augroup vimrc-indentlines-disable autocmd! diff --git a/nvim/plugin/interface.vim b/nvim/plugin/interface.vim index de8091a..183ec89 100644 --- a/nvim/plugin/interface.vim +++ b/nvim/plugin/interface.vim @@ -113,6 +113,7 @@ endif \ 'obsession', \ 'dotfiles_tweaks', \ 'dotfiles_filesize', + \ 'dotfiles_coclist', \ ] let g:airline_detect_iminsert = 1 let g:airline#extensions#tabline#left_sep = ' '