def matches(cls, cursor_offset, current_line, **kwargs): return importcompletion.complete(cursor_offset, current_line)
def test_package_completion(self): self.assertSetEqual( importcompletion.complete(13, "import zzabc."), {"zzabc.e", "zzabc.f"}, )
def test_from_package(self): self.assertEqual(importcompletion.complete(17, 'from xml import d'), ['dom'])
def test_from_package(self): self.assertEqual( sorted(importcompletion.complete(17, 'from xml import d')), ['dom'])
def complete(self, tab=False): """Construct a full list of possible completions and construct and display them in a window. Also check if there's an available argspec. (via the inspect module) and bang that on top of the completions too. The return value is whether the list_win is visible or not. """ self.docstring = None if not self.get_args(): self.argspec = None elif self.current_func is not None: try: self.docstring = pydoc.getdoc(self.current_func) except IndexError: self.docstring = None else: # pydoc.getdoc() returns an empty string if no # docstring was found if not self.docstring: self.docstring = None cw = self.cw() cs = self.current_string() if not cw: self.matches = [] self.matches_iter.update() if not (cw or cs): return bool(self.argspec) if cs and tab: # Filename completion self.matches = list() username = cs.split(os.path.sep, 1)[0] user_dir = os.path.expanduser(username) for filename in glob(os.path.expanduser(cs + '*')): if os.path.isdir(filename): filename += os.path.sep if cs.startswith('~'): filename = username + filename[len(user_dir):] self.matches.append(filename) self.matches_iter.update(cs, self.matches) return bool(self.matches) elif cs: # Do not provide suggestions inside strings, as one cannot tab # them so they would be really confusing. self.matches_iter.update() return False # Check for import completion e = False matches = importcompletion.complete(self.current_line(), cw) if matches is not None and not matches: self.matches = [] self.matches_iter.update() return False if matches is None: # Nope, no import, continue with normal completion try: self.completer.complete(cw, 0) except Exception: # This sucks, but it's either that or list all the exceptions that could # possibly be raised here, so if anyone wants to do that, feel free to send me # a patch. XXX: Make sure you raise here if you're debugging the completion # stuff ! e = True else: matches = self.completer.matches if (self.config.complete_magic_methods and self.buffer and self.buffer[0].startswith('class ') and self.current_line().lstrip().startswith('def ')): matches.extend(name for name in self.config.magic_methods if name.startswith(cw)) if not e and self.argspec: matches.extend(name + '=' for name in self.argspec[1][0] if isinstance(name, basestring) and name.startswith(cw)) if py3: matches.extend(name + '=' for name in self.argspec[1][4] if name.startswith(cw)) # unless the first character is a _ filter out all attributes starting # with a _ if not e and not cw.split('.')[-1].startswith('_'): matches = [match for match in matches if not match.split('.')[-1].startswith('_')] if e or not matches: self.matches = [] self.matches_iter.update() if not self.argspec: return False else: # remove duplicates self.matches = sorted(set(matches)) if len(self.matches) == 1 and not self.config.auto_display_list: self.list_win_visible = True self.tab() return False self.matches_iter.update(cw, self.matches) return True
def test_simple_completion(self): self.assertEqual(sorted(importcompletion.complete(10, 'import zza')), ['zzabc', 'zzabd'])
def test_from_attribute(self): self.assertEqual( sorted(importcompletion.complete(19, 'from sys import arg')), ['argv'])
def test_from_attribute(self): self.assertSetEqual( importcompletion.complete(19, 'from sys import arg'), set(['argv']))
def test_from_attr_module(self): self.assertSetEqual(importcompletion.complete(9, 'from os.p'), set(['os.path']))
def test_simple_completion(self): self.assertSetEqual(importcompletion.complete(10, 'import zza'), set(['zzabc', 'zzabd']))
def test_package_completion(self): self.assertSetEqual(importcompletion.complete(13, 'import zzabc.'), set(['zzabc.e', 'zzabc.f']))
def test_from_package(self): self.assertSetEqual( importcompletion.complete(17, "from xml import d"), {"dom"} )
def test_from_attr_module(self): self.assertSetEqual( importcompletion.complete(9, "from os.p"), {"os.path"} )
def test_from_attribute(self): self.assertSetEqual( importcompletion.complete(19, "from sys import arg"), {"argv"} )
def test_from_package(self): self.assertSetEqual(importcompletion.complete(17, 'from xml import d'), set(['dom']))
def matches(self, cursor_offset, line, **kwargs): return importcompletion.complete(cursor_offset, line)
def test_simple_completion(self): self.assertEqual(importcompletion.complete(10, 'import zza'), ['zzabc', 'zzabd'])
def test_package_completion(self): self.assertEqual( sorted(importcompletion.complete(13, 'import zzabc.')), [ 'zzabc.e', 'zzabc.f', ])
def test_package_completion(self): self.assertEqual(importcompletion.complete(13, 'import zzabc.'), ['zzabc.e', 'zzabc.f', ])
def test_from_attr_module(self): self.assertEqual(sorted(importcompletion.complete(9, 'from os.p')), ['os.path'])
def test_from_attribute(self): self.assertEqual(importcompletion.complete(19, 'from sys import arg'), ['argv'])
def test_from_attr_module(self): self.assertEqual(importcompletion.complete(9, 'from os.p'), ['os.path'])
def complete(self, tab=False): """Construct a full list of possible completions and construct and display them in a window. Also check if there's an available argspec (via the inspect module) and bang that on top of the completions too. The return value is whether the list_win is visible or not.""" self.docstring = None if not self.get_args(): self.argspec = None elif self.current_func is not None: try: self.docstring = pydoc.getdoc(self.current_func) except IndexError: self.docstring = None else: # pydoc.getdoc() returns an empty string if no # docstring was found if not self.docstring: self.docstring = None cw = self.cw() cs = self.current_string() if not cw: self.matches = [] self.matches_iter.update() if not (cw or cs): return bool(self.argspec) if cs and tab: # Filename completion self.matches = list() username = cs.split(os.path.sep, 1)[0] user_dir = os.path.expanduser(username) for filename in glob(os.path.expanduser(cs + '*')): if os.path.isdir(filename): filename += os.path.sep if cs.startswith('~'): filename = username + filename[len(user_dir):] self.matches.append(filename) self.matches_iter.update(cs, self.matches) return bool(self.matches) elif cs: # Do not provide suggestions inside strings, as one cannot tab # them so they would be really confusing. self.matches_iter.update() return False # Check for import completion e = False matches = importcompletion.complete(self.current_line(), cw) if matches is not None and not matches: self.matches = [] self.matches_iter.update() return False if matches is None: # Nope, no import, continue with normal completion try: self.completer.complete(cw, 0) except Exception: # This sucks, but it's either that or list all the exceptions that could # possibly be raised here, so if anyone wants to do that, feel free to send me # a patch. XXX: Make sure you raise here if you're debugging the completion # stuff ! e = True else: matches = self.completer.matches if (self.config.complete_magic_methods and self.buffer and self.buffer[0].startswith("class ") and self.current_line().lstrip().startswith("def ")): matches.extend(name for name in self.config.magic_methods if name.startswith(cw)) if not e and self.argspec: matches.extend(name + '=' for name in self.argspec[1][0] if isinstance(name, str) and name.startswith(cw)) if py3: matches.extend(name + '=' for name in self.argspec[1][4] if name.startswith(cw)) # unless the first character is a _ filter out all attributes starting with a _ if not e and not cw.split('.')[-1].startswith('_'): matches = [ match for match in matches if not match.split('.')[-1].startswith('_') ] if e or not matches: self.matches = [] self.matches_iter.update() if not self.argspec: return False else: # remove duplicates self.matches = sorted(set(matches)) if len(self.matches) == 1 and not self.config.auto_display_list: self.list_win_visible = True self.tab() return False self.matches_iter.update(cw, self.matches) return True
def test_simple_completion(self): self.assertSetEqual( importcompletion.complete(10, "import zza"), {"zzabc", "zzabd"} )