コード例 #1
0
 def __init__(self):
     self.gencomp = GeneralCompleterStore()
     self.omnicomp = OmniCompleter()
     self.filetype_completers = {}
コード例 #2
0
 def __init__(self, user_options):
     self._user_options = user_options
     self._filetype_completers = {}
     self._gencomp = GeneralCompleterStore(self._user_options)
コード例 #3
0
class YouCompleteMe(object):
    def __init__(self):
        self.gencomp = GeneralCompleterStore()
        self.omnicomp = OmniCompleter()
        self.filetype_completers = {}

    def GetGeneralCompleter(self):
        return self.gencomp

    def GetOmniCompleter(self):
        return self.omnicomp

    def GetFiletypeCompleter(self):
        filetypes = vimsupport.CurrentFiletypes()

        completers = [
            self.GetFiletypeCompleterForFiletype(filetype)
            for filetype in filetypes
        ]

        if not completers:
            return None

        # Try to find a native completer first
        for completer in completers:
            if completer and completer is not self.omnicomp:
                return completer

        # Return the omni completer for the first filetype
        return completers[0]

    def GetFiletypeCompleterForFiletype(self, filetype):
        try:
            return self.filetype_completers[filetype]
        except KeyError:
            pass

        module_path = _PathToFiletypeCompleterPluginLoader(filetype)

        completer = None
        supported_filetypes = [filetype]
        if os.path.exists(module_path):
            module = imp.load_source(filetype, module_path)
            completer = module.GetCompleter()
            if completer:
                supported_filetypes.extend(completer.SupportedFiletypes())
        else:
            completer = self.omnicomp

        for supported_filetype in supported_filetypes:
            self.filetype_completers[supported_filetype] = completer
        return completer

    def ShouldUseGeneralCompleter(self, start_column):
        return self.gencomp.ShouldUseNow(start_column)

    def ShouldUseFiletypeCompleter(self, start_column):
        if self.FiletypeCompletionUsable():
            return self.GetFiletypeCompleter().ShouldUseNow(start_column)
        return False

    def NativeFiletypeCompletionAvailable(self):
        completer = self.GetFiletypeCompleter()
        return bool(completer) and completer is not self.omnicomp

    def FiletypeCompletionAvailable(self):
        return bool(self.GetFiletypeCompleter())

    def NativeFiletypeCompletionUsable(self):
        return (_CurrentFiletypeCompletionEnabled()
                and self.NativeFiletypeCompletionAvailable())

    def FiletypeCompletionUsable(self):
        return (_CurrentFiletypeCompletionEnabled()
                and self.FiletypeCompletionAvailable())

    def OnFileReadyToParse(self):
        self.gencomp.OnFileReadyToParse()

        if self.FiletypeCompletionUsable():
            self.GetFiletypeCompleter().OnFileReadyToParse()

    def OnBufferUnload(self, deleted_buffer_file):
        self.gencomp.OnBufferUnload(deleted_buffer_file)

        if self.FiletypeCompletionUsable():
            self.GetFiletypeCompleter().OnBufferUnload(deleted_buffer_file)

    def OnBufferVisit(self):
        self.gencomp.OnBufferVisit()

        if self.FiletypeCompletionUsable():
            self.GetFiletypeCompleter().OnBufferVisit()

    def OnInsertLeave(self):
        self.gencomp.OnInsertLeave()

        if self.FiletypeCompletionUsable():
            self.GetFiletypeCompleter().OnInsertLeave()

    def DiagnosticsForCurrentFileReady(self):
        if self.FiletypeCompletionUsable():
            return self.GetFiletypeCompleter().DiagnosticsForCurrentFileReady()
        return False

    def GetDiagnosticsForCurrentFile(self):
        if self.FiletypeCompletionUsable():
            return self.GetFiletypeCompleter().GetDiagnosticsForCurrentFile()
        return []

    def ShowDetailedDiagnostic(self):
        if self.FiletypeCompletionUsable():
            return self.GetFiletypeCompleter().ShowDetailedDiagnostic()

    def GettingCompletions(self):
        if self.FiletypeCompletionUsable():
            return self.GetFiletypeCompleter().GettingCompletions()
        return False

    def OnCurrentIdentifierFinished(self):
        self.gencomp.OnCurrentIdentifierFinished()

        if self.FiletypeCompletionUsable():
            self.GetFiletypeCompleter().OnCurrentIdentifierFinished()

    def DebugInfo(self):
        completers = set(self.filetype_completers.values())
        completers.add(self.gencomp)
        output = []
        for completer in completers:
            if not completer:
                continue
            debug = completer.DebugInfo()
            if debug:
                output.append(debug)

        has_clang_support = ycm_core.HasClangSupport()
        output.append(
            'Has Clang support compiled in: {0}'.format(has_clang_support))

        if has_clang_support:
            output.append(ycm_core.ClangVersion())

        return '\n'.join(output)
コード例 #4
0
class ServerState(object):
    def __init__(self, user_options):
        self._user_options = user_options
        self._filetype_completers = {}
        self._gencomp = GeneralCompleterStore(self._user_options)

    @property
    def user_options(self):
        return self._user_options

    def Shutdown(self):
        for completer in self._filetype_completers.itervalues():
            if completer:
                completer.Shutdown()

        self._gencomp.Shutdown()

    def _GetFiletypeCompleterForFiletype(self, filetype):
        try:
            return self._filetype_completers[filetype]
        except KeyError:
            pass

        module_path = PathToFiletypeCompleterPluginLoader(filetype)
        completer = None
        supported_filetypes = [filetype]
        if os.path.exists(module_path):
            module = imp.load_source(filetype, module_path)
            completer = module.GetCompleter(self._user_options)
            if completer:
                supported_filetypes.extend(completer.SupportedFiletypes())

        for supported_filetype in supported_filetypes:
            self._filetype_completers[supported_filetype] = completer
        return completer

    def GetFiletypeCompleter(self, current_filetypes):
        completers = [
            self._GetFiletypeCompleterForFiletype(filetype)
            for filetype in current_filetypes
        ]

        for completer in completers:
            if completer:
                return completer

        raise ValueError(
            'No semantic completer exists for filetypes: {0}'.format(
                current_filetypes))

    def FiletypeCompletionAvailable(self, filetypes):
        try:
            self.GetFiletypeCompleter(filetypes)
            return True
        except:
            return False

    def FiletypeCompletionUsable(self, filetypes):
        return (self.CurrentFiletypeCompletionEnabled(filetypes)
                and self.FiletypeCompletionAvailable(filetypes))

    def ShouldUseGeneralCompleter(self, request_data):
        return self._gencomp.ShouldUseNow(request_data)

    def ShouldUseFiletypeCompleter(self, request_data):
        filetypes = request_data['filetypes']
        if self.FiletypeCompletionUsable(filetypes):
            return (ForceSemanticCompletion(request_data)
                    or self.GetFiletypeCompleter(filetypes).ShouldUseNow(
                        request_data))
        return False

    def GetGeneralCompleter(self):
        return self._gencomp

    def CurrentFiletypeCompletionEnabled(self, current_filetypes):
        filetype_to_disable = self._user_options[
            'filetype_specific_completion_to_disable']
        return not all([x in filetype_to_disable for x in current_filetypes])