<commit_before>" FIXME: Switch to using the global buffer data dictionary instead.
" Cleanup will work better if there isn't a second Dictionary we have to work
" with.
let s:buffer_data = {}
let s:job_info_map = {}

function! s:GatherOutput(job_id, line) abort
    if has_key(s:job_info_map, a:job_id)
        call add(s:job_info_map[a:job_id].output, a:line)
    endif
endfunction

function! ale#fix#ApplyQueuedFixes() abort
    let l:buffer = bufnr('')
    let l:data = get(s:buffer_data, l:buffer, {'done': 0})

    if !l:data.done
        return
    endif

    call remove(s:buffer_data, l:buffer)
    let l:lines = getbufline(l:buffer, 1, '$')

    if l:data.lines_before != l:lines
        echoerr 'The file was changed before fixing finished'
        return
    endif

    call setline(1, l:data.output)

    let l:start_line = len(l:data.output) + 1
    let l:end_line = len(l:lines)

    if l:end_line >= l:start_line
        let l:save = winsaveview()
        silent execute l:start_line . ',' . l:end_line . 'd'
        call winrestview(l:save)
    endif
endfunction

function! s:ApplyFixes(buffer, output) abort
    call ale#fix#RemoveManagedFiles(a:buffer)

    let s:buffer_data[a:buffer].output = a:output
    let s:buffer_data[a:buffer].done = 1

    " We can only change the lines of a buffer which is currently open,
    " so try and apply the fixes to the current buffer.
    call ale#fix#ApplyQueuedFixes()
endfunction
<commit_msg>Don't modify files when fixing doesn't change anything.<commit_after>" FIXME: Switch to using the global buffer data dictionary instead.
" Cleanup will work better if there isn't a second Dictionary we have to work
" with.
let s:buffer_data = {}
let s:job_info_map = {}

function! s:GatherOutput(job_id, line) abort
    if has_key(s:job_info_map, a:job_id)
        call add(s:job_info_map[a:job_id].output, a:line)
    endif
endfunction

function! ale#fix#ApplyQueuedFixes() abort
    let l:buffer = bufnr('')
    let l:data = get(s:buffer_data, l:buffer, {'done': 0})

    if !l:data.done
        return
    endif

    call remove(s:buffer_data, l:buffer)
    let l:lines = getbufline(l:buffer, 1, '$')

    if l:data.lines_before != l:lines
        echoerr 'The file was changed before fixing finished'
        return
    endif

    if l:data.lines_before == l:data.output
        " Don't modify the buffer if nothing has changed.
        return
    endif

    call setline(1, l:data.output)

    let l:start_line = len(l:data.output) + 1
    let l:end_line = len(l:lines)

    if l:end_line >= l:start_line
        let l:save = winsaveview()
        silent execute l:start_line . ',' . l:end_line . 'd'
        call winrestview(l:save)
    endif
endfunction

function! s:ApplyFixes(buffer, output) abort
    call ale#fix#RemoveManagedFiles(a:buffer)

    let s:buffer_data[a:buffer].output = a:output
    let s:buffer_data[a:buffer].done = 1

    " We can only change the lines of a buffer which is currently open,
    " so try and apply the fixes to the current buffer.
    call ale#fix#ApplyQueuedFixes()
endfunction

{'fraction_non_alphanumeric': 0.10474951203643461, 'fraction_numerical': 0.0032530904359141183, 'mean_word_length': 3.3309859154929575, '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': '4291785', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1026, 'n_words': 302}