2017-11-03 10:34:41 +03:00
|
|
|
declare-option -hidden str jedi_tmp_dir
|
|
|
|
declare-option -hidden completions jedi_completions
|
|
|
|
declare-option -docstring "colon separated list of path added to `python`'s $PYTHONPATH environment variable" \
|
2018-05-30 16:28:50 +03:00
|
|
|
str jedi_python_path
|
2014-11-06 00:02:34 +03:00
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command jedi-complete -docstring "Complete the current selection" %{
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2017-06-09 14:05:31 +03:00
|
|
|
dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-jedi.XXXXXXXX)
|
2014-11-06 00:02:34 +03:00
|
|
|
mkfifo ${dir}/fifo
|
2017-11-03 10:34:41 +03:00
|
|
|
printf %s\\n "set-option buffer jedi_tmp_dir ${dir}"
|
2018-07-04 09:55:05 +03:00
|
|
|
printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf"
|
2014-11-06 00:02:34 +03:00
|
|
|
}
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2014-11-06 00:02:34 +03:00
|
|
|
dir=${kak_opt_jedi_tmp_dir}
|
2017-11-03 11:09:45 +03:00
|
|
|
printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
|
2014-11-06 00:02:34 +03:00
|
|
|
(
|
|
|
|
cd $(dirname ${kak_buffile})
|
|
|
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
|
|
|
|
2016-02-28 21:48:59 +03:00
|
|
|
export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH"
|
2014-11-06 22:17:13 +03:00
|
|
|
compl=$(python 2> "${dir}/fifo" <<-END
|
2014-11-06 00:02:34 +03:00
|
|
|
import jedi
|
|
|
|
script=jedi.Script(open('$dir/buf', 'r').read(), $kak_cursor_line, $kak_cursor_column - 1, '$kak_buffile')
|
2017-02-20 23:13:48 +03:00
|
|
|
print(':'.join([(str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|")).replace(":", "\\:") + "|" + str(c.name).replace("|", "\\|") for c in script.completions()]).replace("'", r"\\\\'"))
|
2014-11-06 00:02:34 +03:00
|
|
|
END
|
|
|
|
)
|
2017-11-03 11:09:45 +03:00
|
|
|
printf %s\\n "evaluate-commands -client ${kak_client} 'echo completed; set-option %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session}
|
2014-11-19 16:54:36 +03:00
|
|
|
rm -r ${dir}
|
2014-11-06 00:02:34 +03:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command jedi-enable-autocomplete -docstring "Add jedi completion candidates to the completer" %{
|
|
|
|
set-option window completers "option=jedi_completions:%opt{completers}"
|
2014-11-06 00:02:34 +03:00
|
|
|
hook window -group jedi-autocomplete InsertIdle .* %{ try %{
|
2017-11-03 11:09:45 +03:00
|
|
|
execute-keys -draft <a-h><a-k>\..\z<ret>
|
2014-11-06 00:02:34 +03:00
|
|
|
echo 'completing...'
|
|
|
|
jedi-complete
|
|
|
|
} }
|
2014-11-18 16:55:52 +03:00
|
|
|
alias window complete jedi-complete
|
2014-11-06 00:02:34 +03:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command jedi-disable-autocomplete -docstring "Disable jedi completion" %{
|
|
|
|
set-option window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' }
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window jedi-autocomplete
|
2014-11-18 16:55:52 +03:00
|
|
|
unalias window complete jedi-complete
|
2014-11-06 00:02:34 +03:00
|
|
|
}
|