Example #1
0
    def CandidatesForQueryAsync(self, query, start_column):
        filename = vim.current.buffer.name

        if not filename:
            return

        if self.completer.UpdatingTranslationUnit(filename):
            vimsupport.PostVimMessage(
                'Still parsing file, no completions yet.')
            self.completions_future = None
            return

        flags = self.flags.FlagsForFile(filename)
        if not flags:
            vimsupport.PostVimMessage(
                'Still no compile flags, no completions yet.')
            self.completions_future = None
            return

        # TODO: sanitize query, probably in C++ code

        files = ycm_core.UnsavedFileVec()
        if not query:
            files = self.GetUnsavedFilesVector()

        line, _ = vim.current.window.cursor
        column = start_column + 1
        self.completions_future = (
            self.completer.CandidatesForQueryAndLocationInFileAsync(
                query, filename, line, column, files, flags))
Example #2
0
    def GetUnsavedFilesVector(self):
        # CAREFUL HERE! For UnsavedFile filename and contents we are referring
        # directly to Python-allocated and -managed memory since we are accepting
        # pointers to data members of python objects. We need to ensure that those
        # objects outlive our UnsavedFile objects. This is why we need the
        # contents_holder and filename_holder lists, to make sure the string objects
        # are still around when we call CandidatesForQueryAndLocationInFile.  We do
        # this to avoid an extra copy of the entire file contents.

        files = ycm_core.UnsavedFileVec()
        self.contents_holder = []
        self.filename_holder = []
        for buffer in vimsupport.GetUnsavedBuffers():
            if not ClangAvailableForBuffer(buffer):
                continue
            contents = '\n'.join(buffer)
            name = buffer.name
            if not contents or not name:
                continue
            self.contents_holder.append(contents)
            self.filename_holder.append(name)

            unsaved_file = ycm_core.UnsavedFile()
            unsaved_file.contents_ = self.contents_holder[-1]
            unsaved_file.length_ = len(self.contents_holder[-1])
            unsaved_file.filename_ = self.filename_holder[-1]

            files.append(unsaved_file)

        return files
Example #3
0
    def GetUnsavedFilesVector(self, request_data):
        files = ycm_core.UnsavedFileVec()
        for filename, file_data in request_data['file_data'].iteritems():
            if not ClangAvailableForFiletypes(file_data['filetypes']):
                continue
            contents = file_data['contents']
            if not contents or not filename:
                continue

            unsaved_file = ycm_core.UnsavedFile()
            utf8_contents = ToUtf8IfNeeded(contents)
            unsaved_file.contents_ = utf8_contents
            unsaved_file.length_ = len(utf8_contents)
            unsaved_file.filename_ = ToUtf8IfNeeded(filename)

            files.append(unsaved_file)
        return files