@@ -13,7 +13,7 @@ import {
1313 CompletionParams , CompletionContext , CompletionTriggerKind ,
1414 InsertTextFormat , Range , Diagnostic , CompletionItemKind ,
1515 Hover , SignatureHelp , SignatureInformation , ParameterInformation ,
16- Definition , Location , DocumentHighlight , DocumentHighlightKind ,
16+ Definition , DefinitionLink , Location , LocationLink , DocumentHighlight , DocumentHighlightKind ,
1717 SymbolInformation , DocumentSymbolParams , CodeActionContext , DiagnosticSeverity ,
1818 Command , CodeLens , FormattingOptions , TextEdit , WorkspaceEdit , DocumentLinkParams , DocumentLink ,
1919 MarkedString , MarkupContent , ColorInformation , ColorPresentation , FoldingRange , FoldingRangeKind ,
@@ -56,6 +56,12 @@ export namespace ProtocolCompletionItem {
5656 }
5757}
5858
59+ type RangeReplace = { insert : monaco . IRange ; replace : monaco . IRange }
60+
61+ function isRangeReplace ( v : Partial < monaco . IRange > | RangeReplace ) : v is RangeReplace {
62+ return ( v as RangeReplace ) . insert !== undefined ;
63+ }
64+
5965export class MonacoToProtocolConverter {
6066 asPosition ( lineNumber : undefined | null , column : undefined | null ) : { } ;
6167 asPosition ( lineNumber : number , column : undefined | null ) : Pick < Position , 'line' > ;
@@ -75,21 +81,28 @@ export class MonacoToProtocolConverter {
7581 asRange ( range : monaco . IRange ) : Range ;
7682 asRange ( range : monaco . IRange | undefined ) : Range | undefined ;
7783 asRange ( range : monaco . IRange | null ) : Range | null ;
84+ asRange ( range : monaco . IRange | { insert : monaco . IRange ; replace : monaco . IRange } ) : Range ;
7885 asRange ( range : Partial < monaco . IRange > ) : RecursivePartial < Range > ;
7986 asRange ( range : Partial < monaco . IRange > | undefined ) : RecursivePartial < Range > | undefined ;
8087 asRange ( range : Partial < monaco . IRange > | null ) : RecursivePartial < Range > | null ;
81- asRange ( range : Partial < monaco . IRange > | undefined | null ) : RecursivePartial < Range > | undefined | null {
88+ asRange ( range : Partial < monaco . IRange > | undefined | null | RangeReplace ) : RecursivePartial < Range > | undefined | null {
8289 if ( range === undefined ) {
8390 return undefined ;
8491 }
8592 if ( range === null ) {
8693 return null ;
8794 }
88- const start = this . asPosition ( range . startLineNumber , range . startColumn ) ;
89- const end = this . asPosition ( range . endLineNumber , range . endColumn ) ;
90- return {
91- start, end
92- } ;
95+
96+ if ( isRangeReplace ( range ) ) {
97+ return this . asRange ( range . insert ) ;
98+
99+ } else {
100+ const start = this . asPosition ( range . startLineNumber , range . startColumn ) ;
101+ const end = this . asPosition ( range . endLineNumber , range . endColumn ) ;
102+ return {
103+ start, end
104+ } ;
105+ }
93106 }
94107
95108 asTextDocumentIdentifier ( model : IReadOnlyModel ) : TextDocumentIdentifier {
@@ -679,14 +692,23 @@ export class ProtocolToMonacoConverter {
679692 }
680693
681694 asDefinitionResult ( item : Definition ) : monaco . languages . Definition ;
695+ asDefinitionResult ( item : DefinitionLink [ ] ) : monaco . languages . Definition ;
682696 asDefinitionResult ( item : undefined | null ) : undefined ;
683- asDefinitionResult ( item : Definition | undefined | null ) : monaco . languages . Definition | undefined ;
684- asDefinitionResult ( item : Definition | undefined | null ) : monaco . languages . Definition | undefined {
697+ asDefinitionResult ( item : Definition | DefinitionLink [ ] | undefined | null ) : monaco . languages . Definition | undefined ;
698+ asDefinitionResult ( item : Definition | DefinitionLink [ ] | undefined | null ) : monaco . languages . Definition | undefined {
685699 if ( ! item ) {
686700 return undefined ;
687701 }
688702 if ( Is . array ( item ) ) {
689- return item . map ( ( location ) => this . asLocation ( location ) ) ;
703+ if ( item . length == 0 ) {
704+ return undefined ;
705+ } else if ( LocationLink . is ( item [ 0 ] ) ) {
706+ let links : LocationLink [ ] = item as LocationLink [ ] ;
707+ return links . map ( ( location ) => this . asLocationLink ( location ) ) ;
708+ } else {
709+ let locations : Location [ ] = item as Location [ ] ;
710+ return locations . map ( ( location ) => this . asLocation ( location ) ) ;
711+ }
690712 } else {
691713 return this . asLocation ( item ) ;
692714 }
@@ -706,6 +728,24 @@ export class ProtocolToMonacoConverter {
706728 }
707729 }
708730
731+ asLocationLink ( item : undefined | null ) : undefined ;
732+ asLocationLink ( item : ls . LocationLink ) : monaco . languages . LocationLink ;
733+ asLocationLink ( item : ls . LocationLink | undefined | null ) : monaco . languages . LocationLink | undefined {
734+ if ( ! item ) {
735+ return undefined ;
736+ }
737+ let result : monaco . languages . LocationLink = {
738+ uri : monaco . Uri . parse ( item . targetUri ) ,
739+ range : this . asRange ( item . targetSelectionRange ) ! , // See issue: https://github.com/Microsoft/vscode/issues/58649
740+ originSelectionRange : this . asRange ( item . originSelectionRange ) ,
741+ targetSelectionRange : this . asRange ( item . targetSelectionRange )
742+ } ;
743+ if ( ! result . targetSelectionRange ) {
744+ throw new Error ( `targetSelectionRange must not be undefined or null` ) ;
745+ }
746+ return result ;
747+ }
748+
709749 asSignatureHelpResult ( item : undefined | null ) : undefined ;
710750 asSignatureHelpResult ( item : SignatureHelp ) : monaco . languages . SignatureHelpResult ;
711751 asSignatureHelpResult ( item : SignatureHelp | undefined | null ) : monaco . languages . SignatureHelpResult | undefined ;
@@ -882,7 +922,7 @@ export class ProtocolToMonacoConverter {
882922 }
883923 }
884924
885- asCompletionItem ( item : CompletionItem , defaultRange : monaco . IRange ) : ProtocolCompletionItem {
925+ asCompletionItem ( item : CompletionItem , defaultRange : monaco . IRange | RangeReplace ) : ProtocolCompletionItem {
886926 const result = < ProtocolCompletionItem > { label : item . label } ;
887927 if ( item . detail ) { result . detail = item . detail ; }
888928 if ( item . documentation ) {
@@ -952,7 +992,8 @@ export class ProtocolToMonacoConverter {
952992 return [ CompletionItemKind . Text , value ] ;
953993 }
954994
955- asCompletionInsertText ( item : CompletionItem , defaultRange : monaco . IRange ) : { insertText : string , range : monaco . IRange , fromEdit : boolean , isSnippet : boolean } {
995+ asCompletionInsertText ( item : CompletionItem , defaultRange : monaco . IRange | RangeReplace )
996+ : { insertText : string , range : monaco . IRange | RangeReplace , fromEdit : boolean , isSnippet : boolean } {
956997 const isSnippet = item . insertTextFormat === InsertTextFormat . Snippet ;
957998 if ( item . textEdit ) {
958999 const range = this . asRange ( item . textEdit . range ) ;
0 commit comments