<commit_before>" Vlime Connection constructor.
" vlime#New([cb_data[, ui]])
function! vlime#New(...)
    let cb_data = s:GetNthVarArg(a:000, 0)
    let ui = s:GetNthVarArg(a:000, 1)
    let obj = {
                \ 'cb_data': cb_data,
                \ 'channel': v:null,
                \ 'remote_prefix': '',
                \ 'ping_tag': 1,
                \ 'ui': ui,
                \ 'Connect': function('vlime#Connect'),
                \ 'IsConnected': function('vlime#IsConnected'),
                \ 'Close': function('vlime#Close'),
                \ 'Call': function('vlime#Call'),
                \ 'Send': function('vlime#Send'),
                \ 'FixRemotePath': function('vlime#FixRemotePath'),
                \ 'FixLocalPath': function('vlime#FixLocalPath'),
                \ 'GetCurrentPackage': function('vlime#GetCurrentPackage'),
                \ 'SetCurrentPackage': function('vlime#SetCurrentPackage'),
                \ 'GetCurrentThread': function('vlime#GetCurrentThread'),
                \ 'SetCurrentThread': function('vlime#SetCurrentThread'),
                \ 'WithPackage': function('vlime#WithPackage'),
                \ 'WithThread': function('vlime#WithThread'),
                \ 'EmacsRex': function('vlime#EmacsRex'),
                \ 'Ping': function('vlime#Ping'),
                \ 'Pong': function('vlime#Pong'),
                \ 'ConnectionInfo': function('vlime#ConnectionInfo'),
                \ 'SwankRequire': function('vlime#SwankRequire'),
                \ 'CreateREPL': function('vlime#CreateREPL'),
                \ 'ListenerEval': function('vlime#ListenerEval'),
                \ 'SetPackage': function('vlime#SetPackage'),
                \ 'DescribeSymbol': function('vlime#DescribeSymbol'),
                \ 'OperatorArgList': function('vlime#OperatorArgList'),
                \ 'SimpleCompletions': function('vlime#SimpleCompletions'),
                \ 'FuzzyCompletions': function('vlime#FuzzyCompletions'),
                \ 'ReturnString': function('vlime#ReturnString'),
                \ 'Return': function('vlime#Return'),
                \ 'SwankMacroExpandOne': function('vlime#SwankMacroExpandOne'),
                \ 'SwankMacroExpand': function('vlime#SwankMacroExpand'),
                \ 'SwankMacroExpandAll': function('vlime#SwankMacroExpandAll'),
                \ 'DisassembleForm': function('vlime#DisassembleForm'),
                \ 'CompileStringForEmacs': function('vlime#CompileStringForEmacs'),
                \ 'CompileFileForEmacs': function('vlime#CompileFileForEmacs'),
                \ 'LoadFile': function('vlime#LoadFile'),
                \ 'XRef': function('vlime#XRef'),
                \ 'FindDefinitionsForEmacs': function('vlime#FindDefinitionsForEmacs'),
                \ 'AproposListForEmacs': function('vlime#AproposListForEmacs'),
                \ 'DocumentationSymbol': function('vlime#DocumentationSymbol'),
                \ 'Interrupt': function('vlime#Interrupt'),
                \ 'SLDBAbort': function('vlime#SLDBAbort'),
                \ 'SLDBBreak': function('vlime#SLDBBreak'),
                \ 'SLDBContinue': function('vlime#SLDBContinue'),
                \ 'SLDBStep': function('vlime#SLDBStep'),
                \ 'SLDBNext': function('vlime#SLDBNext'),
                \ 'SLDBOut': function('vlime#SLDBOut'),
                \ 'SLDBReturnFromFrame': function('vlime#SLDBReturnFromFrame'),
                \ 'SLDBDisassemble': function('vlime#SLDBDisassemble'),
                \ 'InvokeNthRestartForEmacs': function('vlime#InvokeNthRestartForEmacs'),
                \ 'RestartFrame': function('vlime#RestartFrame'),
                \ 'FrameLocalsAndCatchTags': function('vlime#FrameLocalsAndCatchTags'),
                \ 'FrameSourceLocation': function('vlime#FrameSourceLocation'),
                \ 'EvalStringInFrame': function('vlime#EvalStringInFrame'),
                \ 'InitInspector': function('vlime#InitInspector'),
                \ 'InspectorReinspect': function('vlime#InspectorReinspect'),
                \ 'InspectorRange': function('vlime#InspectorRange'),
                \ 'InspectNthPart': function('vlime#InspectNthPart'),
                \ 'InspectorCallNthAction': function('vlime#InspectorCallNthAction'),
                \ 'InspectorPop': function('vlime#InspectorPop'),
                \ 'InspectCurrentCondition': function('vlime#InspectCurrentCondition'),
                \ 'InspectInFrame': function('vlime#InspectInFrame'),
                \ 'InspectPresentation': function('vlime#InspectPresentation'),
                \ 'ListThreads': function('vlime#ListThreads'),
                \ 'KillNthThread': function('vlime#KillNthThread'),
                \ 'DebugNthThread': function('vlime#DebugNthThread'),
                \ 'UndefineFunction': function('vlime#UndefineFunction'),
                \ 'UninternSymbol': function('vlime#UninternSymbol'),
                \ 'OnServerEvent': function('vlime#OnServerEvent'),
                \ 'server_event_handlers': {
                    \ 'PING': function('vlime#OnPing'),
                    \ 'NEW-PACKAGE': function('vlime#OnNewPackage'),
                    \ 'DEBUG': function('vlime#OnDebug'),
                    \ 'DEBUG-ACTIVATE': function('vlime#OnDebugActivate'),
                    \ 'DEBUG-RETURN': function('vlime#OnDebugReturn'),
                    \ 'WRITE-STRING': function('vlime#OnWriteString'),
                    \ 'READ-STRING': function('vlime#OnReadString'),
                    \ 'READ-FROM-MINIBUFFER': function('vlime#OnReadFromMiniBuffer'),
                    \ 'INDENTATION-UPDATE': function('vlime#OnIndentationUpdate'),
                    \ 'INVALID-RPC': function('vlime#OnInvalidRPC'),
                    \ 'INSPECT': function('vlime#OnInspect'),
                    \ }
                \ }
    return obj
endfunction

" ================== methods for vlime connections ==================

" vlime#Connect(host, port[, remote_prefix])
function! vlime#Connect(host, port, ...) dict
    let self.channel = vlime#compat#ch_open(a:host, a:port,
                \ {chan, msg -> self.OnServerEvent(chan, msg)})
    " XXX: There should be a better way to wait for ncat
    sleep 500m
    if vlime#compat#ch_status(self.channel) != 'open'
        call self.Close()
        throw 'vlime#Connect: failed to open channel'
    endif

    let remote_prefix = vlime#GetNthVarArg(a:000, 0, '')
    let self['remote_prefix'] = remote_prefix

    return self
endfunction

function! vlime#IsConnected() dict
    return type(self.channel) == vlime#compat#ch_type() &&
                \ vlime#compat#ch_status(self.channel) == 'open'
endfunction

function! vlime#Close() dict
    if type(self.channel) == vlime#compat#ch_type()
        try
            call vlime#compat#ch_close(self.channel)
        catch /^Vim\%((\a\+)\)\=:E906/  " Not an open channel
        endtry
        let self.channel = v:null
    endif<commit_msg>Catch the correct exception when closing the connections<commit_after>" Vlime Connection constructor.
" vlime#New([cb_data[, ui]])
function! vlime#New(...)
    let cb_data = s:GetNthVarArg(a:000, 0)
    let ui = s:GetNthVarArg(a:000, 1)
    let obj = {
                \ 'cb_data': cb_data,
                \ 'channel': v:null,
                \ 'remote_prefix': '',
                \ 'ping_tag': 1,
                \ 'ui': ui,
                \ 'Connect': function('vlime#Connect'),
                \ 'IsConnected': function('vlime#IsConnected'),
                \ 'Close': function('vlime#Close'),
                \ 'Call': function('vlime#Call'),
                \ 'Send': function('vlime#Send'),
                \ 'FixRemotePath': function('vlime#FixRemotePath'),
                \ 'FixLocalPath': function('vlime#FixLocalPath'),
                \ 'GetCurrentPackage': function('vlime#GetCurrentPackage'),
                \ 'SetCurrentPackage': function('vlime#SetCurrentPackage'),
                \ 'GetCurrentThread': function('vlime#GetCurrentThread'),
                \ 'SetCurrentThread': function('vlime#SetCurrentThread'),
                \ 'WithPackage': function('vlime#WithPackage'),
                \ 'WithThread': function('vlime#WithThread'),
                \ 'EmacsRex': function('vlime#EmacsRex'),
                \ 'Ping': function('vlime#Ping'),
                \ 'Pong': function('vlime#Pong'),
                \ 'ConnectionInfo': function('vlime#ConnectionInfo'),
                \ 'SwankRequire': function('vlime#SwankRequire'),
                \ 'CreateREPL': function('vlime#CreateREPL'),
                \ 'ListenerEval': function('vlime#ListenerEval'),
                \ 'SetPackage': function('vlime#SetPackage'),
                \ 'DescribeSymbol': function('vlime#DescribeSymbol'),
                \ 'OperatorArgList': function('vlime#OperatorArgList'),
                \ 'SimpleCompletions': function('vlime#SimpleCompletions'),
                \ 'FuzzyCompletions': function('vlime#FuzzyCompletions'),
                \ 'ReturnString': function('vlime#ReturnString'),
                \ 'Return': function('vlime#Return'),
                \ 'SwankMacroExpandOne': function('vlime#SwankMacroExpandOne'),
                \ 'SwankMacroExpand': function('vlime#SwankMacroExpand'),
                \ 'SwankMacroExpandAll': function('vlime#SwankMacroExpandAll'),
                \ 'DisassembleForm': function('vlime#DisassembleForm'),
                \ 'CompileStringForEmacs': function('vlime#CompileStringForEmacs'),
                \ 'CompileFileForEmacs': function('vlime#CompileFileForEmacs'),
                \ 'LoadFile': function('vlime#LoadFile'),
                \ 'XRef': function('vlime#XRef'),
                \ 'FindDefinitionsForEmacs': function('vlime#FindDefinitionsForEmacs'),
                \ 'AproposListForEmacs': function('vlime#AproposListForEmacs'),
                \ 'DocumentationSymbol': function('vlime#DocumentationSymbol'),
                \ 'Interrupt': function('vlime#Interrupt'),
                \ 'SLDBAbort': function('vlime#SLDBAbort'),
                \ 'SLDBBreak': function('vlime#SLDBBreak'),
                \ 'SLDBContinue': function('vlime#SLDBContinue'),
                \ 'SLDBStep': function('vlime#SLDBStep'),
                \ 'SLDBNext': function('vlime#SLDBNext'),
                \ 'SLDBOut': function('vlime#SLDBOut'),
                \ 'SLDBReturnFromFrame': function('vlime#SLDBReturnFromFrame'),
                \ 'SLDBDisassemble': function('vlime#SLDBDisassemble'),
                \ 'InvokeNthRestartForEmacs': function('vlime#InvokeNthRestartForEmacs'),
                \ 'RestartFrame': function('vlime#RestartFrame'),
                \ 'FrameLocalsAndCatchTags': function('vlime#FrameLocalsAndCatchTags'),
                \ 'FrameSourceLocation': function('vlime#FrameSourceLocation'),
                \ 'EvalStringInFrame': function('vlime#EvalStringInFrame'),
                \ 'InitInspector': function('vlime#InitInspector'),
                \ 'InspectorReinspect': function('vlime#InspectorReinspect'),
                \ 'InspectorRange': function('vlime#InspectorRange'),
                \ 'InspectNthPart': function('vlime#InspectNthPart'),
                \ 'InspectorCallNthAction': function('vlime#InspectorCallNthAction'),
                \ 'InspectorPop': function('vlime#InspectorPop'),
                \ 'InspectCurrentCondition': function('vlime#InspectCurrentCondition'),
                \ 'InspectInFrame': function('vlime#InspectInFrame'),
                \ 'InspectPresentation': function('vlime#InspectPresentation'),
                \ 'ListThreads': function('vlime#ListThreads'),
                \ 'KillNthThread': function('vlime#KillNthThread'),
                \ 'DebugNthThread': function('vlime#DebugNthThread'),
                \ 'UndefineFunction': function('vlime#UndefineFunction'),
                \ 'UninternSymbol': function('vlime#UninternSymbol'),
                \ 'OnServerEvent': function('vlime#OnServerEvent'),
                \ 'server_event_handlers': {
                    \ 'PING': function('vlime#OnPing'),
                    \ 'NEW-PACKAGE': function('vlime#OnNewPackage'),
                    \ 'DEBUG': function('vlime#OnDebug'),
                    \ 'DEBUG-ACTIVATE': function('vlime#OnDebugActivate'),
                    \ 'DEBUG-RETURN': function('vlime#OnDebugReturn'),
                    \ 'WRITE-STRING': function('vlime#OnWriteString'),
                    \ 'READ-STRING': function('vlime#OnReadString'),
                    \ 'READ-FROM-MINIBUFFER': function('vlime#OnReadFromMiniBuffer'),
                    \ 'INDENTATION-UPDATE': function('vlime#OnIndentationUpdate'),
                    \ 'INVALID-RPC': function('vlime#OnInvalidRPC'),
                    \ 'INSPECT': function('vlime#OnInspect'),
                    \ }
                \ }
    return obj
endfunction

" ================== methods for vlime connections ==================

" vlime#Connect(host, port[, remote_prefix])
function! vlime#Connect(host, port, ...) dict
    let self.channel = vlime#compat#ch_open(a:host, a:port,
                \ {chan, msg -> self.OnServerEvent(chan, msg)})
    " XXX: There should be a better way to wait for ncat
    sleep 500m
    if vlime#compat#ch_status(self.channel) != 'open'
        call self.Close()
        throw 'vlime#Connect: failed to open channel'
    endif

    let remote_prefix = vlime#GetNthVarArg(a:000, 0, '')
    let self['remote_prefix'] = remote_prefix

    return self
endfunction

function! vlime#IsConnected() dict
    return type(self.channel) == vlime#compat#ch_type() &&
                \ vlime#compat#ch_status(self.channel) == 'open'
endfunction

function! vlime#Close() dict
    if type(self.channel) == vlime#compat#ch_type()
        try
            call vlime#compat#ch_close(self.channel)
        catch /^vlime#compat#.*not an open channel.*/
        endtry
        let self.channel = v:null
    endif
{'fraction_non_alphanumeric': 0.1470651472801548, 'fraction_numerical': 0.002508421128072816, 'mean_word_length': 2.339875538535184, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4190509', 'n_tokens_mistral': 4039, 'n_tokens_neox': 3822, 'n_words': 545}