forked from VimPlug/jedi
A first iteration of adding signatures to the API, fixes #1139
This commit is contained in:
@@ -330,6 +330,8 @@ class BaseDefinition(object):
|
|||||||
@memoize_method
|
@memoize_method
|
||||||
def params(self):
|
def params(self):
|
||||||
"""
|
"""
|
||||||
|
Deprecated! Will raise a warning soon. Use get_signatures()[...].params.
|
||||||
|
|
||||||
Raises an ``AttributeError`` if the definition is not callable.
|
Raises an ``AttributeError`` if the definition is not callable.
|
||||||
Otherwise returns a list of `Definition` that represents the params.
|
Otherwise returns a list of `Definition` that represents the params.
|
||||||
"""
|
"""
|
||||||
@@ -387,6 +389,9 @@ class BaseDefinition(object):
|
|||||||
start_index = max(index - before, 0)
|
start_index = max(index - before, 0)
|
||||||
return ''.join(lines[start_index:index + after + 1])
|
return ''.join(lines[start_index:index + after + 1])
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
return [Signature(self._evaluator, s) for s in self._name.infer().get_signatures()]
|
||||||
|
|
||||||
|
|
||||||
class Completion(BaseDefinition):
|
class Completion(BaseDefinition):
|
||||||
"""
|
"""
|
||||||
@@ -601,14 +606,31 @@ class Definition(BaseDefinition):
|
|||||||
return hash((self._name.start_pos, self.module_path, self.name, self._evaluator))
|
return hash((self._name.start_pos, self.module_path, self.name, self._evaluator))
|
||||||
|
|
||||||
|
|
||||||
class CallSignature(Definition):
|
class Signature(Definition):
|
||||||
"""
|
"""
|
||||||
`CallSignature` objects is the return value of `Script.function_definition`.
|
`Signature` objects is the return value of `Script.function_definition`.
|
||||||
It knows what functions you are currently in. e.g. `isinstance(` would
|
It knows what functions you are currently in. e.g. `isinstance(` would
|
||||||
return the `isinstance` function. without `(` it would return nothing.
|
return the `isinstance` function. without `(` it would return nothing.
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, signature, call_details):
|
def __init__(self, evaluator, signature):
|
||||||
super(CallSignature, self).__init__(evaluator, signature.name)
|
super(CallSignature, self).__init__(evaluator, signature.name)
|
||||||
|
self._signature = signature
|
||||||
|
|
||||||
|
@property
|
||||||
|
def params(self):
|
||||||
|
return [Definition(self._evaluator, n)
|
||||||
|
for n in self._signature.get_param_names(resolve_stars=True)]
|
||||||
|
|
||||||
|
|
||||||
|
class CallSignature(Signature):
|
||||||
|
"""
|
||||||
|
`CallSignature` objects is the return value of `Script.call_signatures`.
|
||||||
|
It knows what functions you are currently in. e.g. `isinstance(` would
|
||||||
|
return the `isinstance` function with its params. Without `(` it would
|
||||||
|
return nothing.
|
||||||
|
"""
|
||||||
|
def __init__(self, evaluator, signature, call_details):
|
||||||
|
super(CallSignature, self).__init__(evaluator, signature)
|
||||||
self._call_details = call_details
|
self._call_details = call_details
|
||||||
self._signature = signature
|
self._signature = signature
|
||||||
|
|
||||||
@@ -622,16 +644,11 @@ class CallSignature(Definition):
|
|||||||
self._signature.get_param_names(resolve_stars=True)
|
self._signature.get_param_names(resolve_stars=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def params(self):
|
|
||||||
return [Definition(self._evaluator, n)
|
|
||||||
for n in self._signature.get_param_names(resolve_stars=True)]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bracket_start(self):
|
def bracket_start(self):
|
||||||
"""
|
"""
|
||||||
The indent of the bracket that is responsible for the last function
|
The line/column of the bracket that is responsible for the last
|
||||||
call.
|
function call.
|
||||||
"""
|
"""
|
||||||
return self._call_details.bracket_leaf.start_pos
|
return self._call_details.bracket_leaf.start_pos
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user