Skip to content

Commit

Permalink
Try and avoid errors for file changing, increase timeout and decode m…
Browse files Browse the repository at this point in the history
…odifiers (probably)
  • Loading branch information
puremourning committed Apr 21, 2021
1 parent d95360a commit 2327c58
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
54 changes: 41 additions & 13 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ class ResponseAbortedException( Exception ):

class ResponseFailedException( Exception ):
"""Raised by LanguageServerConnection if a request returns an error"""
pass # pragma: no cover
def __init__( self, error ):
self.error_code = error.get( 'code' ) or 0
self.error_message = error.get( 'message' ) or "No message"
super().__init__( f'Request failed: { self.error_code }: '
f'{ self.error_message }' )


class IncompatibleCompletionException( Exception ):
Expand Down Expand Up @@ -212,11 +216,7 @@ def AwaitResponse( self, timeout ):

if 'error' in self._message:
error = self._message[ 'error' ]
raise ResponseFailedException(
'Request failed: '
f'{ error.get( "code" ) or 0 }'
': '
f'{ error.get( "message" ) or "No message" }' )
raise ResponseFailedException( error )

return self._message

Expand Down Expand Up @@ -1559,12 +1559,23 @@ def ComputeSemanticTokens( self, request_data ):
return {}

request_id = self.GetConnection().NextRequestId()
response = self._connection.GetResponse(
request_id,
lsp.SemanticTokens(
request_id,
request_data ),
REQUEST_TIMEOUT_COMPLETION )

# Retry up to 3 times to avoid ContentModified errors
MAX_RETRY = 3
for i in range( MAX_RETRY ):
try:
response = self._connection.GetResponse(
request_id,
lsp.SemanticTokens(
request_id,
request_data ),
3 * REQUEST_TIMEOUT_COMPLETION )
break
except ResponseFailedException as e:
if i < ( MAX_RETRY - 1 ) and e.error_code == lsp.Errors.ContentModified:
continue
else:
raise

if response is None:
return {}
Expand Down Expand Up @@ -3339,6 +3350,23 @@ class Token:
token_type = 0
token_modifiers = 0

def DecodeModifiers( self, tokenModifiers ):
modifiers = []
bit_index = 0
while True:
bit_value = pow( 2, bit_index )

if bit_value > self.token_modifiers:
break

if self.token_modifiers & bit_value:
modifiers.append( tokenModifiers[ bit_index ] )

bit_index += 1

return modifiers


last_token = Token()
tokens = []

Expand Down Expand Up @@ -3372,7 +3400,7 @@ class Token:
}
) ),
'type': atlas.tokenTypes[ token.token_type ],
'modifiers': [] # TODO: bits represent indexes in atlas
'modifiers': token.DecodeModifiers( atlas.tokenModifiers )
} )

last_token = token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class Errors:
'enumMember',
'event',
'function',
'method',
'member',
'macro',
'keyword',
Expand Down

0 comments on commit 2327c58

Please sign in to comment.