@@ -2,9 +2,54 @@ import {
22 DisposableCollection , MonacoLanguageClient
33} from 'monaco-languageclient'
44import { StaticFeature , FeatureState } from 'vscode-languageclient/lib/common/api'
5- import { WorkspaceEdit } from 'vscode-languageserver-protocol'
5+ import { InlayHint , InlayHintParams , InlayHintRefreshRequest , InlayHintRequest , WorkspaceEdit } from 'vscode-languageserver-protocol'
66import * as vscode from 'vscode'
77
8+ async function asInlayHints ( values : InlayHint [ ] | undefined | null , client : MonacoLanguageClient ) : Promise < vscode . InlayHint [ ] | undefined > {
9+ if ( ! Array . isArray ( values ) ) {
10+ return undefined
11+ }
12+ return values . map ( lsHint => asInlayHint ( lsHint , client ) )
13+ }
14+
15+ function asInlayHint ( value : InlayHint , client : MonacoLanguageClient ) : vscode . InlayHint {
16+ const label = value . label as string
17+ const result = new vscode . InlayHint ( client . protocol2CodeConverter . asPosition ( value . position ) , label )
18+ result . paddingRight = true
19+ result . kind = vscode . InlayHintKind . Parameter
20+ return result
21+ }
22+
23+ /**
24+ * Comes from https://github.com/redhat-developer/vscode-java/blob/9b6046eecc65fd47507f309a3ccc9add45c6d3be/src/inlayHintsProvider.ts#L5
25+ */
26+ class JavaInlayHintsProvider implements vscode . InlayHintsProvider {
27+ private onDidChange = new vscode . EventEmitter < void > ( )
28+ public onDidChangeInlayHints = this . onDidChange . event
29+
30+ constructor ( private client : MonacoLanguageClient ) {
31+ this . client . onRequest ( InlayHintRefreshRequest . type , async ( ) => {
32+ this . onDidChange . fire ( )
33+ } )
34+ }
35+
36+ public async provideInlayHints ( document : vscode . TextDocument , range : vscode . Range , token : vscode . CancellationToken ) : Promise < vscode . InlayHint [ ] | undefined > {
37+ const requestParams : InlayHintParams = {
38+ textDocument : this . client . code2ProtocolConverter . asTextDocumentIdentifier ( document ) ,
39+ range : this . client . code2ProtocolConverter . asRange ( range )
40+ }
41+ try {
42+ const values = await this . client . sendRequest ( InlayHintRequest . type , requestParams , token )
43+ if ( token . isCancellationRequested ) {
44+ return [ ]
45+ }
46+ return asInlayHints ( values , this . client )
47+ } catch ( error ) {
48+ return this . client . handleFailedRequest ( InlayHintRequest . type , token , error , [ ] )
49+ }
50+ }
51+ }
52+
853export class JavaExtensionFeature implements StaticFeature {
954 private disposables : DisposableCollection
1055 constructor ( private languageClient : MonacoLanguageClient ) {
@@ -19,6 +64,8 @@ export class JavaExtensionFeature implements StaticFeature {
1964 const edit = await this . languageClient . protocol2CodeConverter . asWorkspaceEdit ( obj )
2065 return vscode . workspace . applyEdit ( edit )
2166 } ) )
67+
68+ this . disposables . push ( vscode . languages . registerInlayHintsProvider ( this . languageClient . clientOptions . documentSelector ! , new JavaInlayHintsProvider ( this . languageClient ) ) )
2269 }
2370
2471 getState ( ) : FeatureState {
0 commit comments