mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
update completion logic in jupyter kernel
This commit is contained in:
parent
50e0b3df8b
commit
2ab99759fd
1 changed files with 12 additions and 2 deletions
|
@ -9,6 +9,7 @@ from ipykernel.kernelbase import Kernel
|
|||
from xonsh import __version__ as version
|
||||
from xonsh.main import main_context
|
||||
from xonsh.tools import redirect_stdout, redirect_stderr, swap
|
||||
from xonsh.completer import Completer
|
||||
|
||||
|
||||
MAX_SIZE = 8388608 # 8 Mb
|
||||
|
@ -28,6 +29,10 @@ class XonshKernel(Kernel):
|
|||
'file_extension': '.xsh',
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.completer = Completer()
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def do_execute(self, code, silent, store_history=True, user_expressions=None,
|
||||
allow_stdin=False):
|
||||
"""Execute user code."""
|
||||
|
@ -96,8 +101,13 @@ class XonshKernel(Kernel):
|
|||
def do_complete(self, code, pos):
|
||||
"""Get completions."""
|
||||
shell = builtins.__xonsh_shell__
|
||||
comps, beg, end = shell.completer.find_and_complete(code, pos, shell.ctx)
|
||||
message = {'matches': comps, 'cursor_start': beg, 'cursor_end': end+1,
|
||||
line = code.split('\n')[-1]
|
||||
prefix = line.split(' ')[-1]
|
||||
endidx = pos
|
||||
begidx = pos - len(prefix)
|
||||
rtn, _ = self.completer.complete(prefix, line, begidx,
|
||||
endidx, shell.ctx)
|
||||
message = {'matches': rtn, 'cursor_start': begidx, 'cursor_end': endidx,
|
||||
'metadata': {}, 'status': 'ok'}
|
||||
return message
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue