def HandleFileParseRequest( self, block = False ):
    if not self.IsServerReady():
      return

    current_buffer = self.CurrentBuffer()
    # Order is important here:
    # FileParseRequestReady has a low cost, while
    # NativeFiletypeCompletionUsable is a blocking server request
    if ( not current_buffer.IsResponseHandled() and
         current_buffer.FileParseRequestReady( block ) and
         self.NativeFiletypeCompletionUsable() ):

      if self._user_options[ 'show_diagnostics_ui' ]:
        # Forcefuly update the location list, etc. from the parse request when
        # doing something like :YcmDiags
        async_diags = any( self._message_poll_requests.get( filetype )
                           for filetype in vimsupport.CurrentFiletypes() )
        current_buffer.UpdateDiagnostics( block or not async_diags )
      else:
        # If the user disabled diagnostics, we just want to check
        # the _latest_file_parse_request for any exception or UnknownExtraConf
        # response, to allow the server to raise configuration warnings, etc.
        # to the user. We ignore any other supplied data.
        current_buffer.GetResponse()

      # We set the file parse request as handled because we want to prevent
      # repeated issuing of the same warnings/errors/prompts. Setting this
      # makes IsRequestHandled return True until the next request is created.
      #
      # Note: it is the server's responsibility to determine the frequency of
      # error/warning/prompts when receiving a FileReadyToParse event, but
      # it is our responsibility to ensure that we only apply the
      # warning/error/prompt received once (for each event).
      current_buffer.MarkResponseHandled()
Example #2
0
def LastEnteredCharIsIdentifierChar():
    line, current_column = vimsupport.CurrentLineContentsAndCodepointColumn()
    if current_column - 1 < 0:
        return False
    filetype = vimsupport.CurrentFiletypes()[0]
    return (identifier_utils.StartOfLongestIdentifierEndingAtIndex(
        line, current_column, filetype) != current_column)
Example #3
0
  def SendSignatureHelpRequest( self ):
    filetype = vimsupport.CurrentFiletypes()[ 0 ]
    if not self._signature_help_available_requests[ filetype ].Done():
      return

    sig_help_available = self._signature_help_available_requests[
        filetype ].Response()
    if sig_help_available == 'NO':
      return

    if sig_help_available == 'PENDING':
      # Send another /signature_help_available request
      self._signature_help_available_requests[ filetype ].Start( filetype )
      return

    if not self.NativeFiletypeCompletionUsable():
      return

    if not self._latest_completion_request:
      return

    request_data = self._latest_completion_request.request_data.copy()
    request_data[ 'signature_help_state' ] = self._signature_help_state.state

    self._AddExtraConfDataIfNeeded( request_data )

    self._latest_signature_help_request = SignatureHelpRequest(
      request_data )
    self._latest_signature_help_request.Start()
Example #4
0
 def IsAllowed(self, diagnostic):
     # NOTE: in this class's implementation, we ask vimsupport for
     #  the current filetypes and delegate automatically; it is probably,
     #  more efficient, however, to call SubsetForTypes() and reuse
     #  the returned DiagnosticFilter if it will be checked repeatedly.
     filetypes = vimsupport.CurrentFiletypes()
     return self.SubsetForTypes(filetypes).IsAllowed(diagnostic)
    def OnCompleteDone(self):
        if not self.Done():
            return

        if 'cs' in vimsupport.CurrentFiletypes():
            self._OnCompleteDone_Csharp()
        else:
            extra_datas = self._GetExtraDataUserMayHaveCompleted()
            if not extra_datas:
                return

            # If we have user_data in completions (8.0.1493 or later), then we would
            # only ever return max. 1 completion here. However, if we had to guess, it
            # is possible that we matched multiple completion items (e.g. for
            # overloads, or similar classes in multiple packages). In any case, rather
            # than prompting the user and disturbing her workflow, we just apply the
            # first one. This might be wrong, but the solution is to use a newer
            # version of Vim which supports user_data on completion items
            completion_extra_data = extra_datas[0]

            self._OnCompleteDone_FixIt(completion_extra_data)

            snippet = completion_extra_data.get('snippet', None)
            if snippet:
                self._OnCompleteDone_Snippet(snippet)
Example #6
0
  def SendSignatureHelpRequest( self ):
    """Send a signature help request, if we're ready to. Return whether or not a
    request was sent (and should be checked later)"""
    if not self.NativeFiletypeCompletionUsable():
      return False

    for filetype in vimsupport.CurrentFiletypes():
      if not self.SignatureHelpAvailableRequestComplete( filetype ):
        continue

      sig_help_available = self._signature_help_available_requests[
          filetype ].Response()
      if sig_help_available == 'NO':
        continue

      if sig_help_available == 'PENDING':
        # Send another /signature_help_available request
        self._signature_help_available_requests[ filetype ].Start( filetype )
        continue

      if not self._latest_completion_request:
        return False

      request_data = self._latest_completion_request.request_data.copy()
      request_data[ 'signature_help_state' ] = self._signature_help_state.state

      self._AddExtraConfDataIfNeeded( request_data )

      self._latest_signature_help_request = SignatureHelpRequest( request_data )
      self._latest_signature_help_request.Start()
      return True

    return False
    def OnCompleteDone(self):
        if not self.Done():
            return

        if 'cs' in vimsupport.CurrentFiletypes():
            self._OnCompleteDone_Csharp()
        else:
            self._OnCompleteDone_FixIt()
Example #8
0
 def CurrentFiletypeCompletionEnabled(self):
     filetypes = vimsupport.CurrentFiletypes()
     filetype_to_disable = self._user_options[
         'filetype_specific_completion_to_disable']
     if '*' in filetype_to_disable:
         return False
     else:
         return not any([x in filetype_to_disable for x in filetypes])
Example #9
0
    def OnBufferVisit(self):
        for filetype in vimsupport.CurrentFiletypes():
            # Send the signature help available request for these filetypes if we need
            # to (as a side effect of checking if it is complete)
            self.SignatureHelpAvailableRequestComplete(filetype, True)

        extra_data = {}
        self._AddUltiSnipsDataIfNeeded(extra_data)
        SendEventNotificationAsync('BufferVisit', extra_data=extra_data)
Example #10
0
 def OnBufferVisit(self):
     filetype = vimsupport.CurrentFiletypes()[0]
     # The constructor of dictionary values starts the request,
     # so the line below fires a new request only if the dictionary
     # value is accessed for the first time.
     self._signature_help_available_requests[filetype].Done()
     extra_data = {}
     self._AddUltiSnipsDataIfNeeded(extra_data)
     SendEventNotificationAsync('BufferVisit', extra_data=extra_data)
Example #11
0
    def _CurrentFiletype(self):
        filetypes = vimsupport.CurrentFiletypes()
        supported = self.SupportedFiletypes()

        for filetype in filetypes:
            if filetype in supported:
                return filetype

        return filetypes[0]
Example #12
0
    def _AddSyntaxDataIfNeeded(self, extra_data):
        if not self._user_options['seed_identifiers_with_syntax']:
            return
        filetype = vimsupport.CurrentFiletypes()[0]
        if filetype in self._filetypes_with_keywords_loaded:
            return

        self._filetypes_with_keywords_loaded.add(filetype)
        extra_data['syntax_keywords'] = list(
            syntax_parse.SyntaxKeywordsForCurrentBuffer())
Example #13
0
  def _ApplyDiagnosticFilter( self, diags, extra_predicate = None ):
    filetypes = vimsupport.CurrentFiletypes()
    diag_filter = self._diag_filter.SubsetForTypes( filetypes )
    predicate = diag_filter.IsAllowed
    if extra_predicate is not None:
      def Filter( diag ):
        return extra_predicate( diag ) and diag_filter.IsAllowed( diag )

      predicate = Filter

    return filter( predicate, diags )
Example #14
0
def CurrentIdentifierFinished():
    line, current_column = vimsupport.CurrentLineContentsAndCodepointColumn()
    previous_char_index = current_column - 1
    if previous_char_index < 0:
        return True
    filetype = vimsupport.CurrentFiletypes()[0]
    regex = identifier_utils.IdentifierRegexForFiletype(filetype)

    for match in regex.finditer(line):
        if match.end() == previous_char_index:
            return True
    # If the whole line is whitespace, that means the user probably finished an
    # identifier on the previous line.
    return line[:current_column].isspace()
Example #15
0
  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]
Example #16
0
def BuildRequestData(start_column=None, query=None, include_buffer_data=True):
    line, column = vimsupport.CurrentLineAndColumn()
    filepath = vimsupport.GetCurrentBufferFilepath()
    request_data = {
        'filetypes': vimsupport.CurrentFiletypes(),
        'line_num': line,
        'column_num': column,
        'start_column': start_column,
        'line_value': vim.current.line,
        'filepath': filepath
    }

    if include_buffer_data:
        request_data['file_data'] = vimsupport.GetUnsavedAndCurrentBufferData()
    if query:
        request_data['query'] = query

    return request_data
 def _GetCompleteDoneHooks(self):
     filetypes = vimsupport.CurrentFiletypes()
     for key, value in iteritems(self._complete_done_hooks):
         if key in filetypes:
             yield value
Example #18
0
def InCFamilyFile():
    return any([
        filetype in CLANG_FILETYPES
        for filetype in vimsupport.CurrentFiletypes()
    ])
Example #19
0
 def DiagnosticUiSupportedForCurrentFiletype(self):
     return any([
         x in DIAGNOSTIC_UI_FILETYPES
         for x in vimsupport.CurrentFiletypes()
     ])
Example #20
0
 def NativeFiletypeCompletionAvailable(self):
     return any([
         self.FiletypeCompleterExistsForFiletype(x)
         for x in vimsupport.CurrentFiletypes()
     ])
Example #21
0
def _CurrentFiletypeCompletionEnabled():
    filetypes = vimsupport.CurrentFiletypes()
    return not all(
        [x in FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE for x in filetypes])
Example #22
0
def CompletionStartColumn():
  return ( request_wrap.CompletionStartColumn(
      vimsupport.CurrentLineContents(),
      vimsupport.CurrentColumn() + 1,
      vimsupport.CurrentFiletypes()[ 0 ] ) - 1 )
Example #23
0
 def OnFileTypeSet(self):
     buffer_number = vimsupport.GetCurrentBufferNumber()
     filetypes = vimsupport.CurrentFiletypes()
     self._buffers[buffer_number].UpdateFromFileTypes(filetypes)
     self.OnBufferVisit()