<commit_before>" vim: et ts=2 sts=2 sw=2

let s:save_cpo = &cpo
set cpo&vim

let s:loclist = []
let s:tempfile = tempname()
let s:width = 16

let s:manager = {'refcount': 0, 'jobs': []}

function s:manager.add_job(job)
  if job_status(a:job) == 'run'
    call add(self.jobs, a:job)
    let self.refcount += 1
  endif
endfunction

function s:manager.reset_jobs()
  let still_alive = []
  for job in self.jobs
    if job_status(job) == 'run'
      call job_stop(job)
      " recheck
      if job_status(job) == 'run'
        call add(still_alive, job)
      else
        call self.decref()
      endif
    endif
  endfor
  let self.jobs = still_alive
endfunction

function s:manager.decref()
  let self.refcount -= 1
  if self.refcount <= 0
    let self.refcount = 0
  endif
endfunction


function s:handle(ch, ft, nr, checker)
  call s:manager.decref()

  let msg = []
  while ch_status(a:ch) == 'buffered'
    call add(msg, ch_read(a:ch))
  endwhile

  if !bufexists(a:nr) | return | endif

  let s:loclist += validator#utils#parse_loclist(msg, a:nr, a:ft, a:checker)
  if s:manager.refcount <= 0
    call validator#notifier#notify(s:loclist, a:nr)
    let s:loclist = []
  endif
endfunction


function! s:clear(nr)
  let s:loclist = []
  if has_key(g:_sign_map, a:nr)
    call validator#notifier#notify(s:loclist, a:nr)
  endif
endfunction


function! s:send_buffer(job, lines)
  let ch = job_getchannel(a:job)
  if ch_status(ch) == 'open'
    call ch_sendraw(ch, join(a:lines, "\n"))
    call ch_close_in(ch)
  endif
endfunction


function! s:check()
  let ft = &filetype
  if  pumvisible() || index(g:validator_ignore, ft) != -1 | return | endif

  let nr = bufnr('')
  if empty(ft)
    call s:clear(nr)
    return
  endif

  call s:manager.reset_jobs()

  let ext = expand('%:e')
  let ext = empty(ext) ? '' : '.'.ext
  let tail = fnamemodify(s:tempfile, ':t')
  let fname = 'temp'.tail.ext
  let tmp = fnamemodify(s:tempfile, ':s?'.tail.'$?'.fname.'?')
  echo tmp

  let lines = getline(1, '$')
  if len(lines) == 1 && empty(lines[0])
    call s:clear(nr)
    return
  endif<commit_msg>Remove echo<commit_after>" vim: et ts=2 sts=2 sw=2

let s:save_cpo = &cpo
set cpo&vim

let s:loclist = []
let s:tempfile = tempname()
let s:width = 16

let s:manager = {'refcount': 0, 'jobs': []}

function s:manager.add_job(job)
  if job_status(a:job) == 'run'
    call add(self.jobs, a:job)
    let self.refcount += 1
  endif
endfunction

function s:manager.reset_jobs()
  let still_alive = []
  for job in self.jobs
    if job_status(job) == 'run'
      call job_stop(job)
      " recheck
      if job_status(job) == 'run'
        call add(still_alive, job)
      else
        call self.decref()
      endif
    endif
  endfor
  let self.jobs = still_alive
endfunction

function s:manager.decref()
  let self.refcount -= 1
  if self.refcount <= 0
    let self.refcount = 0
  endif
endfunction


function s:handle(ch, ft, nr, checker)
  call s:manager.decref()

  let msg = []
  while ch_status(a:ch) == 'buffered'
    call add(msg, ch_read(a:ch))
  endwhile

  if !bufexists(a:nr) | return | endif

  let s:loclist += validator#utils#parse_loclist(msg, a:nr, a:ft, a:checker)
  if s:manager.refcount <= 0
    call validator#notifier#notify(s:loclist, a:nr)
    let s:loclist = []
  endif
endfunction


function! s:clear(nr)
  let s:loclist = []
  if has_key(g:_sign_map, a:nr)
    call validator#notifier#notify(s:loclist, a:nr)
  endif
endfunction


function! s:send_buffer(job, lines)
  let ch = job_getchannel(a:job)
  if ch_status(ch) == 'open'
    call ch_sendraw(ch, join(a:lines, "\n"))
    call ch_close_in(ch)
  endif
endfunction


function! s:check()
  let ft = &filetype
  if  pumvisible() || index(g:validator_ignore, ft) != -1 | return | endif

  let nr = bufnr('')
  if empty(ft)
    call s:clear(nr)
    return
  endif

  call s:manager.reset_jobs()

  let ext = expand('%:e')
  let ext = empty(ext) ? '' : '.'.ext
  let tail = fnamemodify(s:tempfile, ':t')
  let fname = 'temp'.tail.ext
  let tmp = fnamemodify(s:tempfile, ':s?'.tail.'$?'.fname.'?')

  let lines = getline(1, '$')
  if len(lines) == 1 && empty(lines[0])
    call s:clear(nr)
    return
  endif
{'fraction_non_alphanumeric': 0.14775725593667546, 'fraction_numerical': 0.007195970256656272, 'mean_word_length': 3.389473684210526, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3476585', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1641, 'n_words': 396}