<commit_before>function! phpcd#CompletePHP(findstart, base) " {{{
	" we need to wait phpcd {{{
	if !exists('g:phpcd_channel_id')
		return
	endif " }}}

	if a:findstart " {{{
		unlet! b:php_menu
		" locate the start of the word
		let line = getline('.')
		let start = col('.') - 1
		let compl_begin = col('.') - 2
		while start >= 0 && line[start - 1] =~ '[\\a-zA-Z_0-9\x7f-\xff$]'
			let start -= 1
		endwhile

		" TODO 清理 phpbegin
		let phpbegin = searchpairpos('<?', '', '?>', 'bWn',
				\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
		let b:phpbegin = phpbegin
		let b:compl_context = phpcd#GetCurrentInstruction(line('.'), max([0, col('.') - 2]), phpbegin)

		return start
	endif " }}}

	" If exists b:php_menu it means completion was already constructed {{{
	" we don't need to do anything more
	if exists('b:php_menu')
		return b:php_menu
	endif " }}}

	" a:base is very short - we need context {{{
	if exists('b:compl_context')
		let context = b:compl_context
		unlet! b:compl_context
		" chop of the "base" from the end of the current instruction
		if a:base != ""
			let context = substitute(context, '\s*[$a-zA-Z_0-9\x7f-\xff]*$', '', '')
		end
	else
		let context = ''
	end " }}}

	try " {{{
		let winheight = winheight(0)
		let winnr = winnr()
		if context =~? '^namespace'
			return phpcd#GetPsrNamespace()
		endif

		if context =~? '\v^(abstract\s+)?(class|interface|trait)'
			return [expand('%:t:r')]
		end

		let [current_namespace, imports] = phpcd#GetCurrentNameSpace()

		if context =~? '^use\s' || context ==? 'use' " {{{
			" TODO complete use
		endif " }}}

		if context =~ '\(->\|::\)$' " {{{
			let classname = phpcd#GetClassName(line('.'), context, current_namespace, imports)

			" TODO Fix it for variables with reference to $this etc.
			let public_only = (context !~# '^\(\$this\|self\|static\|parent\)' )

			let is_static = 'only_nonstatic'

			if strridx(context, '::') == strlen(context) - 2 " context =~ '::$'
				if stridx(context, 'parent') != 0
					let is_static = 'only_static'
				else
					let is_static = 'both'
				endif
			endif

			return rpc#request(g:phpcd_channel_id, 'info', classname, a:base, is_static, public_only)
		elseif context =~? 'implements'
			" TODO complete class Foo implements
		elseif context =~? 'extends\s\+.\+$' && a:base == ''
			" TODO complete class Foo extends
		elseif context =~? 'extends'
			" TODO complete class Foo extends Prefix..
		elseif context =~? 'class [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*'
			" special case when you've typed the class keyword and the name too,
			" only extends and implements allowed there
			return filter(['extends', 'implements'], 'stridx(v:val, a:base) == 0')
		elseif context =~? 'new'
			" TODO complete $foo = new
		endif " }}}

		if a:base =~ '^[^$]' " {{{
			return phpcd#CompleteGeneral(a:base, current_namespace, imports)
		endif " }}}
	finally
		silent! exec winnr.'resize '.winheight
	endtry " }}}
endfunction " }}}

function! phpcd#GetPsrNamespace() " {{{
	let path = expand('%:p')
	if !filereadable(path)
		return []
	endif

	return rpc#request(g:phpcd_channel_id, 'psr4ns', path)
endfunction " }}}

function! phpcd#CompleteGeneral(base, current_namespace, imports) " {{{
	let base = substitute(a:base, '^\\', '', '')
	let [pattern, namespace] = phpcd#ExpandClassName(a:base, a:current_namespace, a:imports)
	return rpc#request(g:phpcd_channel_id, 'info', '', pattern)
endfunction " }}}

function! phpcd#JumpToDefinition(mode) " {{{
	if !exists('g:phpcd_channel_id')
		return
	endif

	let [symbol, symbol_context, symbol_namespace, current_imports] = phpcd#GetCurrentSymbolWithContext()
	if symbol == ''
		return
	endif

	let [symbol_file, symbol_line, symbol_col] = phpcd#LocateSymbol(symbol, symbol_context, symbol_namespace, current_imports)
	if symbol_file == '' || symbol_file == v:false
		return
	endif

	if a:mode == 'normal'
		let edit_cmd = "e +"
	elseif a:mode == 'preview'
		let edit_cmd = "pedit +"
	else
		let edit_cmd = a:mode . " +"
	endif

	let cur_pos = getcurpos()
	let cur_pos[0] = bufnr('%')
	if !exists('s:phpcd_jump_stack')
		let s:phpcd_jump_stack = []
	endif
	call add(s:phpcd_jump_stack, cur_pos)

	if str2nr(symbol_line) > 0
		silent! execute edit_cmd . symbol_line . ' ' . symbol_file
	else
		silent! execute edit_cmd . '1 ' . symbol_file
		silent! call search(symbol_line)
	endif

	silent! execute "normal! zt"
	normal! zv
	normal! zz
endfunction " }}}

function! phpcd#JumpBack() "{{{"
	if !exists('s:phpcd_jump_stack') || len(s:phpcd_jump_stack) == 0
		return
	endif

	let prev_pos = s:phpcd_jump_stack[-1]
	let prev_buf = prev_pos[0]
	let prev_pos[0] = 0
	unlet s:phpcd_jump_stack[-1]
	exec 'buffer '.prev_buf
	call setpos('.', prev_pos)
endfunction "}}}"<commit_msg>do not reopen current file<commit_after>function! phpcd#CompletePHP(findstart, base) " {{{
	" we need to wait phpcd {{{
	if !exists('g:phpcd_channel_id')
		return
	endif " }}}

	if a:findstart " {{{
		unlet! b:php_menu
		" locate the start of the word
		let line = getline('.')
		let start = col('.') - 1
		let compl_begin = col('.') - 2
		while start >= 0 && line[start - 1] =~ '[\\a-zA-Z_0-9\x7f-\xff$]'
			let start -= 1
		endwhile

		" TODO 清理 phpbegin
		let phpbegin = searchpairpos('<?', '', '?>', 'bWn',
				\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')
		let b:phpbegin = phpbegin
		let b:compl_context = phpcd#GetCurrentInstruction(line('.'), max([0, col('.') - 2]), phpbegin)

		return start
	endif " }}}

	" If exists b:php_menu it means completion was already constructed {{{
	" we don't need to do anything more
	if exists('b:php_menu')
		return b:php_menu
	endif " }}}

	" a:base is very short - we need context {{{
	if exists('b:compl_context')
		let context = b:compl_context
		unlet! b:compl_context
		" chop of the "base" from the end of the current instruction
		if a:base != ""
			let context = substitute(context, '\s*[$a-zA-Z_0-9\x7f-\xff]*$', '', '')
		end
	else
		let context = ''
	end " }}}

	try " {{{
		let winheight = winheight(0)
		let winnr = winnr()
		if context =~? '^namespace'
			return phpcd#GetPsrNamespace()
		endif

		if context =~? '\v^(abstract\s+)?(class|interface|trait)'
			return [expand('%:t:r')]
		end

		let [current_namespace, imports] = phpcd#GetCurrentNameSpace()

		if context =~? '^use\s' || context ==? 'use' " {{{
			" TODO complete use
		endif " }}}

		if context =~ '\(->\|::\)$' " {{{
			let classname = phpcd#GetClassName(line('.'), context, current_namespace, imports)

			" TODO Fix it for variables with reference to $this etc.
			let public_only = (context !~# '^\(\$this\|self\|static\|parent\)' )

			let is_static = 'only_nonstatic'

			if strridx(context, '::') == strlen(context) - 2 " context =~ '::$'
				if stridx(context, 'parent') != 0
					let is_static = 'only_static'
				else
					let is_static = 'both'
				endif
			endif

			return rpc#request(g:phpcd_channel_id, 'info', classname, a:base, is_static, public_only)
		elseif context =~? 'implements'
			" TODO complete class Foo implements
		elseif context =~? 'extends\s\+.\+$' && a:base == ''
			" TODO complete class Foo extends
		elseif context =~? 'extends'
			" TODO complete class Foo extends Prefix..
		elseif context =~? 'class [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*'
			" special case when you've typed the class keyword and the name too,
			" only extends and implements allowed there
			return filter(['extends', 'implements'], 'stridx(v:val, a:base) == 0')
		elseif context =~? 'new'
			" TODO complete $foo = new
		endif " }}}

		if a:base =~ '^[^$]' " {{{
			return phpcd#CompleteGeneral(a:base, current_namespace, imports)
		endif " }}}
	finally
		silent! exec winnr.'resize '.winheight
	endtry " }}}
endfunction " }}}

function! phpcd#GetPsrNamespace() " {{{
	let path = expand('%:p')
	if !filereadable(path)
		return []
	endif

	return rpc#request(g:phpcd_channel_id, 'psr4ns', path)
endfunction " }}}

function! phpcd#CompleteGeneral(base, current_namespace, imports) " {{{
	let base = substitute(a:base, '^\\', '', '')
	let [pattern, namespace] = phpcd#ExpandClassName(a:base, a:current_namespace, a:imports)
	return rpc#request(g:phpcd_channel_id, 'info', '', pattern)
endfunction " }}}

function! phpcd#JumpToDefinition(mode) " {{{
	if !exists('g:phpcd_channel_id')
		return
	endif

	let [symbol, symbol_context, symbol_namespace, current_imports] = phpcd#GetCurrentSymbolWithContext()
	if symbol == ''
		return
	endif

	let [symbol_file, symbol_line, symbol_col] = phpcd#LocateSymbol(symbol, symbol_context, symbol_namespace, current_imports)
	if symbol_file == '' || symbol_file == v:false
		return
	endif

	if a:mode == 'normal'
		let edit_cmd = "e +"
	elseif a:mode == 'preview'
		let edit_cmd = "pedit +"
	else
		let edit_cmd = a:mode . " +"
	endif

	let cur_pos = getcurpos()
	let cur_pos[0] = bufnr('%')
	if !exists('s:phpcd_jump_stack')
		let s:phpcd_jump_stack = []
	endif
	call add(s:phpcd_jump_stack, cur_pos)

	if str2nr(symbol_line) > 0
		if expand('%:p') == symbol_file
			silent! execute symbol_line
		else
			silent! execute edit_cmd . symbol_line . ' ' . symbol_file
		endif
	else
		silent! execute edit_cmd . '1 ' . symbol_file
		silent! call search(symbol_line)
	endif

	silent! execute "normal! zt"
	normal! zv
	normal! zz
endfunction " }}}

function! phpcd#JumpBack() "{{{"
	if !exists('s:phpcd_jump_stack') || len(s:phpcd_jump_stack) == 0
		return
	endif

	let prev_pos = s:phpcd_jump_stack[-1]
	let prev_buf = prev_pos[0]
	let prev_pos[0] = 0
	unlet s:phpcd_jump_stack[-1]
	exec 'buffer '.prev_buf
	call setpos('.', prev_pos)
endfunction "}}}"
{'fraction_non_alphanumeric': 0.16659729448491156, 'fraction_numerical': 0.006867845993756503, 'mean_word_length': 4.005729166666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6494137', 'n_tokens_mistral': 3908, 'n_tokens_neox': 3544, 'n_words': 870}