11import * as vscode from 'vscode' ;
2- import * as lc from 'vscode-languageclient ' ;
2+ import * as ra from './rust-analyzer-api ' ;
33
44import { Ctx } from './ctx' ;
55import { log , sendRequestWithRetry } from './util' ;
@@ -39,16 +39,6 @@ export function activateInlayHints(ctx: Ctx) {
3939 void hintsUpdater . setEnabled ( ctx . config . displayInlayHints ) ;
4040}
4141
42- interface InlayHintsParams {
43- textDocument : lc . TextDocumentIdentifier ;
44- }
45-
46- interface InlayHint {
47- range : vscode . Range ;
48- kind : "TypeHint" | "ParameterHint" ;
49- label : string ;
50- }
51-
5242const typeHintDecorationType = vscode . window . createTextEditorDecorationType ( {
5343 after : {
5444 color : new vscode . ThemeColor ( 'rust_analyzer.inlayHint' ) ,
@@ -107,9 +97,9 @@ class HintsUpdater {
10797 if ( newHints == null ) return ;
10898
10999 const newTypeDecorations = newHints
110- . filter ( hint => hint . kind === ' TypeHint' )
100+ . filter ( hint => hint . kind === ra . InlayKind . TypeHint )
111101 . map ( hint => ( {
112- range : hint . range ,
102+ range : this . ctx . client . protocol2CodeConverter . asRange ( hint . range ) ,
113103 renderOptions : {
114104 after : {
115105 contentText : `: ${ hint . label } ` ,
@@ -119,9 +109,9 @@ class HintsUpdater {
119109 this . setTypeDecorations ( editor , newTypeDecorations ) ;
120110
121111 const newParameterDecorations = newHints
122- . filter ( hint => hint . kind === ' ParameterHint' )
112+ . filter ( hint => hint . kind === ra . InlayKind . ParameterHint )
123113 . map ( hint => ( {
124- range : hint . range ,
114+ range : this . ctx . client . protocol2CodeConverter . asRange ( hint . range ) ,
125115 renderOptions : {
126116 before : {
127117 contentText : `${ hint . label } : ` ,
@@ -151,20 +141,15 @@ class HintsUpdater {
151141 ) ;
152142 }
153143
154- private async queryHints ( documentUri : string ) : Promise < InlayHint [ ] | null > {
144+ private async queryHints ( documentUri : string ) : Promise < ra . InlayHint [ ] | null > {
155145 this . pending . get ( documentUri ) ?. cancel ( ) ;
156146
157147 const tokenSource = new vscode . CancellationTokenSource ( ) ;
158148 this . pending . set ( documentUri , tokenSource ) ;
159149
160- const request : InlayHintsParams = { textDocument : { uri : documentUri } } ;
150+ const request = { textDocument : { uri : documentUri } } ;
161151
162- return sendRequestWithRetry < InlayHint [ ] > (
163- this . ctx . client ,
164- 'rust-analyzer/inlayHints' ,
165- request ,
166- tokenSource . token
167- )
152+ return sendRequestWithRetry ( this . ctx . client , ra . inlayHints , request , tokenSource . token )
168153 . catch ( _ => null )
169154 . finally ( ( ) => {
170155 if ( ! tokenSource . token . isCancellationRequested ) {
0 commit comments