<commit_before>" Author: Baabelfish
" Description: Typechecking for nim files

function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
    let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
    let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        " Only show errors of the current buffer
        " NOTE: Checking filename only is OK because nim enforces unique
        "       module names.

        let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t')
        if l:buffer_filename !=# '' && l:temp_buffer_filename !=# l:buffer_filename
            continue
        endif

        let l:line = l:match[2] + 0
        let l:column = l:match[3] + 0
        let l:text = l:match[4]
        let l:type = 'W'

        " Extract error type from message of type 'Error: Some error message'
        let l:textmatch = matchlist(l:match[4], '^\(.\{-}\): .\+$')

        if len(l:textmatch) > 0
            let l:errortype = l:textmatch[1]
            if l:errortype ==# 'Error'
                let l:type = 'E'
            endif
        endif

        call add(l:output, {
        \   'lnum': l:line,
        \   'col': l:column,
        \   'text': l:text,
        \   'type': l:type,
        \})
    endfor

    return l:output
endfunction


function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
    let l:directory = ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))

    return 'nim check --path:' . l:directory
    \   . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t'
endfunction


call ale#linter#Define('nim', {
\    'name': 'nimcheck',
\    'executable': 'nim',
\    'output_stream': 'both',
\    'command_callback': 'ale_linters#nim#nimcheck#GetCommand',
\    'callback': 'ale_linters#nim#nimcheck#Handle'
\})<commit_msg>#620 Check the Nim files on disk instead<commit_after>" Author: Baabelfish
" Description: Typechecking for nim files

function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
    let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
    let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        " Only show errors of the current buffer
        " NOTE: Checking filename only is OK because nim enforces unique
        "       module names.

        let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t')
        if l:buffer_filename !=# '' && l:temp_buffer_filename !=# l:buffer_filename
            continue
        endif

        let l:line = l:match[2] + 0
        let l:column = l:match[3] + 0
        let l:text = l:match[4]
        let l:type = 'W'

        " Extract error type from message of type 'Error: Some error message'
        let l:textmatch = matchlist(l:match[4], '^\(.\{-}\): .\+$')

        if len(l:textmatch) > 0
            let l:errortype = l:textmatch[1]
            if l:errortype ==# 'Error'
                let l:type = 'E'
            endif
        endif

        call add(l:output, {
        \   'lnum': l:line,
        \   'col': l:column,
        \   'text': l:text,
        \   'type': l:type,
        \})
    endfor

    return l:output
endfunction


function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
    return 'nim check --verbosity:0 --colors:off --listFullPaths %s'
endfunction


call ale#linter#Define('nim', {
\    'name': 'nimcheck',
\    'executable': 'nim',
\    'output_stream': 'both',
\    'command_callback': 'ale_linters#nim#nimcheck#GetCommand',
\    'callback': 'ale_linters#nim#nimcheck#Handle',
\    'lint_file': 1,
\})
{'fraction_non_alphanumeric': 0.15905985241869364, 'fraction_numerical': 0.006559169171904892, 'mean_word_length': 2.4301780693533273, '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': '3801136', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1267, 'n_words': 286}