├── .github └── example-v2.jpg ├── LICENSE ├── README.md ├── autoload └── lightline │ └── coc.vim └── plugin └── lightline └── coc.vim /.github/example-v2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josa42/vim-lightline-coc/53465b2c2ce7b6ae3497ad1cdb751dd3d8084d5c/.github/example-v2.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Josa Gesell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lightline-coc 2 | 3 | This plugin provides [coc](https://github.com/neoclide/coc.nvim) diagnostics indicator for the [lightline](https://github.com/itchyny/lightline.vim) vim plugin. 4 | 5 | ![Example](.github/example-v2.jpg) 6 | 7 | ## Installation 8 | 9 | Install using a plugin manager of your choice, for example [`vim-plug`](https://github.com/junegunn/vim-plug): 10 | 11 | ```viml 12 | Plug 'josa42/vim-lightline-coc' 13 | ``` 14 | 15 | ## Components 16 | 17 | - `coc_errors` Number of diagnostics errors 18 | - `coc_warnings` Number of diagnostics warnings 19 | - `coc_info` Number of diagnostics information messages 20 | - `coc_hints` Number of diagnostics hints 21 | - `coc_ok` Checkmark if there are no errors or warnings 22 | - `coc_status` Show status messages if there are any. 23 | 24 | ## Integration 25 | 26 | ```viml 27 | let g:lightline = { 28 | \ 'active': { 29 | \ left': [[ 'coc_info', 'coc_hints', 'coc_errors', 'coc_warnings', 'coc_ok' ], [ 'coc_status' ]] 30 | \ } 31 | \ } 32 | 33 | " register compoments: 34 | call lightline#coc#register() 35 | ``` 36 | 37 | **Or register manually** 38 | 39 | ```viml 40 | " Register the components: 41 | let g:lightline = {} 42 | let g:lightline.component_expand = { 43 | \ 'linter_warnings': 'lightline#coc#warnings', 44 | \ 'linter_errors': 'lightline#coc#errors', 45 | \ 'linter_info': 'lightline#coc#info', 46 | \ 'linter_hints': 'lightline#coc#hints', 47 | \ 'linter_ok': 'lightline#coc#ok', 48 | \ 'status': 'lightline#coc#status', 49 | \ } 50 | 51 | " Set color to the components: 52 | let g:lightline.component_type = { 53 | \ 'linter_warnings': 'warning', 54 | \ 'linter_errors': 'error', 55 | \ 'linter_info': 'info', 56 | \ 'linter_hints': 'hints', 57 | \ 'linter_ok': 'left', 58 | \ } 59 | 60 | " Add the components to the lightline: 61 | let g:lightline.active = { 62 | \ left': [[ 'coc_info', 'coc_hints', 'coc_errors', 'coc_warnings', 'coc_ok' ], [ 'coc_status' ]] 63 | \ } 64 | ``` 65 | 66 | ## Configuration 67 | 68 | - `g:lightline#coc#indicator_warnings` 69 | The indicator to use when there are warnings. Default is `•`. 70 | 71 | - `g:lightline#coc#indicator_errors` 72 | The indicator to use when there are errors. Default is `×`. 73 | 74 | - `g:lightline#coc#indicator_info` 75 | The indicator to use when there are information messages. Default is `~`. 76 | 77 | - `g:lightline#coc#indicator_hints` 78 | The indicator to use when there are hints. Default is `>`. 79 | 80 | - `g:lightline#coc#indicator_ok` 81 | The indicator to use when there are no warnings or errors. Default is `✓`. 82 | 83 | ## Credit 84 | 85 | - The plugin is based on [`maximbaz/lightline-ale`](https://github.com/maximbaz/lightline-ale) 86 | 87 | ## License 88 | 89 | [MIT © Josa Gesell](LICENSE) 90 | -------------------------------------------------------------------------------- /autoload/lightline/coc.vim: -------------------------------------------------------------------------------- 1 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Configs 3 | 4 | let s:nerdfont = get(g:, 'nerdfont', 0) 5 | 6 | let s:indicator_warnings = get(g:, 'lightline#coc#indicator_warnings', '•') 7 | let s:indicator_errors = get(g:, 'lightline#coc#indicator_errors', '×') 8 | let s:indicator_info = get(g:, 'lightline#coc#indicator_info', '~') 9 | let s:indicator_hints = get(g:, 'lightline#coc#indicator_hints', '>') 10 | let s:indicator_ok = get(g:, 'lightline#coc#indicator_ok', (s:nerdfont ? "\uf058" : '✓')) 11 | 12 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | " Lightline components 14 | 15 | function! lightline#coc#warnings() abort 16 | if s:isHidden() 17 | return '' 18 | endif 19 | 20 | let l:counts = s:count('warning') 21 | return l:counts == 0 ? '' : printf(s:indicator_warnings . '%d', l:counts) 22 | endfunction 23 | 24 | function! lightline#coc#errors() abort 25 | if s:isHidden() 26 | return '' 27 | endif 28 | 29 | let l:counts = s:count('error') 30 | return l:counts == 0 ? '' : printf(s:indicator_errors . '%d', l:counts) 31 | endfunction 32 | 33 | function! lightline#coc#info() abort 34 | if s:isHidden() 35 | return '' 36 | endif 37 | 38 | let l:counts = s:count('information') 39 | return l:counts == 0 ? '' : printf(s:indicator_info . '%d', l:counts) 40 | endfunction 41 | 42 | function! lightline#coc#hints() abort 43 | if s:isHidden() 44 | return '' 45 | endif 46 | 47 | let l:counts = s:count('hint') 48 | return l:counts == 0 ? '' : printf(s:indicator_hints . '%d', l:counts) 49 | endfunction 50 | 51 | function! lightline#coc#ok() abort 52 | if s:isHidden() 53 | return '' 54 | endif 55 | 56 | let l:counts = s:countSum() 57 | return l:counts == 0 ? s:indicator_ok : '' 58 | endfunction 59 | 60 | function! lightline#coc#status() 61 | return get(g:, 'coc_status', '') 62 | endfunction 63 | 64 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 65 | " Register 66 | 67 | function! lightline#coc#register() abort 68 | call s:setLightline('component_expand', 'coc_status', 'lightline#coc#status') 69 | call s:setLightline('component_expand', 'coc_warnings', 'lightline#coc#warnings') 70 | call s:setLightline('component_expand', 'coc_errors', 'lightline#coc#errors') 71 | call s:setLightline('component_expand', 'coc_info', 'lightline#coc#info') 72 | call s:setLightline('component_expand', 'coc_hints', 'lightline#coc#hints') 73 | call s:setLightline('component_expand', 'coc_ok', 'lightline#coc#ok') 74 | 75 | call s:setLightline('component_type', 'coc_warnings', 'warning') 76 | call s:setLightline('component_type', 'coc_errors', 'error') 77 | call s:setLightline('component_type', 'coc_info', 'info') 78 | call s:setLightline('component_type', 'coc_hints', 'hint') 79 | call s:setLightline('component_type', 'coc_ok', 'left') 80 | 81 | call s:setLightline('component_function', 'coc_status', 'lightline#coc#status') 82 | endfunction 83 | 84 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 85 | " Helper functions 86 | 87 | function! s:count(level) abort 88 | let info = get(b:, 'coc_diagnostic_info', {}) 89 | return get(info, a:level, 0) 90 | endfunction 91 | 92 | function! s:countSum() abort 93 | let info = get(b:, 'coc_diagnostic_info', {}) 94 | return get(info, 'error', 0) + get(info, 'warning', 0) 95 | endfunction 96 | 97 | function! s:isHidden() 98 | return exists('*lightline#sensible#isHidden') && lightline#sensible#isHidden() 99 | endfunction 100 | 101 | function! s:setLightline(scope, name, value) abort 102 | let g:lightline = get(g:, 'lightline', {}) 103 | let g:lightline[a:scope] = get(g:lightline, a:scope, {}) 104 | let g:lightline[a:scope][a:name] = get(g:lightline[a:scope], a:name, a:value) 105 | endfunction 106 | 107 | 108 | -------------------------------------------------------------------------------- /plugin/lightline/coc.vim: -------------------------------------------------------------------------------- 1 | augroup lightline#coc 2 | autocmd! 3 | autocmd User CocDiagnosticChange call lightline#update() 4 | autocmd User CocStatusChange call lightline#update() 5 | augroup END 6 | 7 | --------------------------------------------------------------------------------