<commit_before>" vim: ts=4 sw=4 et
scriptencoding utf-8

let s:level_to_name = {0: 'error  ', 1: 'warning', 2: 'verbose', 3: 'debug  '}
let s:short_level_to_name = {0: 'E', 1: 'W', 2: 'V', 3: 'D'}

" Use 'append' with writefile, but only if it is available.  Otherwise, just
" overwrite the file.  'S' is used to disable fsync in Neovim
" (https://github.com/neovim/neovim/pull/6427).
let s:can_append_to_logfile = v:version > 704 || (v:version == 704 && has('patch503'))
if !s:can_append_to_logfile
    redraw
    echohl WarningMsg
    echom 'Neomake: appending to the logfile is not supported in your Vim version.'
    echohl NONE
endif
let s:logfile_writefile_opts = s:can_append_to_logfile ? 'aS' : ''

function! s:reltime_lastmsg() abort
    if exists('s:last_msg_ts')
        let cur = neomake#compat#reltimefloat()
        let diff = (cur - s:last_msg_ts)
    else
        let diff = 0
    endif
    let s:last_msg_ts = neomake#compat#reltimefloat()

    if diff < 0.01
        return '     '
    elseif diff < 10
        let format = '+%.2f'
    elseif diff < 100
        let format = '+%.1f'
    elseif diff < 100
        let format = '  +%.0f'
    elseif diff < 1000
        let format = ' +%.0f'
    else
        let format = '+%.0f'
    endif
    return printf(format, diff)
endfunction

" Get verbosity, optionally based on jobinfo's make_id (a:1).
function! neomake#utils#get_verbosity(...) abort
    if a:0 && has_key(a:1, 'make_id')
        return neomake#GetMakeOptions(a:1.make_id).verbosity
    endif
    return get(g:, 'neomake_verbose', 1) + &verbose
endfunction

function! neomake#utils#LogMessage(level, msg, ...) abort
    if a:0
        let context = a:1
        let verbosity = neomake#utils#get_verbosity(context)
    else
        let context = {}  " just for vimlint (EVL104)
        let verbosity = neomake#utils#get_verbosity()
    endif
    let logfile = get(g:, 'neomake_logfile', '')

    let is_testing = exists('g:neomake_test_messages')
    if !is_testing && verbosity < a:level && logfile is# ''
        return
    endif

    if a:0
        let msg = printf('[%s.%s:%s:%d] %s',
                    \ get(context, 'make_id', '-'),
                    \ get(context, 'id', '-'),
                    \ get(context, 'bufnr', get(context, 'file_mode', 0) ? '?' : '-'),
                    \ winnr(),
                    \ a:msg)
    else
        let msg = a:msg
    endif

    " Use Vader's log for messages during tests.
    " @vimlint(EVL104, 1, l:timediff)
    if is_testing && (verbosity >= a:level || get(g:, 'neomake_test_log_all_messages', 0))
        let timediff = s:reltime_lastmsg()
        if timediff !=# '     '
            let test_msg = '['.s:short_level_to_name[a:level].' '.timediff.']: '.msg
        else
            let test_msg = '['.s:level_to_name[a:level].']: '.msg
        endif

        call vader#log(test_msg)
        " Only keep context entries that are relevant for / used in the message.
        let context = a:0
                    \ ? filter(copy(context), "index(['id', 'make_id', 'bufnr'], v:key) != -1")
                    \ : {}
        call add(g:neomake_test_messages, [a:level, a:msg, context])
        if index(['.', '!', ')', ']'], a:msg[-1:-1]) == -1
            Assert 0, 'Log msg does not end with punctuation: "'.a:msg.'".'
        endif
    elseif verbosity >= a:level
        redraw
        if a:level ==# 0
            echohl ErrorMsg
        endif
        if verbosity > 2
            if !exists('timediff')
                let timediff = s:reltime_lastmsg()
            endif
            echom 'Neomake ['.timediff.']: '.msg
        else
            echom 'Neomake: '.msg
        endif
        if a:level ==# 0
            echohl None
        endif
    endif
    if type(logfile) ==# type('') && !empty(logfile)
        let date = strftime('%H:%M:%S')
        if !exists('timediff')
            let timediff = s:reltime_lastmsg()
        endif
        call writefile([printf('%s [%s %s] %s',
                    \ date, s:short_level_to_name[a:level], timediff, msg)],
                    \ logfile, s:logfile_writefile_opts)
    endif
    " @vimlint(EVL104, 0, l:timediff)
endfunction

function! neomake#utils#ErrorMessage(...) abort
    call call('neomake#utils#LogMessage', [0] + a:000)
endfunction

function! neomake#utils#QuietMessage(...) abort
    call call('neomake#utils#LogMessage', [1] + a:000)
endfunction

function! neomake#utils#LoudMessage(...) abort
    call call('neomake#utils#LogMessage', [2] + a:000)<commit_msg>utils: move s:logfile_writefile_opts check<commit_after>" vim: ts=4 sw=4 et
scriptencoding utf-8

let s:level_to_name = {0: 'error  ', 1: 'warning', 2: 'verbose', 3: 'debug  '}
let s:short_level_to_name = {0: 'E', 1: 'W', 2: 'V', 3: 'D'}

function! s:reltime_lastmsg() abort
    if exists('s:last_msg_ts')
        let cur = neomake#compat#reltimefloat()
        let diff = (cur - s:last_msg_ts)
    else
        let diff = 0
    endif
    let s:last_msg_ts = neomake#compat#reltimefloat()

    if diff < 0.01
        return '     '
    elseif diff < 10
        let format = '+%.2f'
    elseif diff < 100
        let format = '+%.1f'
    elseif diff < 100
        let format = '  +%.0f'
    elseif diff < 1000
        let format = ' +%.0f'
    else
        let format = '+%.0f'
    endif
    return printf(format, diff)
endfunction

" Get verbosity, optionally based on jobinfo's make_id (a:1).
function! neomake#utils#get_verbosity(...) abort
    if a:0 && has_key(a:1, 'make_id')
        return neomake#GetMakeOptions(a:1.make_id).verbosity
    endif
    return get(g:, 'neomake_verbose', 1) + &verbose
endfunction

function! neomake#utils#LogMessage(level, msg, ...) abort
    if a:0
        let context = a:1
        let verbosity = neomake#utils#get_verbosity(context)
    else
        let context = {}  " just for vimlint (EVL104)
        let verbosity = neomake#utils#get_verbosity()
    endif
    let logfile = get(g:, 'neomake_logfile', '')

    let is_testing = exists('g:neomake_test_messages')
    if !is_testing && verbosity < a:level && logfile is# ''
        return
    endif

    if a:0
        let msg = printf('[%s.%s:%s:%d] %s',
                    \ get(context, 'make_id', '-'),
                    \ get(context, 'id', '-'),
                    \ get(context, 'bufnr', get(context, 'file_mode', 0) ? '?' : '-'),
                    \ winnr(),
                    \ a:msg)
    else
        let msg = a:msg
    endif

    " Use Vader's log for messages during tests.
    " @vimlint(EVL104, 1, l:timediff)
    if is_testing && (verbosity >= a:level || get(g:, 'neomake_test_log_all_messages', 0))
        let timediff = s:reltime_lastmsg()
        if timediff !=# '     '
            let test_msg = '['.s:short_level_to_name[a:level].' '.timediff.']: '.msg
        else
            let test_msg = '['.s:level_to_name[a:level].']: '.msg
        endif

        call vader#log(test_msg)
        " Only keep context entries that are relevant for / used in the message.
        let context = a:0
                    \ ? filter(copy(context), "index(['id', 'make_id', 'bufnr'], v:key) != -1")
                    \ : {}
        call add(g:neomake_test_messages, [a:level, a:msg, context])
        if index(['.', '!', ')', ']'], a:msg[-1:-1]) == -1
            Assert 0, 'Log msg does not end with punctuation: "'.a:msg.'".'
        endif
    elseif verbosity >= a:level
        redraw
        if a:level ==# 0
            echohl ErrorMsg
        endif
        if verbosity > 2
            if !exists('timediff')
                let timediff = s:reltime_lastmsg()
            endif
            echom 'Neomake ['.timediff.']: '.msg
        else
            echom 'Neomake: '.msg
        endif
        if a:level ==# 0
            echohl None
        endif
    endif
    if !empty(logfile) && type(logfile) ==# type('')
        if !exists('s:logfile_writefile_opts')
            " Use 'append' with writefile, but only if it is available.  Otherwise, just
            " overwrite the file.  'S' is used to disable fsync in Neovim
            " (https://github.com/neovim/neovim/pull/6427).
            let s:can_append_to_logfile = v:version > 704 || (v:version == 704 && has('patch503'))
            if !s:can_append_to_logfile
                redraw
                echohl WarningMsg
                echom 'Neomake: appending to the logfile is not supported in your Vim version.'
                echohl NONE
            endif
            let s:logfile_writefile_opts = s:can_append_to_logfile ? 'aS' : ''
        endif

        let date = strftime('%H:%M:%S')
        if !exists('timediff')
            let timediff = s:reltime_lastmsg()
        endif
        call writefile([printf('%s [%s %s] %s',
                    \ date, s:short_level_to_name[a:level], timediff, msg)],
                    \ logfile, s:logfile_writefile_opts)
    endif
    " @vimlint(EVL104, 0, l:timediff)
endfunction

function! neomake#utils#ErrorMessage(...) abort
    call call('neomake#utils#LogMessage', [0] + a:000)
endfunction

function! neomake#utils#QuietMessage(...) abort
    call call('neomake#utils#LogMessage', [1] + a:000)
endfunction

function! neomake#utils#LoudMessage(...) abort
    call call('neomake#utils#LogMessage', [2] + a:000)
{'fraction_non_alphanumeric': 0.1406655142610199, 'fraction_numerical': 0.018798617113223854, 'mean_word_length': 2.18000687049124, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '6581525', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3104, 'n_words': 779}