示例#1
0
class Buffer:
    def __init__(self, bufnr, user_options, filetypes):
        self._number = bufnr
        self._parse_tick = 0
        self._handled_tick = 0
        self._parse_request = None
        self._should_resend = False
        self._diag_interface = DiagnosticInterface(bufnr, user_options)
        self._open_loclist_on_ycm_diags = user_options[
            'open_loclist_on_ycm_diags']
        self._semantic_highlighting = SemanticHighlighting(bufnr, user_options)
        self.inlay_hints = InlayHints(bufnr, user_options)
        self.UpdateFromFileTypes(filetypes)

    def FileParseRequestReady(self, block=False):
        return bool(self._parse_request
                    and (block or self._parse_request.Done()))

    def SendParseRequest(self, extra_data):
        # Don't send a parse request if one is in progress
        if self._parse_request is not None and not self._parse_request.Done():
            self._should_resend = True
            return

        self._should_resend = False

        self._parse_request = EventNotification('FileReadyToParse',
                                                extra_data=extra_data)
        self._parse_request.Start()
        # Decrement handled tick to ensure correct handling when we are forcing
        # reparse on buffer visit and changed tick remains the same.
        self._handled_tick -= 1
        self._parse_tick = self._ChangedTick()

    def NeedsReparse(self):
        return self._parse_tick != self._ChangedTick()

    def ShouldResendParseRequest(self):
        return (self._should_resend
                or (bool(self._parse_request)
                    and self._parse_request.ShouldResend()))

    def UpdateDiagnostics(self, force=False):
        if force or not self._async_diags:
            self.UpdateWithNewDiagnostics(self._parse_request.Response(),
                                          False)
        else:
            # We need to call the response method, because it might throw an exception
            # or require extra config confirmation, even if we don't actually use the
            # diagnostics.
            self._parse_request.Response()

    def UpdateWithNewDiagnostics(self, diagnostics, async_message):
        self._async_diags = async_message
        self._diag_interface.UpdateWithNewDiagnostics(
            diagnostics, not self._async_diags
            and self._open_loclist_on_ycm_diags)

    def UpdateMatches(self):
        self._diag_interface.UpdateMatches()

    def PopulateLocationList(self, open_on_edit=False):
        return self._diag_interface.PopulateLocationList(open_on_edit)

    def GetResponse(self):
        return self._parse_request.Response()

    def IsResponseHandled(self):
        return self._handled_tick == self._parse_tick

    def MarkResponseHandled(self):
        self._handled_tick = self._parse_tick

    def OnCursorMoved(self):
        self._diag_interface.OnCursorMoved()

    def GetErrorCount(self):
        return self._diag_interface.GetErrorCount()

    def GetWarningCount(self):
        return self._diag_interface.GetWarningCount()

    def RefreshDiagnosticsUI(self):
        return self._diag_interface.RefreshDiagnosticsUI()

    def DiagnosticsForLine(self, line_number):
        return self._diag_interface.DiagnosticsForLine(line_number)

    def UpdateFromFileTypes(self, filetypes):
        self._filetypes = filetypes
        # We will set this to true if we ever receive any diagnostics asyncronously.
        self._async_diags = False

    def SendSemanticTokensRequest(self):
        self._semantic_highlighting.SendRequest()

    def SemanticTokensRequestReady(self):
        return self._semantic_highlighting.IsResponseReady()

    def UpdateSemanticTokens(self):
        return self._semantic_highlighting.Update()

    def _ChangedTick(self):
        return vimsupport.GetBufferChangedTick(self._number)
示例#2
0
class Buffer( object ):

  def __init__( self, bufnr, user_options, async_diags ):
    self.number = bufnr
    self._parse_tick = 0
    self._handled_tick = 0
    self._parse_request = None
    self._async_diags = async_diags
    self._diag_interface = DiagnosticInterface( bufnr, user_options )


  def FileParseRequestReady( self, block = False ):
    return bool( self._parse_request and
                 ( block or self._parse_request.Done() ) )


  def SendParseRequest( self, extra_data ):
    self._parse_request = EventNotification( 'FileReadyToParse',
                                             extra_data = extra_data )
    self._parse_request.Start()
    # Decrement handled tick to ensure correct handling when we are forcing
    # reparse on buffer visit and changed tick remains the same.
    self._handled_tick -= 1
    self._parse_tick = self._ChangedTick()


  def NeedsReparse( self ):
    return self._parse_tick != self._ChangedTick()


  def ShouldResendParseRequest( self ):
    return bool( self._parse_request and self._parse_request.ShouldResend() )


  def UpdateDiagnostics( self, force=False ):
    if force or not self._async_diags:
      self.UpdateWithNewDiagnostics( self._parse_request.Response() )
    else:
      # We need to call the response method, because it might throw an exception
      # or require extra config confirmation, even if we don't actually use the
      # diagnostics.
      self._parse_request.Response()


  def UpdateWithNewDiagnostics( self, diagnostics ):
    self._diag_interface.UpdateWithNewDiagnostics( diagnostics )


  def UpdateMatches( self ):
    self._diag_interface.UpdateMatches()


  def PopulateLocationList( self ):
    return self._diag_interface.PopulateLocationList()


  def GetResponse( self ):
    return self._parse_request.Response()


  def IsResponseHandled( self ):
    return self._handled_tick == self._parse_tick


  def MarkResponseHandled( self ):
    self._handled_tick = self._parse_tick


  def OnCursorMoved( self ):
    self._diag_interface.OnCursorMoved()


  def GetErrorCount( self ):
    return self._diag_interface.GetErrorCount()


  def GetWarningCount( self ):
    return self._diag_interface.GetWarningCount()


  def _ChangedTick( self ):
    return vimsupport.GetBufferChangedTick( self.number )