Esempio n. 1
0
def complete(dot=False):
    """ Ctrl+Space completion.

    :return bool: success

    """
    row, col = env.cursor
    source, offset = env.get_offset_params()

    cline = env.current.line[:col]
    env.debug('dot completion', cline)
    if FROM_RE.match(cline) or cline.endswith('..') or cline.endswith('\.'):
        return env.stop("")

    proposals = get_proporsals(source, offset, dot=dot)
    if not proposals:
        return False

    prefix = proposals[0]['word']

    # Find common part
    for p in proposals:
        common = len([
            c1 for c1, c2 in zip(prefix, p['word']) if c1 == c2 and c1 != ' '
        ])
        prefix = prefix[:common]
    s_offset = codeassist.starting_offset(source, offset)
    p_prefix = prefix[offset - s_offset:]
    line = env.lines[row - 1]
    cline = line[:col] + p_prefix + line[col:]
    if cline != line:
        env.curbuf[row - 1] = env.prepare_value(cline, dumps=False)
    env.current.window.cursor = (row, col + len(p_prefix))
    env.run('complete', col - len(prefix) + len(p_prefix) + 1, proposals)
    return True
Esempio n. 2
0
def complete(dot=False):
    """ Ctrl+Space completion.

    :return bool: success

    """
    row, col = env.cursor
    source, offset = env.get_offset_params()
    proposals = get_proporsals(source, offset, dot=dot)
    if not proposals:
        return False

    prefix = proposals[0]['word']

    # Find common part
    for p in proposals:
        common = len([
            c1 for c1, c2 in zip(prefix, p['word']) if c1 == c2 and c1 != ' '
        ])
        prefix = prefix[:common]
    s_offset = codeassist.starting_offset(source, offset)
    p_prefix = prefix[offset - s_offset:]
    line = env.lines[row - 1]
    env.curbuf[row - 1] = line[:col] + p_prefix + line[col:] # noqa
    env.current.window.cursor = (row, col + len(p_prefix))
    env.run('complete', col - len(prefix) + len(p_prefix) + 1, proposals)
    return True
Esempio n. 3
0
def complete(dot=False):
    """ Ctrl+Space completion.

    :return bool: success

    """
    row, col = env.cursor
    source, offset = env.get_offset_params()

    cline = env.current.line[:col]
    env.debug('dot completion', cline)
    if FROM_RE.match(cline) or cline.endswith('..') or cline.endswith('\.'):
        return env.stop("")

    proposals = get_proporsals(source, offset, dot=dot)
    if not proposals:
        return False

    prefix = proposals[0]['word']

    # Find common part
    for p in proposals:
        common = len([
            c1 for c1, c2 in zip(prefix, p['word']) if c1 == c2 and c1 != ' '
        ])
        prefix = prefix[:common]
    s_offset = codeassist.starting_offset(source, offset)
    p_prefix = prefix[offset - s_offset:]
    line = env.lines[row - 1]
    cline = line[:col] + p_prefix + line[col:]
    if cline != line:
        env.curbuf[row - 1] = env.prepare_value(cline, dumps=False)
    env.current.window.cursor = (row, col + len(p_prefix))
    env.run('complete', col - len(prefix) + len(p_prefix) + 1, proposals)
    return True
Esempio n. 4
0
def complete(dot=False):
    """ Ctrl+Space completion.

    :return bool: success

    """
    row, column = vim.current.window.cursor
    source, offset = get_assist_params((row, column))
    proposals = get_proporsals(source, offset, dot=dot)
    if not proposals:
        return False

    prefix = proposals[0]['word']

    # Find common part
    for p in proposals:
        common = len([
            c1 for c1, c2 in zip(prefix, p['word']) if c1 == c2 and c1 != ' '
        ])
        prefix = prefix[:common]
    s_offset = codeassist.starting_offset(source, offset)
    p_prefix = prefix[offset - s_offset:]
    line = vim.current.buffer[row - 1]
    vim.current.buffer[row - 1] = line[:column] + p_prefix + line[column:] # noqa
    vim.current.window.cursor = (row, column + len(p_prefix))
    vim.command('call complete(%s, %s)' % (
        column - len(prefix) + len(p_prefix) + 1, json.dumps(proposals)))

    return True
Esempio n. 5
0
    def CompletionRequest(self, request, response):
        """
    Finds completion proposals for the given location in the given source file.
    """

        # Get information out of the request
        project, resource, source, offset = self._Context(request.context)

        # If the cursor is immediately after a comma or open paren, we should look
        # for a calltip first.
        word_finder = worder.Worder(source)
        non_space_offset = word_finder.code_finder._find_last_non_space_char(
            offset)

        if word_finder.code_finder.code[non_space_offset] in "(,":
            paren_start = word_finder.find_parens_start_from_inside(offset)

            # Get a calltip now
            calltip = codeassist.get_calltip(project,
                                             source,
                                             paren_start - 1,
                                             maxfixes=self.MAXFIXES,
                                             resource=resource,
                                             remove_self=True)

            if calltip is not None:
                response.insertion_position = paren_start + 1
                response.calltip = calltip
                return

        # Do normal completion if a calltip couldn't be found
        proposals = codeassist.code_assist(project,
                                           source,
                                           offset,
                                           maxfixes=self.MAXFIXES,
                                           resource=resource)
        proposals = codeassist.sorted_proposals(proposals)

        # Get the position that this completion will start from.
        starting_offset = codeassist.starting_offset(source, offset)
        response.insertion_position = starting_offset

        # Construct the response protobuf
        for proposal in proposals:
            proposal_pb = response.proposal.add()
            proposal_pb.name = proposal.name

            docstring = proposal.get_doc()

            if proposal.type in self.PROPOSAL_TYPES:
                proposal_pb.type = self.PROPOSAL_TYPES[proposal.type]

            if proposal.scope in self.PROPOSAL_SCOPES:
                proposal_pb.scope = self.PROPOSAL_SCOPES[proposal.scope]

            if docstring is not None:
                proposal_pb.docstring = docstring
Esempio n. 6
0
        def on_select(proposal):
            self.gui.hide()

            edit = self.editor.textbuffer
            start_offset = codeassist.starting_offset(source, offset)

            start = edit.get_iter_at_offset(start_offset)
            end = self.editor.cursor

            edit.delete(start, end)
            edit.insert(start, proposal)
Esempio n. 7
0
        def on_select(proposal):
            self.gui.hide()

            edit = self.editor.textbuffer
            start_offset = codeassist.starting_offset(source, offset)

            start = edit.get_iter_at_offset(start_offset)
            end = self.editor.cursor

            edit.delete(start, end)
            edit.insert(start, proposal)
Esempio n. 8
0
  def CompletionRequest(self, request, response):
    """
    Finds completion proposals for the given location in the given source file.
    """

    # Get information out of the request
    project, resource, source, offset = self._Context(request.context)

    # If the cursor is immediately after a comma or open paren, we should look
    # for a calltip first.
    word_finder = worder.Worder(source)
    non_space_offset = word_finder.code_finder._find_last_non_space_char(offset)

    if word_finder.code_finder.code[non_space_offset] in "(,":
      paren_start = word_finder.find_parens_start_from_inside(offset)

      # Get a calltip now
      calltip = codeassist.get_calltip(project, source, paren_start-1,
                                       maxfixes=self.MAXFIXES,
                                       resource=resource,
                                       remove_self=True)
      
      if calltip is not None:
        response.insertion_position = paren_start + 1
        response.calltip = calltip
        return
    
    # Do normal completion if a calltip couldn't be found
    proposals = codeassist.code_assist(project, source, offset,
                                       maxfixes=self.MAXFIXES,
                                       resource=resource)
    proposals = codeassist.sorted_proposals(proposals)

    # Get the position that this completion will start from.
    starting_offset = codeassist.starting_offset(source, offset)
    response.insertion_position = starting_offset
    
    # Construct the response protobuf
    for proposal in proposals:
      proposal_pb = response.proposal.add()
      proposal_pb.name = proposal.name

      docstring = proposal.get_doc()

      if proposal.type in self.PROPOSAL_TYPES:
        proposal_pb.type = self.PROPOSAL_TYPES[proposal.type]

      if proposal.scope in self.PROPOSAL_SCOPES:
        proposal_pb.scope = self.PROPOSAL_SCOPES[proposal.scope]

      if docstring is not None:
        proposal_pb.docstring = docstring
Esempio n. 9
0
 def starting_offset(self):
     return codeassist.starting_offset(self.source, self.offset)
Esempio n. 10
0
 def starting_offset(self):
     return codeassist.starting_offset(self.source, self.offset)
Esempio n. 11
0
 def test_completion_result(self):
     code = 'my_global = 10\nt = my'
     self.assertEquals(len(code) - 2, starting_offset(code, len(code)))
Esempio n. 12
0
 def test_result_start_offset_for_dotted_completions(self):
     code = 'class Sample(object):\n' \
            '    def method1(self):\n' \
            '        pass\n' \
            'Sample.me'
     self.assertEquals(len(code) - 2, starting_offset(code, len(code)))
Esempio n. 13
0
 def test_completion_result(self):
     code = 'my_global = 10\nt = my'
     self.assertEquals(len(code) - 2, starting_offset(code, len(code)))
Esempio n. 14
0
 def test_result_start_offset_for_dotted_completions(self):
     code = 'class Sample(object):\n    def method1(self):\n        pass\n' \
            'Sample.me'
     self.assertEquals(len(code) - 2, starting_offset(code, len(code)))
Esempio n. 15
0
 def starting_offset(self):
     if self._starting_offset is None:
         self._starting_offset = codeassist.starting_offset(self.source,
                                                            self.offset)
     return self._starting_offset
Esempio n. 16
0
 def starting_offset(self):
     if self._starting_offset is None:
         self._starting_offset = codeassist.starting_offset(self.source,
                                                            self.offset)
     return self._starting_offset