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;
@@ -23,10 +26,11 @@ fn test_inlay_hint_default_config() {
2326
2427 interaction. client . did_open ( "inlay_hint_test.py" ) ;
2528
26- interaction
27- . client
28- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
29- . expect_response ( json ! ( [
29+ expect_inlay_hint_response (
30+ interaction
31+ . client
32+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
33+ json ! ( [
3034 {
3135 "label" : [
3236 { "value" : " -> " } ,
@@ -85,7 +89,8 @@ fn test_inlay_hint_default_config() {
8589 "range" : { "end" : { "character" : 15 , "line" : 14 } , "start" : { "character" : 15 , "line" : 14 } }
8690 } ]
8791 }
88- ] ) ) ;
92+ ] ) ,
93+ ) ;
8994
9095 interaction. shutdown ( ) ;
9196}
@@ -167,10 +172,11 @@ fn test_inlay_hint_disable_variables() {
167172
168173 interaction. client . did_open ( "inlay_hint_test.py" ) ;
169174
170- interaction
171- . client
172- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
173- . expect_response ( json ! ( [ {
175+ expect_inlay_hint_response (
176+ interaction
177+ . client
178+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
179+ json ! ( [ {
174180 "label" : [
175181 { "value" : " -> " } ,
176182 { "value" : "tuple" } ,
@@ -205,7 +211,8 @@ fn test_inlay_hint_disable_variables() {
205211 "newText" : " -> Literal[0]" ,
206212 "range" : { "end" : { "character" : 15 , "line" : 14 } , "start" : { "character" : 15 , "line" : 14 } }
207213 } ]
208- } ] ) ) ;
214+ } ] ) ,
215+ ) ;
209216
210217 interaction. shutdown ( ) ;
211218}
@@ -228,10 +235,11 @@ fn test_inlay_hint_disable_returns() {
228235
229236 interaction. client . did_open ( "inlay_hint_test.py" ) ;
230237
231- interaction
232- . client
233- . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 )
234- . expect_response ( json ! ( [ {
238+ expect_inlay_hint_response (
239+ interaction
240+ . client
241+ . inlay_hint ( "inlay_hint_test.py" , 0 , 0 , 100 , 0 ) ,
242+ json ! ( [ {
235243 "label" : [
236244 { "value" : ": " } ,
237245 { "value" : "tuple" } ,
@@ -252,7 +260,8 @@ fn test_inlay_hint_disable_returns() {
252260 "newText" : ": tuple[Literal[1], Literal[2]]" ,
253261 "range" : { "end" : { "character" : 6 , "line" : 11 } , "start" : { "character" : 6 , "line" : 11 } }
254262 } ]
255- } ] ) ) ;
263+ } ] ) ,
264+ ) ;
256265
257266 interaction. shutdown ( ) ;
258267}
@@ -307,3 +316,33 @@ fn test_inlay_hint_labels_support_goto_type_definition() {
307316
308317 interaction. shutdown ( ) ;
309318}
319+
320+ fn expect_inlay_hint_response (
321+ handle : ClientRequestHandle < ' _ , InlayHintRequest > ,
322+ expected : Value ,
323+ ) {
324+ let mut expected = expected;
325+ strip_inlay_hint_locations ( & mut expected) ;
326+ handle. expect_response_with ( move |result| {
327+ let mut actual_json = serde_json:: to_value ( & result) . unwrap ( ) ;
328+ strip_inlay_hint_locations ( & mut actual_json) ;
329+ actual_json == expected
330+ } ) ;
331+ }
332+
333+ fn strip_inlay_hint_locations ( value : & mut Value ) {
334+ match value {
335+ Value :: Object ( map) => {
336+ map. remove ( "location" ) ;
337+ for inner in map. values_mut ( ) {
338+ strip_inlay_hint_locations ( inner) ;
339+ }
340+ }
341+ Value :: Array ( items) => {
342+ for item in items {
343+ strip_inlay_hint_locations ( item) ;
344+ }
345+ }
346+ _ => { }
347+ }
348+ }
0 commit comments