<commit_before>function! lsc#channel#open(command, Callback, ErrCallback, OnExit) abort
  let l:c = s:Channel()
  if type(a:command) == type('') && a:command =~# '[^:]\+:\d\+'
    if !exists('*ch_open')
      call lsc#message#error('No support for sockets for '.a:command)
      return v:null
    endif
    let l:channel_options = {'mode': 'raw',
        \ 'callback': {_, message -> a:Callback(message)},
        \ 'close_cb': {_ -> a:OnExit()}}
    call s:WrapVim(ch_open(a:command, l:channel_options), l:c)
    return l:c
  endif
  if exists('*job_start')
    let l:job_options = {'in_io': 'pipe', 'in_mode': 'raw',
        \ 'out_io': 'pipe', 'out_mode': 'raw',
        \ 'out_cb': {_, message -> a:Callback(message)},
        \ 'err_io': 'pipe', 'err_mode': 'nl',
        \ 'err_cb': {_, message -> a:ErrCallback(message)},
        \ 'exit_cb': {_, __ -> a:OnExit()}}
    let l:job = job_start(a:command, l:job_options)
    call s:WrapVim(job_getchannel(l:job), l:c)
    return l:c
  elseif exists('*jobstart')
    let l:job_options = {
        \ 'on_stdout': {_, data, __ -> a:Callback(join(data, "\n"))},
        \ 'on_stderr': {_, data, __ ->
        \     data == [''] ? v:null : a:ErrCallback(join(data, "\n"))},
        \ 'on_exit': {_, __, ___ -> a:OnExit()}}
    let l:job = jobstart(a:command, l:job_options)
    call s:WrapNeovim(l:job, l:c)
    return l:c
  endif

  call lsc#message#error('Cannot start '.a:command)
  return v:null
endfunction

function! s:Channel() abort
  let l:c = {'send_buffer': ''}<commit_msg>Support TCP sockets in neovim (#323)<commit_after>function! lsc#channel#open(command, Callback, ErrCallback, OnExit) abort
  let l:c = s:Channel()
  if type(a:command) == type('') && a:command =~# '[^:]\+:\d\+'
    if exists('*ch_open')
      let l:channel_options = {'mode': 'raw',
          \ 'callback': {_, message -> a:Callback(message)},
          \ 'close_cb': {_ -> a:OnExit()}}
      call s:WrapVim(ch_open(a:command, l:channel_options), l:c)
      return l:c
    elseif exists('*sockconnect')
      let l:channel_options = {
            \ 'on_data': {_, data, __ -> a:Callback(join(data, "\n"))}}
      let l:channel = sockconnect('tcp', a:command, l:channel_options)
      call s:WrapNeovim(l:channel, l:c)
      return l:c
    else
      call lsc#message#error('No support for sockets for '.a:command)
      return v:null
    endif
  endif
  if exists('*job_start')
    let l:job_options = {'in_io': 'pipe', 'in_mode': 'raw',
        \ 'out_io': 'pipe', 'out_mode': 'raw',
        \ 'out_cb': {_, message -> a:Callback(message)},
        \ 'err_io': 'pipe', 'err_mode': 'nl',
        \ 'err_cb': {_, message -> a:ErrCallback(message)},
        \ 'exit_cb': {_, __ -> a:OnExit()}}
    let l:job = job_start(a:command, l:job_options)
    call s:WrapVim(job_getchannel(l:job), l:c)
    return l:c
  elseif exists('*jobstart')
    let l:job_options = {
        \ 'on_stdout': {_, data, __ -> a:Callback(join(data, "\n"))},
        \ 'on_stderr': {_, data, __ ->
        \     data == [''] ? v:null : a:ErrCallback(join(data, "\n"))},
        \ 'on_exit': {_, __, ___ -> a:OnExit()}}
    let l:job = jobstart(a:command, l:job_options)
    call s:WrapNeovim(l:job, l:c)
    return l:c
  endif

  call lsc#message#error('Cannot start '.a:command)
  return v:null
endfunction

function! s:Channel() abort
  let l:c = {'send_buffer': ''}
{'fraction_non_alphanumeric': 0.19893270085976875, 'fraction_numerical': 0.0008894159501927068, 'mean_word_length': 3.139877300613497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '4505640', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1246, 'n_words': 252}