@@ -1551,10 +1551,13 @@ def ComputeSemanticTokens( self, request_data ):
15511551 if not self ._semantic_token_atlas :
15521552 return {}
15531553
1554+ range_supported = self ._server_capabilities [ 'semanticTokensProvider' ].get (
1555+ 'range' , False )
1556+
15541557 self ._UpdateServerWithCurrentFileContents ( request_data )
15551558
15561559 request_id = self .GetConnection ().NextRequestId ()
1557- body = lsp .SemanticTokens ( request_id , request_data )
1560+ body = lsp .SemanticTokens ( request_id , range_supported , request_data )
15581561
15591562 for _ in RetryOnFailure ( [ lsp .Errors .ContentModified ] ):
15601563 response = self ._connection .GetResponse (
@@ -1578,6 +1581,53 @@ def ComputeSemanticTokens( self, request_data ):
15781581 }
15791582
15801583
1584+ def ComputeInlayHints ( self , request_data ):
1585+ if not self ._initialize_event .wait ( REQUEST_TIMEOUT_COMPLETION ):
1586+ return []
1587+
1588+ if not self ._ServerIsInitialized ():
1589+ return []
1590+
1591+ if 'inlayHintProvider' not in self ._server_capabilities :
1592+ return []
1593+
1594+ self ._UpdateServerWithCurrentFileContents ( request_data )
1595+ request_id = self .GetConnection ().NextRequestId ()
1596+ body = lsp .InlayHints ( request_id , request_data )
1597+
1598+ for _ in RetryOnFailure ( [ lsp .Errors .ContentModified ] ):
1599+ response = self ._connection .GetResponse (
1600+ request_id ,
1601+ body ,
1602+ 3 * REQUEST_TIMEOUT_COMPLETION )
1603+
1604+ if response is None :
1605+ return []
1606+
1607+ file_contents = GetFileLines ( request_data , request_data [ 'filepath' ] )
1608+
1609+ def BuildLabel ( label_or_labels ):
1610+ if isinstance ( label_or_labels , list ):
1611+ return ' ' .join ( label [ 'value' ] for label in label_or_labels )
1612+ return label_or_labels
1613+
1614+ def BuildInlayHint ( inlay_hint : dict ):
1615+ return {
1616+ 'kind' : lsp .INLAY_HINT_KIND [ inlay_hint [ 'kind' ] ],
1617+ 'position' : responses .BuildLocationData (
1618+ _BuildLocationAndDescription (
1619+ request_data [ 'filepath' ],
1620+ file_contents ,
1621+ inlay_hint [ 'position' ] )[ 0 ]
1622+ ),
1623+ 'label' : BuildLabel ( inlay_hint [ 'label' ] ),
1624+ 'paddingLeft' : inlay_hint .get ( 'paddingLeft' , False ),
1625+ 'paddingRight' : inlay_hint .get ( 'paddingRight' , False ),
1626+ }
1627+
1628+ return [ BuildInlayHint ( h ) for h in response .get ( 'result' ) or [] ]
1629+
1630+
15811631 def GetDetailedDiagnostic ( self , request_data ):
15821632 self ._UpdateServerWithFileContents ( request_data )
15831633
@@ -3117,11 +3167,11 @@ def _LocationListToGoTo( request_data, positions ):
31173167 if len ( positions ) > 1 :
31183168 return [
31193169 responses .BuildGoToResponseFromLocation (
3120- * _PositionToLocationAndDescription ( request_data , position ) )
3170+ * _LspLocationToLocationAndDescription ( request_data , position ) )
31213171 for position in positions
31223172 ]
31233173 return responses .BuildGoToResponseFromLocation (
3124- * _PositionToLocationAndDescription ( request_data , positions [ 0 ] ) )
3174+ * _LspLocationToLocationAndDescription ( request_data , positions [ 0 ] ) )
31253175 except ( IndexError , KeyError ):
31263176 raise RuntimeError ( 'Cannot jump to location' )
31273177
@@ -3130,7 +3180,7 @@ def _SymbolInfoListToGoTo( request_data, symbols ):
31303180 """Convert a list of LSP SymbolInformation into a YCM GoTo response"""
31313181
31323182 def BuildGoToLocationFromSymbol ( symbol ):
3133- location , line_value = _PositionToLocationAndDescription (
3183+ location , line_value = _LspLocationToLocationAndDescription (
31343184 request_data ,
31353185 symbol [ 'location' ] )
31363186
@@ -3157,10 +3207,10 @@ def BuildGoToLocationFromSymbol( symbol ):
31573207 return locations
31583208
31593209
3160- def _PositionToLocationAndDescription ( request_data , position ):
3161- """Convert a LSP position to a ycmd location."""
3210+ def _LspLocationToLocationAndDescription ( request_data , location ):
3211+ """Convert a LSP Location to a ycmd location."""
31623212 try :
3163- filename = lsp .UriToFilePath ( position [ 'uri' ] )
3213+ filename = lsp .UriToFilePath ( location [ 'uri' ] )
31643214 file_contents = GetFileLines ( request_data , filename )
31653215 except lsp .InvalidUriException :
31663216 LOGGER .debug ( 'Invalid URI, file contents not available in GoTo' )
@@ -3176,7 +3226,7 @@ def _PositionToLocationAndDescription( request_data, position ):
31763226
31773227 return _BuildLocationAndDescription ( filename ,
31783228 file_contents ,
3179- position [ 'range' ][ 'start' ] )
3229+ location [ 'range' ][ 'start' ] )
31803230
31813231
31823232def _LspToYcmdLocation ( file_contents , location ):
0 commit comments