From 8996bd6ad1c40d1c7f40aa5a043a3d1d4cbe98c7 Mon Sep 17 00:00:00 2001 From: David Halter Date: Fri, 16 Aug 2013 13:38:50 +0430 Subject: [PATCH] modifications to use a differnt kind of completion for the interpreter --- jedi/api.py | 70 +++++++++++++++++++++++++++---------------------- jedi/modules.py | 3 +++ 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 3417c8d9..1c76408b 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -105,39 +105,8 @@ class Script(object): if re.search('^\.|\.\.$', path): return [] path, dot, like = self._get_completion_parts() - completion_line = self._module.get_line(self.pos[0])[:self.pos[1]] - try: - scopes = list(self._prepare_goto(path, True)) - except NotFoundError: - scopes = [] - scope_generator = evaluate.get_names_of_scope( - self._parser.user_scope, self.pos) - completions = [] - for scope, name_list in scope_generator: - for c in name_list: - completions.append((c, scope)) - else: - completions = [] - debug.dbg('possible scopes', scopes) - for s in scopes: - if s.isinstance(er.Function): - names = s.get_magic_method_names() - else: - if isinstance(s, imports.ImportPath): - under = like + self._module.get_path_after_cursor() - if under == 'import': - if not completion_line.endswith('import import'): - continue - a = s.import_stmt.alias - if a and a.start_pos <= self.pos <= a.end_pos: - continue - names = s.get_defined_names(on_import_stmt=True) - else: - names = s.get_defined_names() - - for c in names: - completions.append((c, s)) + completions = self._simple_complete(path, like) if not dot: # named params have no dots for call_def in self.call_signatures(): @@ -149,6 +118,7 @@ class Script(object): u = self._parser.user_stmt bs = builtin.Builtin.scope if isinstance(u, pr.Import): + completion_line = self._module.get_position_line() if (u.relative_count > 0 or u.from_ns) and not re.search( r'(,|from)\s*$|import\s+$', completion_line): completions += ((k, bs) for k @@ -184,6 +154,42 @@ class Script(object): x.name.startswith('_'), x.name.lower())) + def _simple_complete(self, path, like): + try: + scopes = list(self._prepare_goto(path, True)) + except NotFoundError: + scopes = [] + scope_generator = evaluate.get_names_of_scope( + self._parser.user_scope, self.pos) + completions = [] + for scope, name_list in scope_generator: + for c in name_list: + completions.append((c, scope)) + else: + completions = [] + debug.dbg('possible scopes', scopes) + for s in scopes: + if s.isinstance(er.Function): + names = s.get_magic_method_names() + else: + if isinstance(s, imports.ImportPath): + under = like + self._module.get_path_after_cursor() + if under == 'import': + current_line = self._module.get_position_line() + if not current_line.endswith('import import'): + continue + a = s.import_stmt.alias + if a and a.start_pos <= self.pos <= a.end_pos: + continue + names = s.get_defined_names(on_import_stmt=True) + else: + names = s.get_defined_names() + + for c in names: + completions.append((c, s)) + return completions + + def _prepare_goto(self, goto_path, is_like_search=False): """ Base for completions/goto. Basically it returns the resolved scopes diff --git a/jedi/modules.py b/jedi/modules.py index b26c18ad..657650fb 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -256,6 +256,9 @@ class ModuleWithCursor(Module): except IndexError: raise StopIteration() + def get_position_line(self): + return self.get_line(self.position[0])[:self.position[1]] + def get_sys_path(): def check_virtual_env(sys_path):