11import { DecorationOptions , DecorationRangeBehavior , Disposable , OutputChannel , Range , TextDocument , TextDocumentChangeEvent , TextEditor , TextEditorDecorationType , ThemeColor , window , workspace } from "vscode" ;
22import { LanguageClient } from "vscode-languageclient/node" ;
33
4- type Implicit = { position : number , text : string } ;
5- type ImplicitSet = { before : Implicit [ ] , after : Implicit [ ] } ;
4+ type InlayHint = { position : number , text : string } ;
5+ type InlayHintSet = { before : InlayHint [ ] , after : InlayHint [ ] } ;
66
7- class Implicits implements Disposable {
7+ class InlayHints implements Disposable {
88 // The client used to communicate with the language server. In the case of
9- // this class it's used to send a syntaxTree/implicits request.
9+ // this class it's used to send a textDocument/inlayHints request.
1010 private readonly languageClient : LanguageClient ;
1111
1212 // The output channel used for logging for this class. It's given from the
1313 // main file so that it uses the same as the rest of the extension.
1414 private readonly outputChannel : OutputChannel ;
1515
1616 private readonly decorationType : TextEditorDecorationType ;
17- private readonly implicitsCache : WeakMap < TextDocument , ImplicitSet > ;
17+ private readonly inlayHintsCache : WeakMap < TextDocument , InlayHintSet > ;
1818 private readonly debouncedHandleTextDocumentChange : Debounced < TextEditor > ;
1919
2020 private readonly disposables : Disposable [ ] ;
@@ -23,31 +23,31 @@ class Implicits implements Disposable {
2323 this . languageClient = languageClient ;
2424 this . outputChannel = outputChannel ;
2525
26- const color = new ThemeColor ( "syntaxTree.implicits " ) ;
26+ const color = new ThemeColor ( "syntaxTree.inlayHints " ) ;
2727 this . decorationType = window . createTextEditorDecorationType ( {
2828 before : { color, fontStyle : "normal" } ,
2929 after : { color, fontStyle : "normal" } ,
3030 rangeBehavior : DecorationRangeBehavior . ClosedClosed
3131 } ) ;
3232
33- this . implicitsCache = new WeakMap ( ) ;
34- this . setImplicitsForEditors ( window . visibleTextEditors ) ;
33+ this . inlayHintsCache = new WeakMap ( ) ;
34+ this . setInlayHintsForEditors ( window . visibleTextEditors ) ;
3535
3636 // Here we're going to debounce the handleTextDocumentChange callback so
3737 // that we're not reacting too quickly to user inputs and making it flash
3838 // alll around the editor.
3939 this . debouncedHandleTextDocumentChange = debounce ( 300 , ( editor : TextEditor ) => {
4040 this . outputChannel . appendLine ( "Handling text document changes (debounced)" ) ;
41- this . implicitsCache . delete ( editor . document ) ;
42- this . setImplicitsForEditor ( editor ) ;
41+ this . inlayHintsCache . delete ( editor . document ) ;
42+ this . setInlayHintsForEditor ( editor ) ;
4343 } ) ;
4444
4545 // Track all of the various callbacks and objects that implement Disposable
46- // so that when we need to dispose of the entire Implicits instance we can
46+ // so that when we need to dispose of the entire InlayHints instance we can
4747 // iterate through and dispose all of them.
4848 this . disposables = [
4949 this . decorationType ,
50- window . onDidChangeVisibleTextEditors ( this . setImplicitsForEditors , this ) ,
50+ window . onDidChangeVisibleTextEditors ( this . setInlayHintsForEditors , this ) ,
5151 workspace . onDidChangeTextDocument ( this . handleTextDocumentChange , this ) ,
5252 this . debouncedHandleTextDocumentChange
5353 ] ;
@@ -63,20 +63,20 @@ class Implicits implements Disposable {
6363 if ( editor !== undefined && event . document === editor . document ) {
6464 this . debouncedHandleTextDocumentChange ( editor ) ;
6565 } else {
66- this . implicitsCache . delete ( event . document ) ;
66+ this . inlayHintsCache . delete ( event . document ) ;
6767 }
6868 }
6969
70- // Asynchronously get the implicits for a given text document, optionally
70+ // Asynchronously get the inlay hints for a given text document, optionally
7171 // using a cache if it has already been populated.
72- async getImplicitsForTextDocument ( document : TextDocument ) : Promise < ImplicitSet | undefined > {
72+ async getInlayHintsForTextDocument ( document : TextDocument ) : Promise < InlayHintSet | undefined > {
7373 if ( document . languageId !== "ruby" ) {
7474 // This editor may have previously been a Ruby file, but that has now
75- // changed. So we should delete the implicits that may be there.
76- if ( this . implicitsCache . has ( document ) ) {
77- this . implicitsCache . delete ( document ) ;
75+ // changed. So we should delete the inlay hints that may be there.
76+ if ( this . inlayHintsCache . has ( document ) ) {
77+ this . inlayHintsCache . delete ( document ) ;
7878
79- // Return an empty set of implicits so that it gets properly cleared
79+ // Return an empty set of inlay hints so that it gets properly cleared
8080 // from the document.
8181 return { before : [ ] , after : [ ] } ;
8282 }
@@ -86,56 +86,56 @@ class Implicits implements Disposable {
8686 return undefined ;
8787 }
8888
89- // Check the cache first to see if we have already computed the implicits
89+ // Check the cache first to see if we have already computed the inlay hints
9090 // for this document. Return them if we have them.
91- let implicits = this . implicitsCache . get ( document ) ;
92- if ( implicits ) {
93- this . outputChannel . appendLine ( "Loading implicits from cache" ) ;
94- return implicits ;
91+ let inlayHints = this . inlayHintsCache . get ( document ) ;
92+ if ( inlayHints ) {
93+ this . outputChannel . appendLine ( "Loading inlay hints from cache" ) ;
94+ return inlayHints ;
9595 }
9696
97- // Otherwise, asynchronously request the implicits from the language server,
98- // cache the response, and return it.
99- this . outputChannel . appendLine ( "Requesting implicits " ) ;
100- implicits = await this . languageClient . sendRequest < ImplicitSet > ( "syntaxTree/implicits " , {
97+ // Otherwise, asynchronously request the inlay hints from the language
98+ // server, cache the response, and return it.
99+ this . outputChannel . appendLine ( "Requesting inlay hints " ) ;
100+ inlayHints = await this . languageClient . sendRequest < InlayHintSet > ( "textDocument/inlayHints " , {
101101 textDocument : { uri : document . uri . toString ( ) }
102102 } ) ;
103103
104104 // In case of a syntax error, this is not going to return anything. In that
105105 // case, we don't want to set the cache to anything, but we also don't want
106- // to clear the previous implicits either. So we're just going to return
106+ // to clear the previous inlay hints either. So we're just going to return
107107 // undefined
108- if ( ! implicits ) {
108+ if ( ! inlayHints ) {
109109 return undefined ;
110110 }
111111
112- this . implicitsCache . set ( document , implicits ) ;
113- return implicits ;
112+ this . inlayHintsCache . set ( document , inlayHints ) ;
113+ return inlayHints ;
114114 }
115115
116- async setImplicitsForEditor ( editor : TextEditor ) {
117- const implicits = await this . getImplicitsForTextDocument ( editor . document ) ;
118- if ( ! implicits ) {
116+ async setInlayHintsForEditor ( editor : TextEditor ) {
117+ const inlayHints = await this . getInlayHintsForTextDocument ( editor . document ) ;
118+ if ( ! inlayHints ) {
119119 return ;
120120 }
121121
122122 const decorations : DecorationOptions [ ] = [
123- ...implicits . before . map ( ( { position, text : contentText } ) => ( {
123+ ...inlayHints . before . map ( ( { position, text : contentText } ) => ( {
124124 range : new Range ( editor . document . positionAt ( position ) , editor . document . positionAt ( position ) ) ,
125125 renderOptions : { before : { contentText } }
126126 } ) ) ,
127- ...implicits . after . map ( ( { position, text : contentText } ) => ( {
127+ ...inlayHints . after . map ( ( { position, text : contentText } ) => ( {
128128 range : new Range ( editor . document . positionAt ( position ) , editor . document . positionAt ( position ) ) ,
129129 renderOptions : { after : { contentText } }
130130 } ) )
131131 ] ;
132132
133- this . outputChannel . appendLine ( "Settings implicits " ) ;
133+ this . outputChannel . appendLine ( "Settings inlay hints " ) ;
134134 editor . setDecorations ( this . decorationType , decorations ) ;
135135 }
136136
137- setImplicitsForEditors ( editors : readonly TextEditor [ ] ) {
138- editors . forEach ( ( editor ) => this . setImplicitsForEditor ( editor ) ) ;
137+ setInlayHintsForEditors ( editors : readonly TextEditor [ ] ) {
138+ editors . forEach ( ( editor ) => this . setInlayHintsForEditor ( editor ) ) ;
139139 }
140140}
141141
@@ -187,4 +187,4 @@ function debounce<T extends object>(delay: number, callback: (argument: T) => vo
187187 return debounced ;
188188}
189189
190- export default Implicits ;
190+ export default InlayHints ;
0 commit comments