@@ -19,7 +19,7 @@ import {
1919 Command , CodeLens , FormattingOptions , TextEdit , WorkspaceEdit , DocumentLinkParams , DocumentLink ,
2020 MarkedString , MarkupContent , ColorInformation , ColorPresentation , FoldingRange , FoldingRangeKind ,
2121 DiagnosticRelatedInformation , MarkupKind , SymbolKind , DocumentSymbol , CodeAction , SignatureHelpContext , SignatureHelpTriggerKind ,
22- SemanticTokens , InsertTextMode , AnnotatedTextEdit , ChangeAnnotation , CodeDescription
22+ SemanticTokens , InsertTextMode , AnnotatedTextEdit , ChangeAnnotation , CodeDescription , InlayHint , InlayHintLabelPart
2323} from './services' ;
2424
2525export type RecursivePartial < T > = {
@@ -76,6 +76,16 @@ export namespace ProtocolCodeAction {
7676 }
7777}
7878
79+ export interface ProtocolInlayHint extends monaco . languages . InlayHint {
80+ data ?: unknown ;
81+ }
82+ export namespace ProtocolInlayHint {
83+ export function is ( item : any ) : item is ProtocolInlayHint {
84+ return ! ! item && 'data' in item ;
85+ }
86+ }
87+
88+
7989type RangeReplace = { insert : monaco . IRange ; replace : monaco . IRange }
8090
8191function isRangeReplace ( v : Partial < monaco . IRange > | RangeReplace ) : v is RangeReplace {
@@ -127,6 +137,21 @@ export class MonacoToProtocolConverter {
127137 }
128138 }
129139
140+ asLocation ( item : monaco . languages . Location ) : Location ;
141+ asLocation ( item : undefined | null ) : undefined ;
142+ asLocation ( item : monaco . languages . Location | undefined | null ) : Location | undefined ;
143+ asLocation ( item : monaco . languages . Location | undefined | null ) : Location | undefined {
144+ if ( ! item ) {
145+ return undefined ;
146+ }
147+ const uri = item . uri . toString ( ) ;
148+ const range = this . asRange ( item . range ) ;
149+ return {
150+ uri,
151+ range
152+ }
153+ }
154+
130155 asTextDocumentIdentifier ( model : monaco . editor . IReadOnlyModel ) : TextDocumentIdentifier {
131156 return {
132157 uri : model . uri . toString ( )
@@ -493,7 +518,7 @@ export class MonacoToProtocolConverter {
493518 result . diagnostics = this . asDiagnostics ( item . diagnostics ) ;
494519 }
495520 if ( item . edit ) {
496- throw new Error ( `VS Code code actions can only be converted to a protocol code action without an edit.` ) ;
521+ throw new Error ( `VS Code code actions can only be converted to a protocol code action without an edit.` ) ;
497522 }
498523 if ( item . command ) {
499524 result . command = this . asCommand ( item . command ) ;
@@ -511,6 +536,34 @@ export class MonacoToProtocolConverter {
511536 }
512537 return result ;
513538 }
539+
540+ asInlayHintLabelPart ( part : monaco . languages . InlayHintLabelPart ) : InlayHintLabelPart {
541+ return {
542+ value : part . label ,
543+ command : this . asCommand ( part . command ) ,
544+ location : this . asLocation ( part . location ) ,
545+ tooltip : this . asMarkupContent ( part . tooltip )
546+ }
547+ }
548+
549+ asInlayHintLabel ( label : string | monaco . languages . InlayHintLabelPart [ ] ) : string | InlayHintLabelPart [ ] {
550+ if ( Array . isArray ( label ) ) {
551+ return label . map ( part => this . asInlayHintLabelPart ( part ) )
552+ }
553+ return label
554+ }
555+
556+ asInlayHint ( item : monaco . languages . InlayHint ) : InlayHint {
557+ let result = InlayHint . create (
558+ this . asPosition ( item . position . lineNumber , item . position . column ) ,
559+ this . asInlayHintLabel ( item . label ) ,
560+ item . kind
561+ ) ;
562+ if ( ProtocolInlayHint . is ( item ) ) {
563+ if ( item . data ) { result . data = item . data } ;
564+ }
565+ return result ;
566+ }
514567}
515568
516569export class ProtocolToMonacoConverter {
@@ -1235,4 +1288,45 @@ export class ProtocolToMonacoConverter {
12351288 }
12361289 }
12371290
1291+ asInlayHintLabelPart ( part : InlayHintLabelPart ) : monaco . languages . InlayHintLabelPart {
1292+ return {
1293+ label : part . value ,
1294+ command : this . asCommand ( part . command ) ,
1295+ location : this . asLocation ( part . location ) ,
1296+ tooltip : part . tooltip && this . asMarkdownString ( part . tooltip )
1297+ }
1298+ }
1299+
1300+ asInlayHintLabel ( label : string | InlayHintLabelPart [ ] ) : string | monaco . languages . InlayHintLabelPart [ ] {
1301+ if ( Array . isArray ( label ) ) {
1302+ return label . map ( part => this . asInlayHintLabelPart ( part ) )
1303+ }
1304+ return label
1305+ }
1306+
1307+ asInlayHint ( inlayHint : InlayHint ) : ProtocolInlayHint {
1308+ return {
1309+ data : inlayHint . data ,
1310+ label : this . asInlayHintLabel ( inlayHint . label ) ,
1311+ position : this . asPosition ( inlayHint . position ) ,
1312+ kind : inlayHint . kind ,
1313+ paddingLeft : inlayHint . paddingLeft ,
1314+ paddingRight : inlayHint . paddingRight ,
1315+ tooltip : inlayHint . tooltip && this . asMarkdownString ( inlayHint . tooltip )
1316+ }
1317+ }
1318+
1319+ asInlayHintList ( items : InlayHint [ ] ) : monaco . languages . InlayHintList ;
1320+ asInlayHintList ( items : undefined | null ) : undefined ;
1321+ asInlayHintList ( items : InlayHint [ ] | undefined | null ) : monaco . languages . InlayHintList | undefined ;
1322+ asInlayHintList ( items : InlayHint [ ] | undefined | null ) : monaco . languages . InlayHintList | undefined {
1323+ if ( ! items ) {
1324+ return undefined ;
1325+ }
1326+ return {
1327+ hints : items . map ( ( hint ) => this . asInlayHint ( hint ) ) ,
1328+ dispose : ( ) => { }
1329+ } ;
1330+ }
1331+
12381332}
0 commit comments