<commit_before>if !exists("g:go_gorename_bin")
    let g:go_gorename_bin = "gorename"
endif

function! go#rename#Rename(bang, ...)
    let to = ""
    if a:0 == 0
        let from = expand("<cword>")
        let ask = printf("vim-go: rename '%s' to: ", from)
        let to = input(ask, from)
        redraw
    else
        let to = a:1
    endif

    "return with a warning if the bin doesn't exist
    let bin_path = go#path#CheckBinPath(g:go_gorename_bin) 
    if empty(bin_path) 
        return 
    endif

    let fname = expand('%:p')
    let pos = s:getpos(line('.'), col('.'))
    let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))

    let out = go#tool#ExecuteInDir(cmd)

    " strip out newline on the end that gorename puts. If we don't remove, it
    " will trigger the 'Hit ENTER to continue' prompt
    let clean = split(out, '\n')

    if v:shell_error
        let errors = go#tool#ParseErrors(split(out, '\n'))
        call go#list#Populate(errors)
        call go#list#Window(len(errors))
        if !empty(errors) && !a:bang
            call go#list#JumpToFirst()
        endif
        return
    else
        call go#list#Clean()
        call go#list#Window()
        redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
    endif

    " refresh the buffer so we can see the new content
    " TODO(arslan): also find all other buffers and refresh them too. For this
    " we need a way to get the list of changes from gorename upon an success
    " change.
    silent execute ":e"
endfunction

func! s:getpos(l, c)<commit_msg>gorename: Output original error if error parsing fails.<commit_after>if !exists("g:go_gorename_bin")
    let g:go_gorename_bin = "gorename"
endif

function! go#rename#Rename(bang, ...)
    let to = ""
    if a:0 == 0
        let from = expand("<cword>")
        let ask = printf("vim-go: rename '%s' to: ", from)
        let to = input(ask, from)
        redraw
    else
        let to = a:1
    endif

    "return with a warning if the bin doesn't exist
    let bin_path = go#path#CheckBinPath(g:go_gorename_bin) 
    if empty(bin_path) 
        return 
    endif

    let fname = expand('%:p')
    let pos = s:getpos(line('.'), col('.'))
    let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))

    let out = go#tool#ExecuteInDir(cmd)

    " strip out newline on the end that gorename puts. If we don't remove, it
    " will trigger the 'Hit ENTER to continue' prompt
    let clean = split(out, '\n')

    if v:shell_error
        let errors = go#tool#ParseErrors(split(out, '\n'))
        call go#list#Populate(errors)
        call go#list#Window(len(errors))
        if !empty(errors) && !a:bang
            call go#list#JumpToFirst()
        elseif empty(errors)
            " failed to parse errors, output the original content
            call go#util#EchoError(out)
        endif
        return
    else
        call go#list#Clean()
        call go#list#Window()
        redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
    endif

    " refresh the buffer so we can see the new content
    " TODO(arslan): also find all other buffers and refresh them too. For this
    " we need a way to get the list of changes from gorename upon an success
    " change.
    silent execute ":e"
endfunction

func! s:getpos(l, c)
{'fraction_non_alphanumeric': 0.11904073967061543, 'fraction_numerical': 0.0023114706732158337, 'mean_word_length': 2.591286307053942, 'pattern_counts': {'":': 2, '<': 5, '<?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': '1839256', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1128, 'n_words': 366}