<commit_before>if !exists('g:vlime_cl_wait_time')
    let g:vlime_cl_wait_time = 10 " seconds
endif

if !exists('g:vlime_cl_wait_interval')
    let g:vlime_cl_wait_interval = 500 " milliseconds
endif

if !exists('g:vlime_servers')
    let g:vlime_servers = {}
endif

if !exists('g:vlime_next_server_id')
    let g:vlime_next_server_id = 1
endif

let s:cur_src_path = resolve(expand('<sfile>:p'))
let s:vlime_home = fnamemodify(s:cur_src_path, ':h:h:h:h')
let s:path_sep = s:cur_src_path[len(s:vlime_home)]

" vlime#server#New([auto_connect[, use_terminal[, name[, cl_impl]]]])
function! vlime#server#New(...)
    let auto_connect = get(a:000, 0, v:true)
    let use_terminal = get(a:000, 1, v:false)
    let name = get(a:000, 2, v:null)
    let cl_impl = get(a:000, 3, v:null)

    if type(name) != type(v:null)
        let server_name = name
    else
        let server_name = 'Vlime Server ' . g:vlime_next_server_id
    endif
    let server_buf_name = vlime#ui#ServerBufName(server_name)
    let dummy_server_buf = vlime#ui#OpenBufferWithWinSettings(server_buf_name, v:true, 'server')
    call vlime#ui#SetVlimeBufferOpts(dummy_server_buf, v:null)

    let server_obj = {
                \ 'id': g:vlime_next_server_id,
                \ 'name': server_name,
                \ 'auto_connect': auto_connect,
                \ 'use_terminal': use_terminal,
                \ 'cl_impl': cl_impl,
                \ }

    let server_job = vlime#compat#job_start(
                \ vlime#server#BuildServerCommand(cl_impl),
                \ {
                    \ 'buf_name': server_buf_name,
                    \ 'callback': function('s:ServerOutputCB', [server_obj, auto_connect]),
                    \ 'exit_cb': function('s:ServerExitCB', [server_obj]),
                    \ 'use_terminal': use_terminal,
                \ })
    if vlime#compat#job_status(server_job) != 'run'
        call vlime#ui#WithBuffer(dummy_server_buf,
                    \ {-> s:AppendToServerBuf('Failed to start server.')})
        throw 'vlime#server#New: failed to start server job'
    endif

    let server_obj['job'] = server_job
    let g:vlime_servers[g:vlime_next_server_id] = server_obj
    let g:vlime_next_server_id += 1

    let server_buf = vlime#compat#job_getbufnr(server_job)
    call vlime#ui#WithBuffer(server_buf, function('vlime#ui#MapBufferKeys', ['server']))
    call setbufvar(server_buf, '&filetype', 'vlime_server')
    call setbufvar(server_buf, 'vlime_server', server_obj)
    hide

    return server_obj
endfunction

function! vlime#server#Stop(server)
    let server_id = s:NormalizeServerID(a:server)
    let r_server = g:vlime_servers[server_id]

    if !vlime#compat#job_stop(r_server['job'])<commit_msg>Don't hide the server buffer.<commit_after>if !exists('g:vlime_cl_wait_time')
    let g:vlime_cl_wait_time = 10 " seconds
endif

if !exists('g:vlime_cl_wait_interval')
    let g:vlime_cl_wait_interval = 500 " milliseconds
endif

if !exists('g:vlime_servers')
    let g:vlime_servers = {}
endif

if !exists('g:vlime_next_server_id')
    let g:vlime_next_server_id = 1
endif

let s:cur_src_path = resolve(expand('<sfile>:p'))
let s:vlime_home = fnamemodify(s:cur_src_path, ':h:h:h:h')
let s:path_sep = s:cur_src_path[len(s:vlime_home)]

" vlime#server#New([auto_connect[, use_terminal[, name[, cl_impl]]]])
function! vlime#server#New(...)
    let auto_connect = get(a:000, 0, v:true)
    let use_terminal = get(a:000, 1, v:false)
    let name = get(a:000, 2, v:null)
    let cl_impl = get(a:000, 3, v:null)

    if type(name) != type(v:null)
        let server_name = name
    else
        let server_name = 'Vlime Server ' . g:vlime_next_server_id
    endif
    let server_buf_name = vlime#ui#ServerBufName(server_name)
    let dummy_server_buf = vlime#ui#OpenBufferWithWinSettings(server_buf_name, v:true, 'server')
    call vlime#ui#SetVlimeBufferOpts(dummy_server_buf, v:null)

    let server_obj = {
                \ 'id': g:vlime_next_server_id,
                \ 'name': server_name,
                \ 'auto_connect': auto_connect,
                \ 'use_terminal': use_terminal,
                \ 'cl_impl': cl_impl,
                \ }

    let server_job = vlime#compat#job_start(
                \ vlime#server#BuildServerCommand(cl_impl),
                \ {
                    \ 'buf_name': server_buf_name,
                    \ 'callback': function('s:ServerOutputCB', [server_obj, auto_connect]),
                    \ 'exit_cb': function('s:ServerExitCB', [server_obj]),
                    \ 'use_terminal': use_terminal,
                \ })
    if vlime#compat#job_status(server_job) != 'run'
        call vlime#ui#WithBuffer(dummy_server_buf,
                    \ {-> s:AppendToServerBuf('Failed to start server.')})
        throw 'vlime#server#New: failed to start server job'
    endif

    let server_obj['job'] = server_job
    let g:vlime_servers[g:vlime_next_server_id] = server_obj
    let g:vlime_next_server_id += 1

    let server_buf = vlime#compat#job_getbufnr(server_job)
    call vlime#ui#WithBuffer(server_buf, function('vlime#ui#MapBufferKeys', ['server']))
    call setbufvar(server_buf, '&filetype', 'vlime_server')
    call setbufvar(server_buf, 'vlime_server', server_obj)
    "hide

    return server_obj
endfunction

function! vlime#server#Stop(server)
    let server_id = s:NormalizeServerID(a:server)
    let r_server = g:vlime_servers[server_id]

    if !vlime#compat#job_stop(r_server['job'])
{'fraction_non_alphanumeric': 0.12465678198791873, 'fraction_numerical': 0.008420281896393923, 'mean_word_length': 3.2160493827160495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2949823', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1930, 'n_words': 337}