<commit_before>if !exists("g:go_godef_bin")
	let g:go_godef_bin = "godef"
endif


" modified and improved version of vim-godef
function! go#def#Jump(...)
	if !len(a:000)
		" gives us the offset of the word, basicall the position of the word under
		" he cursor
		let arg = s:getOffset()
	else
		let arg = a:1
	endif

	let bin_path = go#tool#BinPath(g:go_godef_bin)
	if empty(bin_path)
		return
	endif

	let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)

	" get output of godef
	let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))

	" jump to it
	call s:godefJump(out, "")
endfunction


function! go#def#JumpMode(mode)
	let arg = s:getOffset()

	let bin_path = go#tool#BinPath(g:go_godef_bin)
	if empty(bin_path)
		return
	endif

	let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)

	" get output of godef
	let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))

	call s:godefJump(out, a:mode)
endfunction


function! s:getOffset()
	let pos = getpos(".")[1:2]
	if &encoding == 'utf-8'
		let offs = line2byte(pos[0]) + pos[1] - 2
	else
		let c = pos[1]
		let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), "\n") . "\n")
		let buf .= c == 1 ? "" : getline(pos[0])[:c-2]
		let offs = len(iconv(buf, &encoding, "utf-8"))
	endif

	let argOff = "-o=" . offs
	return argOff
endfunction


function! s:godefJump(out, mode)
	let old_errorformat = &errorformat
	let &errorformat = "%f:%l:%c"

	if a:out =~ 'godef: '
		let out=substitute(a:out, '\n$', '', '')
		echom out
	else
		let parts = split(a:out, ':')
		" parts[0] contains filename
		let fileName = parts[0]

		" put the error format into location list so we can jump automatically to
		" it
		lgetexpr a:out

		" needed for restoring back user setting this is because there are two
		" modes of switchbuf which we need based on the split mode
		let old_switchbuf = &switchbuf

		if a:mode == "tab"
			let &switchbuf = "usetab"

			if bufloaded(fileName) == 0
				tab split
			endif
		else
			if a:mode  == "split"
				split
			elseif a:mode == "vsplit"
				vsplit
			endif
		endif

		" jump to file now
		ll 1
		normal zz

		let &switchbuf = old_switchbuf
	end
	let &errorformat = old_errorformat
endfunction

<commit_msg>GoDef: open definition window silently<commit_after>if !exists("g:go_godef_bin")
	let g:go_godef_bin = "godef"
endif


" modified and improved version of vim-godef
function! go#def#Jump(...)
	if !len(a:000)
		" gives us the offset of the word, basicall the position of the word under
		" he cursor
		let arg = s:getOffset()
	else
		let arg = a:1
	endif

	let bin_path = go#tool#BinPath(g:go_godef_bin)
	if empty(bin_path)
		return
	endif

	let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)

	" get output of godef
	let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))

	" jump to it
	call s:godefJump(out, "")
endfunction


function! go#def#JumpMode(mode)
	let arg = s:getOffset()

	let bin_path = go#tool#BinPath(g:go_godef_bin)
	if empty(bin_path)
		return
	endif

	let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)

	" get output of godef
	let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))

	call s:godefJump(out, a:mode)
endfunction


function! s:getOffset()
	let pos = getpos(".")[1:2]
	if &encoding == 'utf-8'
		let offs = line2byte(pos[0]) + pos[1] - 2
	else
		let c = pos[1]
		let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), "\n") . "\n")
		let buf .= c == 1 ? "" : getline(pos[0])[:c-2]
		let offs = len(iconv(buf, &encoding, "utf-8"))
	endif

	let argOff = "-o=" . offs
	return argOff
endfunction


function! s:godefJump(out, mode)
	let old_errorformat = &errorformat
	let &errorformat = "%f:%l:%c"

	if a:out =~ 'godef: '
		let out=substitute(a:out, '\n$', '', '')
		echom out
	else
		let parts = split(a:out, ':')
		" parts[0] contains filename
		let fileName = parts[0]

		" put the error format into location list so we can jump automatically to
		" it
		lgetexpr a:out

		" needed for restoring back user setting this is because there are two
		" modes of switchbuf which we need based on the split mode
		let old_switchbuf = &switchbuf

		if a:mode == "tab"
			let &switchbuf = "usetab"

			if bufloaded(fileName) == 0
				tab split
			endif
		else
			if a:mode  == "split"
				split
			elseif a:mode == "vsplit"
				vsplit
			endif
		endif

		" jump to file now
		sil ll 1
		normal zz

		let &switchbuf = old_switchbuf
	end
	let &errorformat = old_errorformat
endfunction


{'fraction_non_alphanumeric': 0.14926357441195867, 'fraction_numerical': 0.011431083754671357, 'mean_word_length': 3.4695481335952847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1504586', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1748, 'n_words': 511}