rope.contrib.codeassist ======================= .. py:module:: rope.contrib.codeassist Attributes ---------- .. autoapisummary:: rope.contrib.codeassist.CodeAssistProposal Classes ------- .. autoapisummary:: rope.contrib.codeassist.CompletionProposal rope.contrib.codeassist.NamedParamProposal rope.contrib.codeassist.PyDocExtractor rope.contrib.codeassist.TemplateProposal rope.contrib.codeassist.Template Functions --------- .. autoapisummary:: rope.contrib.codeassist.code_assist rope.contrib.codeassist.starting_offset rope.contrib.codeassist.get_doc rope.contrib.codeassist.get_calltip rope.contrib.codeassist.get_definition_location rope.contrib.codeassist.find_occurrences rope.contrib.codeassist.get_canonical_path rope.contrib.codeassist.sorted_proposals rope.contrib.codeassist.starting_expression rope.contrib.codeassist.default_templates Module Contents --------------- .. py:function:: 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. .. py:function:: 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. .. py:function:: get_doc(project, source_code, offset, resource=None, maxfixes=1) Get the pydoc .. py:function:: 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. .. py:function:: 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. .. py:function:: find_occurrences(*args, **kwds) .. py:function:: 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. .. py:class:: 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 | | | | | + .. py:attribute:: name .. py:attribute:: pyname :value: None .. py:attribute:: scope :value: 'builtin' .. py:property:: parameters The names of the parameters the function takes. Returns None if this completion is not a function. .. py:property:: type .. py:method:: get_doc() Get the proposed object's docstring. Returns None if it can not be get. .. py:property:: kind .. py:data:: CodeAssistProposal .. py:class:: NamedParamProposal(name, function) Bases: :py:obj:`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. .. py:attribute:: argname .. py:method:: get_default() Get a string representation of a param's default value. Returns None if there is no default value for this param. .. py:attribute:: name .. py:attribute:: pyname :value: None .. py:attribute:: scope :value: 'builtin' .. py:property:: parameters The names of the parameters the function takes. Returns None if this completion is not a function. .. py:property:: type .. py:method:: get_doc() Get the proposed object's docstring. Returns None if it can not be get. .. py:property:: kind .. py:function:: 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.) .. py:function:: starting_expression(source_code, offset) Return the expression to complete .. py:function:: default_templates() .. py:class:: PyDocExtractor .. py:method:: get_doc(pyobject) .. py:method:: get_calltip(pyobject, ignore_unknown=False, remove_self=False) .. py:class:: TemplateProposal(name, template) Bases: :py:obj:`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 | | | | | + .. py:attribute:: template .. py:attribute:: name .. py:attribute:: pyname :value: None .. py:attribute:: scope :value: 'builtin' .. py:property:: parameters The names of the parameters the function takes. Returns None if this completion is not a function. .. py:property:: type .. py:method:: get_doc() Get the proposed object's docstring. Returns None if it can not be get. .. py:property:: kind .. py:class:: Template(template) .. py:attribute:: template .. py:method:: variables() .. py:method:: substitute(mapping) .. py:method:: get_cursor_location(mapping)