2018-01-06 07:16:30 -05:00
|
|
|
# Copyright (C) 2013-2018 YouCompleteMe contributors
|
2013-09-20 20:24:34 -04:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
2017-03-09 09:57:27 -05:00
|
|
|
# Not installing aliases from python-future; it's unreliable and slow.
|
2016-02-27 19:12:24 -05:00
|
|
|
from builtins import * # noqa
|
|
|
|
|
2013-10-03 16:15:43 -04:00
|
|
|
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
2014-12-09 18:22:58 -05:00
|
|
|
JsonFromFuture, HandleServerException )
|
2013-09-20 20:24:34 -04:00
|
|
|
|
2013-10-08 19:21:43 -04:00
|
|
|
|
2013-09-20 20:24:34 -04:00
|
|
|
class EventNotification( BaseRequest ):
|
2018-01-06 07:16:30 -05:00
|
|
|
def __init__( self, event_name, buffer_number = None, extra_data = None ):
|
2013-09-20 20:24:34 -04:00
|
|
|
super( EventNotification, self ).__init__()
|
|
|
|
self._event_name = event_name
|
2018-01-06 07:16:30 -05:00
|
|
|
self._buffer_number = buffer_number
|
2013-09-20 20:24:34 -04:00
|
|
|
self._extra_data = extra_data
|
2016-12-06 19:02:00 -05:00
|
|
|
self._response_future = None
|
2013-10-03 16:15:43 -04:00
|
|
|
self._cached_response = None
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
def Start( self ):
|
2018-01-06 07:16:30 -05:00
|
|
|
request_data = BuildRequestData( self._buffer_number )
|
2013-09-20 20:24:34 -04:00
|
|
|
if self._extra_data:
|
|
|
|
request_data.update( self._extra_data )
|
|
|
|
request_data[ 'event_name' ] = self._event_name
|
|
|
|
|
2013-10-03 16:15:43 -04:00
|
|
|
self._response_future = self.PostDataToHandlerAsync( request_data,
|
|
|
|
'event_notification' )
|
|
|
|
|
|
|
|
|
|
|
|
def Done( self ):
|
2016-12-06 19:02:00 -05:00
|
|
|
return bool( self._response_future ) and self._response_future.done()
|
2013-10-03 16:15:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
def Response( self ):
|
|
|
|
if self._cached_response:
|
|
|
|
return self._cached_response
|
|
|
|
|
|
|
|
if not self._response_future or self._event_name != 'FileReadyToParse':
|
|
|
|
return []
|
|
|
|
|
2016-11-05 09:57:02 -04:00
|
|
|
with HandleServerException( truncate = True ):
|
|
|
|
self._cached_response = JsonFromFuture( self._response_future )
|
2013-10-03 16:15:43 -04:00
|
|
|
|
2014-01-05 15:58:13 -05:00
|
|
|
return self._cached_response if self._cached_response else []
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
|
2016-09-05 11:33:30 -04:00
|
|
|
def SendEventNotificationAsync( event_name,
|
2018-01-06 07:16:30 -05:00
|
|
|
buffer_number = None,
|
2016-09-05 11:33:30 -04:00
|
|
|
extra_data = None ):
|
2018-01-06 07:16:30 -05:00
|
|
|
event = EventNotification( event_name, buffer_number, extra_data )
|
2013-09-20 20:24:34 -04:00
|
|
|
event.Start()
|