Skip to content

Commit

Permalink
Rename legacy-named 'server' to 'connection'
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Sep 21, 2017
1 parent 4f4d4b3 commit ae2a73f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
26 changes: 13 additions & 13 deletions ycmd/completers/java/java_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__( self, user_options ):


with self._server_state_mutex:
self._server = None
self._connection = None
self._server_handle = None
self._server_stderr = None
self._workspace_path = None
Expand All @@ -123,8 +123,8 @@ def __init__( self, user_options ):
self._StopServer()


def GetServer( self ):
return self._server
def GetConnection( self ):
return self._connection


def SupportedFiletypes( self ):
Expand Down Expand Up @@ -195,7 +195,7 @@ def _Reset( self ):
self._server_handle = None
self._received_ready_message = threading.Event()

self._server = None
self._connection = None

self._ServerReset()

Expand Down Expand Up @@ -238,17 +238,17 @@ def _StartServer( self ):
_logger.warning( 'JDT Language Server failed to start' )
return

self._server = (
self._connection = (
language_server_completer.StandardIOLanguageServerConnection(
self._server_handle.stdin,
self._server_handle.stdout,
self._GetDefaultNotificationHandler() )
)

self._server.start()
self._connection.start()

try:
self._server.TryServerConnection()
self._connection.TryServerConnection()
except language_server_completer.LanguageServerConnectionTimeout:
_logger.warn( 'Java language server failed to start, or did not '
'connect successfully' )
Expand All @@ -270,8 +270,8 @@ def _StopServerCleanly( self ):
utils.WaitUntilProcessIsTerminated( self._server_handle,
timeout = 5 )

if self._server:
self._server.join()
if self._connection:
self._connection.join()

_logger.info( 'JDT Language server stopped' )
except Exception:
Expand All @@ -289,8 +289,8 @@ def _StopServerForecefully( self ):
utils.WaitUntilProcessIsTerminated( self._server_handle,
timeout = 5 )

if self._server:
self._server.join()
if self._connection:
self._connection.join()

_logger.info( 'JDT Language server killed' )
except Exception:
Expand All @@ -305,8 +305,8 @@ def _StopServer( self ):
self._server_handle.stderr.close()

# Tell the connection to expect the server to disconnect
if self._server:
self._server.stop()
if self._connection:
self._connection.stop()

# Tell the server to exit using the shutdown request.
self._StopServerCleanly()
Expand Down
67 changes: 34 additions & 33 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,13 @@ def _ServerReset( self ):

def _ShutdownServer( self ):
if self.ServerIsReady():
request_id = self.GetServer().NextRequestId()
request_id = self.GetConnection().NextRequestId()
msg = lsapi.Shutdown( request_id )

try:
self.GetServer().GetResponse( request_id,
msg,
REQUEST_TIMEOUT_INITIALISE )
self.GetConnection().GetResponse( request_id,
msg,
REQUEST_TIMEOUT_INITIALISE )
except ResponseAbortedException:
# When the language server (heinously) dies handling the shutdown
# request, it is aborted. Just return - we're done.
Expand All @@ -578,12 +578,12 @@ def _ShutdownServer( self ):

# Assuming that worked, send the exit notification
if self.ServerIsHealthy():
self.GetServer().SendNotification( lsapi.Exit() )
self.GetConnection().SendNotification( lsapi.Exit() )



@abc.abstractmethod
def GetServer( sefl ):
def GetConnection( sefl ):
"""Method that must be implemented by derived classes to return an instance
of LanguageServerConnection appropriate for the language server in
question"""
Expand All @@ -609,11 +609,11 @@ def ComputeCandidatesInner( self, request_data ):

self._RefreshFiles( request_data )

request_id = self.GetServer().NextRequestId()
request_id = self.GetConnection().NextRequestId()
msg = lsapi.Completion( request_id, request_data )
response = self.GetServer().GetResponse( request_id,
msg,
REQUEST_TIMEOUT_COMPLETION )
response = self.GetConnection().GetResponse( request_id,
msg,
REQUEST_TIMEOUT_COMPLETION )

do_resolve = (
'completionProvider' in self._server_capabilities and
Expand All @@ -627,11 +627,12 @@ def MakeCompletion( item ):
# _at all_ here.

if do_resolve:
resolve_id = self.GetServer().NextRequestId()
resolve_id = self.GetConnection().NextRequestId()
resolve = lsapi.ResolveCompletion( resolve_id, item )
response = self.GetServer().GetResponse( resolve_id,
resolve,
REQUEST_TIMEOUT_COMPLETION )
response = self.GetConnection().GetResponse(
resolve_id,
resolve,
REQUEST_TIMEOUT_COMPLETION )
item = response[ 'result' ]

# Note Vim only displays the first character, so we map them to the
Expand Down Expand Up @@ -705,7 +706,7 @@ def OnFileReadyToParse( self, request_data ):


def _PollForMessagesNoBlock( self, request_data, messages ):
notification = self.GetServer()._notifications.get_nowait( )
notification = self.GetConnection()._notifications.get_nowait( )
message = self._ConvertNotificationToMessage( request_data,
notification )
if message:
Expand All @@ -715,12 +716,12 @@ def _PollForMessagesNoBlock( self, request_data, messages ):
def _PollForMessagesBlock( self, request_data ):
try:
while True:
if not self.GetServer():
if not self.GetConnection():
# The server isn't running or something. Don't re-poll, as this will
# just cause errors.
return False

notification = self.GetServer()._notifications.get(
notification = self.GetConnection()._notifications.get(
timeout = MESSAGE_POLL_TIMEOUT )
message = self._ConvertNotificationToMessage( request_data,
notification )
Expand All @@ -736,7 +737,7 @@ def PollForMessagesInner( self, request_data ):
messages = list()
try:
while True:
if not self.GetServer():
if not self.GetConnection():
# The server isn't running or something. Don't re-poll.
return False

Expand Down Expand Up @@ -833,7 +834,7 @@ def _RefreshFiles( self, request_data ):
file_data[ 'contents' ] )

self._serverFileState[ file_name ] = 'Open'
self.GetServer().SendNotification( msg )
self.GetConnection().SendNotification( msg )

stale_files = list()
for file_name in iterkeys( self._serverFileState ):
Expand All @@ -846,15 +847,15 @@ def _RefreshFiles( self, request_data ):
# TODO(Ben): Isn't there a client->server event when a buffer is closed?
for file_name in stale_files:
msg = lsapi.DidCloseTextDocument( file_name )
self.GetServer().SendNotification( msg )
self.GetConnection().SendNotification( msg )
del self._serverFileState[ file_name ]


def _SendInitialiseAsync( self ):
with self._mutex:
assert not self._initialise_response

request_id = self.GetServer().NextRequestId()
request_id = self.GetConnection().NextRequestId()
msg = lsapi.Initialise( request_id )

def response_handler( response, message ):
Expand All @@ -863,7 +864,7 @@ def response_handler( response, message ):

self._HandleInitialiseInPollThread( message )

self._initialise_response = self.GetServer().GetResponseAsync(
self._initialise_response = self.GetConnection().GetResponseAsync(
request_id,
msg,
response_handler )
Expand Down Expand Up @@ -892,8 +893,8 @@ def _GetHoverResponse( self, request_data ):
if not self.ServerIsReady():
raise RuntimeError( 'Server is initialising. Please wait.' )

request_id = self.GetServer().NextRequestId()
response = self.GetServer().GetResponse(
request_id = self.GetConnection().NextRequestId()
response = self.GetConnection().GetResponse(
request_id,
lsapi.Hover( request_id,
request_data ),
Expand Down Expand Up @@ -923,8 +924,8 @@ def _GoToDeclaration( self, request_data ):
if not self.ServerIsReady():
raise RuntimeError( 'Server is initialising. Please wait.' )

request_id = self.GetServer().NextRequestId()
response = self.GetServer().GetResponse(
request_id = self.GetConnection().NextRequestId()
response = self.GetConnection().GetResponse(
request_id,
lsapi.Definition( request_id,
request_data ),
Expand All @@ -942,8 +943,8 @@ def _GoToReferences( self, request_data ):
if not self.ServerIsReady():
raise RuntimeError( 'Server is initialising. Please wait.' )

request_id = self.GetServer().NextRequestId()
response = self.GetServer().GetResponse(
request_id = self.GetConnection().NextRequestId()
response = self.GetConnection().GetResponse(
request_id,
lsapi.References( request_id,
request_data ),
Expand Down Expand Up @@ -978,9 +979,9 @@ def WithinRange( diag ):
d for d in file_diagnostics if WithinRange( d )
]

request_id = self.GetServer().NextRequestId()
request_id = self.GetConnection().NextRequestId()
if matched_diagnostics:
code_actions = self.GetServer().GetResponse(
code_actions = self.GetConnection().GetResponse(
request_id,
lsapi.CodeAction( request_id,
request_data,
Expand All @@ -989,7 +990,7 @@ def WithinRange( diag ):
REQUEST_TIMEOUT_COMMAND )

else:
code_actions = self.GetServer().GetResponse(
code_actions = self.GetConnection().GetResponse(
request_id,
lsapi.CodeAction(
request_id,
Expand Down Expand Up @@ -1031,8 +1032,8 @@ def _Rename( self, request_data, args ):

new_name = args[ 0 ]

request_id = self.GetServer().NextRequestId()
response = self.GetServer().GetResponse(
request_id = self.GetConnection().NextRequestId()
response = self.GetConnection().GetResponse(
request_id,
lsapi.Rename( request_id,
request_data,
Expand Down

0 comments on commit ae2a73f

Please sign in to comment.