<commit_before>" MIT License. Copyright (c) 2013-2018 <NAME>, w0rp et al.
" vim: et ts=2 sts=2 sw=2

scriptencoding utf-8

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 ''
  endif

  let error_symbol = get(g:, 'airline#extensions#ale#error_symbol', 'E:')
  let warning_symbol = get(g:, 'airline#extensions#ale#warning_symbol', 'W:')
  let checking_symbol = get(g:, 'airline#extensions#ale#checking_symbol', '...')
  let show_line_numbers = get(g:, 'airline#extensions#ale#show_line_numbers', 1)

  let is_err = a:type ==# 'error'

  if ale#engine#IsCheckingBuffer(bufnr('')) == 1
    return is_err ? '' : checking_symbol
  endif

  let symbol = is_err ? error_symbol : warning_symbol

  let counts = ale#statusline#Count(bufnr(''))
  if type(counts) == type({}) && has_key(counts, 'error')
    " Use the current Dictionary format.
    let errors = counts.error + counts.style_error
    let num = is_err ? errors : counts.total - errors
  else
    " Use the old List format.
    let num = is_err ? counts[0] : counts[1]<commit_msg>Added a hook to the new ALE api to grab line numbers. Should be more efficient.<commit_after>" MIT License. Copyright (c) 2013-2018 <NAME>, w0rp et al.
" vim: et ts=2 sts=2 sw=2

scriptencoding utf-8

function! s:airline_ale_count(cnt, symbol)
  return a:cnt ? a:symbol. a:cnt : ''
endfunction

function! s:legacy_airline_ale_get_line_number(cnt, type) abort
  " Before ALE introduced the FirstProblem API function, this is how
  " airline would get the line numbers:
  " 1. Get the whole loclist; 2. Filter it for the desired problem type.
  " 3. Return the line number of the first element in the filtered list.
  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! s:new_airline_ale_get_line_number(cnt, type) abort
  " The FirstProblem call in ALE is a far more efficient way
  " of obtaining line number data. If the installed ALE supports
  " it, we should use this method of getting line data.
  if a:cnt == 0
    return ''
  endif
  let l:buffer = bufnr('')

  " Try to get the first error from ALE.
  let l:result = ale#statusline#FirstProblem(l:buffer, a:type)
  if empty(l:result)
    " If there are no errors then try and check for style errors.
    let l:result =  ale#statusline#FirstProblem(l:buffer, 'style_' . a:type)
  endif

  if empty(l:result)
      return ''
  endif

  let l:open_lnum_symbol  =
    \ get(g:, 'airline#extensions#ale#open_lnum_symbol', '(L')
  let l:close_lnum_symbol =
    \ get(g:, 'airline#extensions#ale#close_lnum_symbol', ')')

  return open_lnum_symbol . l:result.lnum . close_lnum_symbol
endfunction

function! s:airline_ale_get_line_number(cnt, type) abort
  " Use the new ALE statusline API function if it is available.
  if exists("*ale#statusline#FirstProblem")
    return s:new_airline_ale_get_line_number(a:cnt, a:type)
  endif

  return s:legacy_airline_ale_get_line_number(a:cnt, a:type)
endfunction

function! airline#extensions#ale#get(type)
  if !exists(':ALELint')
    return ''
  endif

  let error_symbol = get(g:, 'airline#extensions#ale#error_symbol', 'E:')
  let warning_symbol = get(g:, 'airline#extensions#ale#warning_symbol', 'W:')
  let checking_symbol = get(g:, 'airline#extensions#ale#checking_symbol', '...')
  let show_line_numbers = get(g:, 'airline#extensions#ale#show_line_numbers', 1)

  let is_err = a:type ==# 'error'

  if ale#engine#IsCheckingBuffer(bufnr('')) == 1
    return is_err ? '' : checking_symbol
  endif

  let symbol = is_err ? error_symbol : warning_symbol

  let counts = ale#statusline#Count(bufnr(''))
  if type(counts) == type({}) && has_key(counts, 'error')
    " Use the current Dictionary format.
    let errors = counts.error + counts.style_error
    let num = is_err ? errors : counts.total - errors
  else
    " Use the old List format.
    let num = is_err ? counts[0] : counts[1]
{'fraction_non_alphanumeric': 0.12633451957295375, 'fraction_numerical': 0.00830367734282325, 'mean_word_length': 4.319663512092534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114822', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1765, 'n_words': 468}