-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sirisak Lueangsaksri
committed
Jan 16, 2021
0 parents
commit 449dbb8
Showing
5 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ISC License | ||
|
||
Copyright (c) 2021 Sirisak Lueangsaksri | ||
based on the work by Maxim Baz on [lightline-ale](https://github.com/maximbaz/lightline-ale) | ||
|
||
Copyright (c) 2017-2021, Maxim Baz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# lightline-lsp | ||
|
||
This plugin provides neovim's LSP diagnostic indicator for the [lightline](https://github.com/itchyny/lightline.vim) vim plugin. | ||
|
||
![screenshot](./screenshot.png) | ||
|
||
## Table Of Contents | ||
|
||
* [Installation](#installation) | ||
* [Integration](#integration) | ||
* [Configuration](#configuration) | ||
* [License](#license) | ||
|
||
## Installation | ||
|
||
Install using a plugin manager of your choice, for example: | ||
|
||
```viml | ||
" neovim 0.5 or later which support lsp and lua | ||
Plug 'itchyny/lightline.vim' " Dependency: status line | ||
Plug 'spywhere/lightline-lsp' | ||
``` | ||
|
||
## Integration | ||
|
||
1. Register the components: | ||
|
||
```viml | ||
let g:lightline = {} | ||
let g:lightline.component_expand = { | ||
\ 'linter_hints': 'lightline#lsp#hints', | ||
\ 'linter_infos': 'lightline#lsp#infos', | ||
\ 'linter_warnings': 'lightline#lsp#warnings', | ||
\ 'linter_errors': 'lightline#lsp#errors', | ||
\ 'linter_ok': 'lightline#lsp#ok', | ||
\ } | ||
``` | ||
|
||
2. Set color to the components: | ||
|
||
```viml | ||
let g:lightline.component_type = { | ||
\ 'linter_hints': 'right', | ||
\ 'linter_infos': 'right', | ||
\ 'linter_warnings': 'warning', | ||
\ 'linter_errors': 'error', | ||
\ 'linter_ok': 'right', | ||
\ } | ||
``` | ||
|
||
3. Add the components to the lightline, for example to the right side: | ||
|
||
```viml | ||
let g:lightline.active = { 'right': [[ 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_hints', 'linter_ok' ]] } | ||
``` | ||
|
||
## Configuration | ||
|
||
##### `g:lightline#lsp#indicator_hints` | ||
|
||
The indicator to use when there are hints. Default is `H:`. | ||
|
||
##### `g:lightline#lsp#indicator_infos` | ||
|
||
The indicator to use when there are infos. Default is `I:`. | ||
|
||
##### `g:lightline#lsp#indicator_warnings` | ||
|
||
The indicator to use when there are warnings. Default is `W:`. | ||
|
||
##### `g:lightline#lsp#indicator_errors` | ||
|
||
The indicator to use when there are errors. Default is `E:`. | ||
|
||
##### `g:lightline#lsp#indicator_ok` | ||
|
||
The indicator to use when there are no diagnostic. Default is `OK`. | ||
|
||
### Using icons as indicators | ||
|
||
If you would like to replace the default indicators with symbols like on the screenshot, then you'll need to ensure you have some "iconic fonts" installed, such as [Font Awesome](https://fontawesome.com). A common alternative is to replace your primary font with one of the [Patched Nerd Fonts](https://github.com/ryanoasis/nerd-fonts), which saves you from having to install multiple fonts. | ||
|
||
The following icons from the Font Awesome font are used in the screenshot: | ||
|
||
* Hints: [f002](https://fontawesome.com/icons/search) | ||
* Infos: [f129](https://fontawesome.com/icons/info) | ||
* Warnings: [f071](https://fontawesome.com/icons/exclamation-triangle) | ||
* Errors: [f05e](https://fontawesome.com/icons/ban) | ||
* OK: [f00c](https://fontawesome.com/icons/check) | ||
|
||
To specify icons in the configuration, use their unicode codes as `"\uXXXX"` (make sure to wrap them in double quotes). Alternatively copy the icons from a font website, or type <kbd>\<C-v\>u\<4-digit-unicode\></kbd> or <kbd>\<C-v\>U\<8-digit-unicode\></kbd> to insert the literal characters. | ||
|
||
See the code points here: | ||
|
||
* Font Awesome: https://fontawesome.com/icons | ||
* Nerd Fonts: https://github.com/ryanoasis/nerd-fonts#glyph-sets | ||
|
||
Here's the configuration snippet used in the screenshot: | ||
|
||
```viml | ||
let g:lightline#lsp#indicator_hints = "\uf002" | ||
let g:lightline#lsp#indicator_infos = "\uf129" | ||
let g:lightline#lsp#indicator_warnings = "\uf071" | ||
let g:lightline#lsp#indicator_errors = "\uf05e" | ||
let g:lightline#lsp#indicator_ok = "\uf00c" | ||
``` | ||
|
||
## License | ||
|
||
Released under the [ISC License](LICENSE) | ||
based on the work by Maxim Baz on [lightline-ale](https://github.com/maximbaz/lightline-ale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
let s:indicator_hints = get(g:, 'lightline#lsp#indicator_hints', 'H: ') | ||
let s:indicator_infos = get(g:, 'lightline#lsp#indicator_infos', 'I: ') | ||
let s:indicator_warnings = get(g:, 'lightline#lsp#indicator_warnings', 'W: ') | ||
let s:indicator_errors = get(g:, 'lightline#lsp#indicator_errors', 'E: ') | ||
let s:indicator_ok = get(g:, 'lightline#lsp#indicator_ok', 'OK') | ||
|
||
|
||
"""""""""""""""""""""" | ||
" Lightline components | ||
|
||
function! lightline#lsp#hints() abort | ||
if !lightline#lsp#linted() | ||
return '' | ||
endif | ||
let l:counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Hint]])') | ||
return l:counts == 0 ? '' : printf(s:indicator_hints . '%d', counts) | ||
endfunction | ||
|
||
function! lightline#lsp#infos() abort | ||
if !lightline#lsp#linted() | ||
return '' | ||
endif | ||
let l:counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Info]])') | ||
return l:counts == 0 ? '' : printf(s:indicator_infos . '%d', counts) | ||
endfunction | ||
|
||
function! lightline#lsp#warnings() abort | ||
if !lightline#lsp#linted() | ||
return '' | ||
endif | ||
let l:counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Warning]])') | ||
return l:counts == 0 ? '' : printf(s:indicator_warnings . '%d', counts) | ||
endfunction | ||
|
||
function! lightline#lsp#errors() abort | ||
if !lightline#lsp#linted() | ||
return '' | ||
endif | ||
let l:counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Error]])') | ||
return l:counts == 0 ? '' : printf(s:indicator_errors . '%d', counts) | ||
endfunction | ||
|
||
function! lightline#lsp#ok() abort | ||
if !lightline#lsp#linted() | ||
return '' | ||
endif | ||
let l:hint_counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Hint]])') | ||
let l:info_counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Info]])') | ||
let l:warn_counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Warning]])') | ||
let l:error_counts = luaeval('vim.lsp.diagnostic.get_count('.bufnr().', [[Error]])') | ||
let l:counts = l:hint_counts+l:info_counts+l:warn_counts+l:error_counts | ||
return l:counts == 0 ? s:indicator_ok : '' | ||
endfunction | ||
|
||
"""""""""""""""""" | ||
" Helper functions | ||
|
||
function! lightline#lsp#linted() abort | ||
return !!luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients('.bufnr().'))') | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
augroup lightline#lsp | ||
autocmd! | ||
autocmd User LspDiagnosticsChanged call lightline#update() | ||
augroup END |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.