Skip to content

Commit

Permalink
More refactoring of completion item resolution code
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Oct 26, 2017
1 parent 634c61d commit 134b581
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,17 +687,37 @@ def ComputeCandidatesInner( self, request_data ):
return self._ResolveCompletionItems( items, request_data )


def _ResolveCompletionItem( self, item ):
try:
resolve_id = self.GetConnection().NextRequestId()
resolve = lsp.ResolveCompletion( resolve_id, item )
response = self.GetConnection().GetResponse(
resolve_id,
resolve,
REQUEST_TIMEOUT_COMPLETION )
item = response[ 'result' ]
except ResponseFailedException:
_logger.exception( 'A completion item could not be resolved. Using '
'basic data.' )

return item


def _ShouldResolveCompletionItems( self ):
return ( 'completionProvider' in self._server_capabilities and
self._server_capabilities[ 'completionProvider' ].get(
'resolveProvider',
False ) )


def _ResolveCompletionItems( self, items, request_data ):
"""Issue the resolve request for each completion item in |items|, then fix
up the items such that a single start codepoint is used."""

# We might not actually need to issue the resolve request if the server
# claims that it doesn't support it. However, we still might need to fix up
# the completion items.
do_resolve = (
'completionProvider' in self._server_capabilities and
self._server_capabilities[ 'completionProvider' ].get( 'resolveProvider',
False ) )
do_resolve = self._ShouldResolveCompletionItems( )

#
# Important note on the following logic:
Expand Down Expand Up @@ -735,17 +755,7 @@ def _ResolveCompletionItems( self, items, request_data ):
for item in items:
# First, resolve the completion.
if do_resolve:
try:
resolve_id = self.GetConnection().NextRequestId()
resolve = lsp.ResolveCompletion( resolve_id, item )
response = self.GetConnection().GetResponse(
resolve_id,
resolve,
REQUEST_TIMEOUT_COMPLETION )
item = response[ 'result' ]
except ResponseFailedException:
_logger.exception( 'A completion item could not be resolved. Using '
'basic data.' )
item = self._ResolveCompletionItem( item )

try:
( insertion_text, fixits, start_codepoint ) = (
Expand Down

0 comments on commit 134b581

Please sign in to comment.