mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
add automatically an opening bracket to a function and a dot to a module. also added settings to turn off this behaviour
This commit is contained in:
26
functions.py
26
functions.py
@@ -20,16 +20,26 @@ class NotFoundError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class Completion(object):
|
class Completion(object):
|
||||||
def __init__(self, name, needs_dot, like_name_length):
|
def __init__(self, name, needs_dot, like_name_length, base):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.needs_dot = needs_dot
|
self.needs_dot = needs_dot
|
||||||
self.like_name_length = like_name_length
|
self.like_name_length = like_name_length
|
||||||
self._completion_parent = name.parent() # limit gc
|
self._completion_parent = name.parent() # limit gc
|
||||||
|
self.base = base
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def complete(self):
|
def complete(self):
|
||||||
dot = '.' if self.needs_dot else ''
|
dot = '.' if self.needs_dot else ''
|
||||||
return dot + self.name.names[-1][self.like_name_length:]
|
append = ''
|
||||||
|
funcs = (parsing.Function, evaluate.Function)
|
||||||
|
if settings.add_bracket_after_function \
|
||||||
|
and isinstance( self._completion_parent, funcs):
|
||||||
|
append = '('
|
||||||
|
|
||||||
|
if settings.add_dot_after_module:
|
||||||
|
if isinstance(self.base, parsing.Module):
|
||||||
|
append += '.'
|
||||||
|
return dot + self.name.names[-1][self.like_name_length:] + append
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def word(self):
|
def word(self):
|
||||||
@@ -165,8 +175,9 @@ def complete(source, line, column, source_path):
|
|||||||
scope_generator = evaluate.get_names_for_scope(f.parser.user_scope,
|
scope_generator = evaluate.get_names_for_scope(f.parser.user_scope,
|
||||||
pos)
|
pos)
|
||||||
completions = []
|
completions = []
|
||||||
for dummy, name_list in scope_generator:
|
for scope, name_list in scope_generator:
|
||||||
completions += name_list
|
for c in name_list:
|
||||||
|
completions.append((c, scope))
|
||||||
else:
|
else:
|
||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible scopes', scopes)
|
debug.dbg('possible scopes', scopes)
|
||||||
@@ -174,15 +185,16 @@ def complete(source, line, column, source_path):
|
|||||||
# TODO is this really the right way? just ignore the functions? \
|
# TODO is this really the right way? just ignore the functions? \
|
||||||
# do the magic functions first? and then recheck here?
|
# do the magic functions first? and then recheck here?
|
||||||
if not isinstance(s, evaluate.Function):
|
if not isinstance(s, evaluate.Function):
|
||||||
completions += s.get_defined_names()
|
for c in s.get_defined_names():
|
||||||
|
completions.append((c, s))
|
||||||
|
|
||||||
completions = [c for c in completions
|
completions = [(c, s) for c, s in completions
|
||||||
if settings.case_insensitive_completion
|
if settings.case_insensitive_completion
|
||||||
and c.names[-1].lower().startswith(like.lower())
|
and c.names[-1].lower().startswith(like.lower())
|
||||||
or c.names[-1].startswith(like)]
|
or c.names[-1].startswith(like)]
|
||||||
|
|
||||||
needs_dot = not dot and path
|
needs_dot = not dot and path
|
||||||
c = [Completion(c, needs_dot, len(like)) for c in set(completions)]
|
c = [Completion(c, needs_dot, len(like), s) for c, s in set(completions)]
|
||||||
|
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return c
|
return c
|
||||||
|
|||||||
@@ -2,8 +2,17 @@
|
|||||||
# completion output settings
|
# completion output settings
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|
||||||
|
# The completion is by default case insensitive.
|
||||||
case_insensitive_completion = True
|
case_insensitive_completion = True
|
||||||
|
|
||||||
|
# Adds a dot after a module, because a module that is not accessed this way is
|
||||||
|
# definitely not the normal case.
|
||||||
|
add_dot_after_module = True
|
||||||
|
|
||||||
|
# Adds an opening bracket after a function, because that's normal behaviour.
|
||||||
|
add_bracket_after_function = True
|
||||||
|
|
||||||
|
|
||||||
# ----------------
|
# ----------------
|
||||||
# dynamic stuff
|
# dynamic stuff
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user