From 58328b347c5cf02396d77ccf42cbcf8f2518f9a2 Mon Sep 17 00:00:00 2001 From: Pratik Bhusal Date: Thu, 16 Nov 2017 12:08:41 -0600 Subject: [PATCH] Added function to show line number The function shows the line number of the first error/warning that appears in the current buffer. If there are 20 warnings and the first warning exists on line 33, then vim-airline would show "W:20(L33)". One can change how the line number is represented using: `g:airline#extensions#ale#open_lnum_symbol` and `airline#extensions#ale#close_lnum_symbol` --- autoload/airline/extensions/ale.vim | 23 ++++++++++++++++++++++- doc/airline.txt | 6 ++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/autoload/airline/extensions/ale.vim b/autoload/airline/extensions/ale.vim index 07639a8..51755b9 100644 --- a/autoload/airline/extensions/ale.vim +++ b/autoload/airline/extensions/ale.vim @@ -8,6 +8,27 @@ function! s:airline_ale_count(cnt, symbol) return a:cnt ? a:symbol. a:cnt : '' endfunction +function! s:airline_ale_get_line_number(cnt, type) abort + if a:cnt == 0 + return '' + endif + + let buffer = bufnr('') + let problem_type = (a:type ==# 'error') ? 'E' : 'W' + let problems = copy(ale#engine#GetLoclist(buffer)) + + call filter(problems, 'v:val.bufnr is buffer && v:val.type is# problem_type') + + if empty(problems) + return '' + endif + + let open_lnum_symbol = get(g:, 'airline#extensions#ale#open_lnum_symbol', '(L') + let close_lnum_symbol = get(g:, 'airline#extensions#ale#close_lnum_symbol', ')') + + return open_lnum_symbol . problems[0].lnum . close_lnum_symbol +endfunction + function! airline#extensions#ale#get(type) if !exists(':ALELint') return '' @@ -29,7 +50,7 @@ function! airline#extensions#ale#get(type) let num = is_err ? counts[0] : counts[1] endif - return s:airline_ale_count(num, symbol) + return s:airline_ale_count(num, symbol) . airline_ale_get_line_number(num, a:type) endfunction function! airline#extensions#ale#get_warning() diff --git a/doc/airline.txt b/doc/airline.txt index b829872..ae43254 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -987,6 +987,12 @@ ale * ale warning > let airline#extensions#ale#warning_symbol = 'W:' < +* ale open_lnum_symbol > + let airline#extensions#ale#open_lnum_symbol = '(L' +< +* ale close_lnum_symbol > + let airline#extensions#ale#close_lnum_symbol = ')' +< ------------------------------------- *airline-neomake* neomake