55 * LICENSE file in the root directory of this source tree.
66 */
77
8+ use lsp_types:: request:: InlayHintRequest ;
89use serde_json:: json;
10+ use serde_json:: Value ;
911
12+ use crate :: test:: lsp:: lsp_interaction:: object_model:: ClientRequestHandle ;
1013use crate :: test:: lsp:: lsp_interaction:: object_model:: InitializeSettings ;
1114use crate :: test:: lsp:: lsp_interaction:: object_model:: LspInteraction ;
1215use crate :: test:: lsp:: lsp_interaction:: util:: get_test_files_root;
@@ -25,10 +28,11 @@ fn test_inlay_hint_default_config() {
2528
2629 interaction. client . did_open ( "inlay_hint_test.py" ) ;
2730
28- interaction
29- . client
30- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
31- . expect_response ( json ! ( [
31+ expect_inlay_hint_response (
32+ interaction
33+ . client
34+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
35+ json ! ( [
3236 {
3337 "label" : [
3438 { "value" : " -> " } ,
@@ -87,7 +91,8 @@ fn test_inlay_hint_default_config() {
8791 "range" : { "end" : { "character" : 15 , "line" : 14 } , "start" : { "character" : 15 , "line" : 14 } }
8892 } ]
8993 }
90- ] ) )
94+ ] ) ,
95+ )
9196 . unwrap ( ) ;
9297
9398 interaction. shutdown ( ) . unwrap ( ) ;
@@ -178,10 +183,11 @@ fn test_inlay_hint_disable_variables() {
178183
179184 interaction. client . did_open ( "inlay_hint_test.py" ) ;
180185
181- interaction
182- . client
183- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
184- . expect_response ( json ! ( [ {
186+ expect_inlay_hint_response (
187+ interaction
188+ . client
189+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
190+ json ! ( [ {
185191 "label" : [
186192 { "value" : " -> " } ,
187193 { "value" : "tuple" } ,
@@ -216,7 +222,8 @@ fn test_inlay_hint_disable_variables() {
216222 "newText" : " -> Literal[0]" ,
217223 "range" : { "end" : { "character" : 15 , "line" : 14 } , "start" : { "character" : 15 , "line" : 14 } }
218224 } ]
219- } ] ) )
225+ } ] ) ,
226+ )
220227 . unwrap ( ) ;
221228
222229 interaction. shutdown ( ) . unwrap ( ) ;
@@ -242,10 +249,11 @@ fn test_inlay_hint_disable_returns() {
242249
243250 interaction. client . did_open ( "inlay_hint_test.py" ) ;
244251
245- interaction
246- . client
247- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
248- . expect_response ( json ! ( [ {
252+ expect_inlay_hint_response (
253+ interaction
254+ . client
255+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
256+ json ! ( [ {
249257 "label" : [
250258 { "value" : ": " } ,
251259 { "value" : "tuple" } ,
@@ -266,7 +274,8 @@ fn test_inlay_hint_disable_returns() {
266274 "newText" : ": tuple[Literal[1], Literal[2]]" ,
267275 "range" : { "end" : { "character" : 6 , "line" : 11 } , "start" : { "character" : 6 , "line" : 11 } }
268276 } ]
269- } ] ) )
277+ } ] ) ,
278+ )
270279 . unwrap ( ) ;
271280
272281 interaction. shutdown ( ) . unwrap ( ) ;
@@ -325,3 +334,33 @@ fn test_inlay_hint_labels_support_goto_type_definition() {
325334
326335 interaction. shutdown ( ) . unwrap ( ) ;
327336}
337+
338+ fn expect_inlay_hint_response (
339+ handle : ClientRequestHandle < ' _ , InlayHintRequest > ,
340+ expected : Value ,
341+ ) {
342+ let mut expected = expected;
343+ strip_inlay_hint_locations ( & mut expected) ;
344+ handle. expect_response_with ( move |result| {
345+ let mut actual_json = serde_json:: to_value ( & result) . unwrap ( ) ;
346+ strip_inlay_hint_locations ( & mut actual_json) ;
347+ actual_json == expected
348+ } ) ;
349+ }
350+
351+ fn strip_inlay_hint_locations ( value : & mut Value ) {
352+ match value {
353+ Value :: Object ( map) => {
354+ map. remove ( "location" ) ;
355+ for inner in map. values_mut ( ) {
356+ strip_inlay_hint_locations ( inner) ;
357+ }
358+ }
359+ Value :: Array ( items) => {
360+ for item in items {
361+ strip_inlay_hint_locations ( item) ;
362+ }
363+ }
364+ _ => { }
365+ }
366+ }
0 commit comments