@@ -9,6 +9,7 @@ import { should, assert } from 'chai';
99import { activateCSharpExtension , isRazorWorkspace , isSlnWithGenerator , restartOmniSharpServer } from './integrationHelpers' ;
1010import testAssetWorkspace from './testAssets/testAssetWorkspace' ;
1111import * as path from 'path' ;
12+ import { InlayHint , LinePositionSpanTextChange } from '../../src/omnisharp/protocol' ;
1213
1314const chai = require ( 'chai' ) ;
1415chai . use ( require ( 'chai-arrays' ) ) ;
@@ -49,7 +50,7 @@ suite(`Inlay Hints ${testAssetWorkspace.description}`, function () {
4950 const projectDirectory = testAssetWorkspace . projects [ 0 ] . projectDirectoryPath ;
5051 const filePath = path . join ( projectDirectory , fileName ) ;
5152 fileUri = vscode . Uri . file ( filePath ) ;
52-
53+
5354 await vscode . commands . executeCommand ( "vscode.open" , fileUri ) ;
5455 await testAssetWorkspace . waitForIdle ( activation . eventStream ) ;
5556 } ) ;
@@ -60,19 +61,42 @@ suite(`Inlay Hints ${testAssetWorkspace.description}`, function () {
6061
6162 test ( "Hints retrieved for region" , async ( ) => {
6263 const range = new vscode . Range ( new vscode . Position ( 4 , 8 ) , new vscode . Position ( 15 , 85 ) ) ;
63- const hints : vscode . InlayHint [ ] = await vscode . commands . executeCommand ( 'vscode.executeInlayHintProvider' , fileUri , range ) ;
64+ const hints : vscode . InlayHint [ ] = await vscode . commands . executeCommand ( 'vscode.executeInlayHintProvider' , fileUri , range ) ;
65+
6466 assert . lengthOf ( hints , 6 ) ;
65- assertValues ( hints [ 0 ] , 'InlayHints ' , 6 , 12 ) ;
66- assertValues ( hints [ 1 ] , ' InlayHints' , 7 , 27 ) ;
67- assertValues ( hints [ 2 ] , 'string ' , 8 , 28 ) ;
68- assertValues ( hints [ 3 ] , 'i: ' , 9 , 17 ) ;
69- assertValues ( hints [ 4 ] , 'param1: ' , 10 , 15 ) ;
70- assertValues ( hints [ 5 ] , 'param1: ' , 11 , 27 ) ;
71-
72- function assertValues ( hint : vscode . InlayHint , expectedLabel : string , expectedLine : number , expectedCharacter : number ) {
73- assert . equal ( hint . label , expectedLabel ) ;
74- assert . equal ( hint . position . line , expectedLine ) ;
75- assert . equal ( hint . position . character , expectedCharacter ) ;
67+
68+ assertInlayHintEqual ( hints [ 0 ] , { Label : 'InlayHints ' , Position : { Line : 6 , Column : 12 } , Data : { } , TextEdits : [ { StartLine : 6 , StartColumn : 8 , EndLine : 6 , EndColumn : 11 , NewText : 'InlayHints' } ] } ) ;
69+ assertInlayHintEqual ( hints [ 1 ] , { Label : ' InlayHints' , Position : { Line : 7 , Column : 27 } , Data : { } , TextEdits : [ { StartLine : 7 , StartColumn : 27 , EndLine : 7 , EndColumn : 27 , NewText : ' InlayHints' } ] } ) ;
70+ assertInlayHintEqual ( hints [ 2 ] , { Label : 'string ' , Position : { Line : 8 , Column : 28 } , Data : { } , TextEdits : [ { StartLine : 8 , StartColumn : 28 , EndLine : 8 , EndColumn : 28 , NewText : 'string ' } ] } ) ;
71+ assertInlayHintEqual ( hints [ 3 ] , { Label : 'i: ' , Position : { Line : 9 , Column : 17 } , Data : { } , TextEdits : [ { StartLine : 9 , StartColumn : 17 , EndLine : 9 , EndColumn : 17 , NewText : 'i: ' } ] } ) ;
72+ assertInlayHintEqual ( hints [ 4 ] , { Label : 'param1: ' , Position : { Line : 10 , Column : 15 } , Data : { } , TextEdits : [ { StartLine : 10 , StartColumn : 15 , EndLine : 10 , EndColumn : 15 , NewText : 'param1: ' } ] } ) ;
73+ assertInlayHintEqual ( hints [ 5 ] , { Label : 'param1: ' , Position : { Line : 11 , Column : 27 } , Data : { } , TextEdits : [ { StartLine : 11 , StartColumn : 27 , EndLine : 11 , EndColumn : 27 , NewText : 'param1: ' } ] } ) ;
74+
75+ function assertInlayHintEqual ( actual : vscode . InlayHint , expected : InlayHint ) {
76+ assert . equal ( actual . label , expected . Label ) ;
77+ assert . equal ( actual . position . line , expected . Position . Line ) ;
78+ assert . equal ( actual . position . character , expected . Position . Column ) ;
79+
80+ if ( ! actual . textEdits ) {
81+ assert . isUndefined ( expected . TextEdits ) ;
82+ return ;
83+ }
84+
85+ assert . equal ( actual . textEdits . length , expected . TextEdits . length ) ;
86+ for ( let i = 0 ; i < actual . textEdits . length ; i ++ ) {
87+ const actualTextEdit = actual . textEdits [ i ] ;
88+ const expectedTextEdit = expected . TextEdits [ i ] ;
89+
90+ assertTextEditEqual ( actualTextEdit , expectedTextEdit ) ;
91+ }
92+ }
93+
94+ function assertTextEditEqual ( actual : vscode . TextEdit , expected : LinePositionSpanTextChange ) {
95+ assert . equal ( actual . range . start . line , expected . StartLine ) ;
96+ assert . equal ( actual . range . start . character , expected . StartColumn ) ;
97+ assert . equal ( actual . range . end . line , expected . EndLine ) ;
98+ assert . equal ( actual . range . end . character , expected . EndColumn ) ;
99+ assert . equal ( actual . newText , expected . NewText ) ;
76100 }
77101 } ) ;
78102} ) ;
0 commit comments