rope.contrib.codeassist

Attributes

CodeAssistProposal

Classes

CompletionProposal

A completion proposal

NamedParamProposal

A parameter keyword completion proposal

PyDocExtractor

TemplateProposal

A completion proposal

Template

Functions

code_assist(project, source_code, offset[, resource, ...])

Return python code completions as a list of CodeAssistProposal

starting_offset(source_code, offset)

Return the offset in which the completion should be inserted

get_doc(project, source_code, offset[, resource, maxfixes])

Get the pydoc

get_calltip(project, source_code, offset[, resource, ...])

Get the calltip of a function

get_definition_location(project, source_code, offset)

Return the definition location of the python name at offset

find_occurrences(*args, **kwds)

get_canonical_path(project, resource, offset)

Get the canonical path to an object.

sorted_proposals(proposals[, scopepref, typepref])

Sort a list of proposals

starting_expression(source_code, offset)

Return the expression to complete

default_templates()

Module Contents

rope.contrib.codeassist.code_assist(project, source_code, offset, resource=None, templates=None, maxfixes=1, later_locals=True)

Return python code completions as a list of CodeAssistProposal

resource is a rope.base.resources.Resource object. If provided, relative imports are handled.

maxfixes is the maximum number of errors to fix if the code has errors in it.

If later_locals is False names defined in this scope and after this line is ignored.

rope.contrib.codeassist.starting_offset(source_code, offset)

Return the offset in which the completion should be inserted

Usually code assist proposals should be inserted like:

completion = proposal.name
result = (source_code[:starting_offset] +
          completion + source_code[offset:])

Where starting_offset is the offset returned by this function.

rope.contrib.codeassist.get_doc(project, source_code, offset, resource=None, maxfixes=1)

Get the pydoc

rope.contrib.codeassist.get_calltip(project, source_code, offset, resource=None, maxfixes=1, ignore_unknown=False, remove_self=False)

Get the calltip of a function

The format of the returned string is module_name.holding_scope_names.function_name(arguments). For classes __init__() and for normal objects __call__() function is used.

Note that the offset is on the function itself not after the its open parenthesis. (Actually it used to be the other way but it was easily confused when string literals were involved. So I decided it is better for it not to try to be too clever when it cannot be clever enough). You can use a simple search like:

offset = source_code.rindex('(', 0, offset) - 1

to handle simple situations.

If ignore_unknown is True, None is returned for functions without source-code like builtins and extensions.

If remove_self is True, the first parameter whose name is self will be removed for methods.

rope.contrib.codeassist.get_definition_location(project, source_code, offset, resource=None, maxfixes=1)

Return the definition location of the python name at offset

Return a (rope.base.resources.Resource, lineno) tuple. If no resource is given and the definition is inside the same module, the first element of the returned tuple would be None. If the location cannot be determined (None, None) is returned.

rope.contrib.codeassist.find_occurrences(*args, **kwds)
rope.contrib.codeassist.get_canonical_path(project, resource, offset)

Get the canonical path to an object.

Given the offset of the object, this returns a list of (name, name_type) tuples representing the canonical path to the object. For example, the ‘x’ in the following code:

class Foo(object):
def bar(self):
class Qux(object):
def mux(self, x):

pass

we will return:

[(‘Foo’, ‘CLASS’), (‘bar’, ‘FUNCTION’), (‘Qux’, ‘CLASS’),

(‘mux’, ‘FUNCTION’), (‘x’, ‘PARAMETER’)]

resource is a rope.base.resources.Resource object.

offset is the offset of the pyname you want the path to.

class rope.contrib.codeassist.CompletionProposal(name, scope, pyname=None)

A completion proposal

The scope instance variable shows where proposed name came from and can be ‘global’, ‘local’, ‘builtin’, ‘attribute’, ‘keyword’, ‘imported’, ‘parameter_keyword’.

The type instance variable shows the approximate type of the proposed object and can be ‘instance’, ‘class’, ‘function’, ‘module’, and None.

All possible relations between proposal’s scope and type are shown in the table below (different scopes in rows and types in columns):

instance | class | function | module | None

local | + | + | + | + |

global | + | + | + | + |

builtin | + | + | + | |

attribute | + | + | + | + |
imported | + | + | + | + |

keyword | | | | | +

parameter_keyword | | | | | +

name
pyname = None
scope = 'builtin'
property parameters

The names of the parameters the function takes.

Returns None if this completion is not a function.

property type
get_doc()

Get the proposed object’s docstring.

Returns None if it can not be get.

property kind
rope.contrib.codeassist.CodeAssistProposal
class rope.contrib.codeassist.NamedParamProposal(name, function)

Bases: CompletionProposal

A parameter keyword completion proposal

Holds reference to _function – the function which parameter name belongs to. This allows to determine default value for this parameter.

argname
get_default()

Get a string representation of a param’s default value.

Returns None if there is no default value for this param.

name
pyname = None
scope = 'builtin'
property parameters

The names of the parameters the function takes.

Returns None if this completion is not a function.

property type
get_doc()

Get the proposed object’s docstring.

Returns None if it can not be get.

property kind
rope.contrib.codeassist.sorted_proposals(proposals, scopepref=None, typepref=None)

Sort a list of proposals

Return a sorted list of the given CodeAssistProposal.

scopepref can be a list of proposal scopes. Defaults to ['parameter_keyword', 'local', 'global', 'imported', 'attribute', 'builtin', 'keyword'].

typepref can be a list of proposal types. Defaults to ['class', 'function', 'instance', 'module', None]. (None stands for completions with no type like keywords.)

rope.contrib.codeassist.starting_expression(source_code, offset)

Return the expression to complete

rope.contrib.codeassist.default_templates()
class rope.contrib.codeassist.PyDocExtractor
get_doc(pyobject)
get_calltip(pyobject, ignore_unknown=False, remove_self=False)
class rope.contrib.codeassist.TemplateProposal(name, template)

Bases: CodeAssistProposal

A completion proposal

The scope instance variable shows where proposed name came from and can be ‘global’, ‘local’, ‘builtin’, ‘attribute’, ‘keyword’, ‘imported’, ‘parameter_keyword’.

The type instance variable shows the approximate type of the proposed object and can be ‘instance’, ‘class’, ‘function’, ‘module’, and None.

All possible relations between proposal’s scope and type are shown in the table below (different scopes in rows and types in columns):

instance | class | function | module | None

local | + | + | + | + |

global | + | + | + | + |

builtin | + | + | + | |

attribute | + | + | + | + |
imported | + | + | + | + |

keyword | | | | | +

parameter_keyword | | | | | +

template
name
pyname = None
scope = 'builtin'
property parameters

The names of the parameters the function takes.

Returns None if this completion is not a function.

property type
get_doc()

Get the proposed object’s docstring.

Returns None if it can not be get.

property kind
class rope.contrib.codeassist.Template(template)
template
variables()
substitute(mapping)
get_cursor_location(mapping)