@@ -2616,6 +2616,80 @@ type LspServerTests () =
26162616 try shutdown client with _ -> ()
26172617 LspClient.stop client
26182618
2619+ [<Test>]
2620+ member _. ``Hover returns inferred type for local lambda variables`` () =
2621+ let client = LspClient.start ()
2622+ try
2623+ initialize client
2624+
2625+ let uri = " file:///tmp/hover-local-variables-test.fss"
2626+ let source =
2627+ " let rec fib n = if n < 2 then n else fib (n - 1) + fib (n - 2)\n "
2628+ + " let values =\n "
2629+ + " [0..9]\n "
2630+ + " |> List.map (fun i ->\n "
2631+ + " i |> fib |> fun x ->\n "
2632+ + " $\" {x}\" )\n "
2633+
2634+ let td = JsonObject()
2635+ td[ " uri" ] <- JsonValue.Create( uri)
2636+ td[ " languageId" ] <- JsonValue.Create( " fscript" )
2637+ td[ " version" ] <- JsonValue.Create( 1 )
2638+ td[ " text" ] <- JsonValue.Create( source)
2639+
2640+ let didOpenParams = JsonObject()
2641+ didOpenParams[ " textDocument" ] <- td
2642+ LspClient.sendNotification client " textDocument/didOpen" ( Some didOpenParams)
2643+
2644+ LspClient.readUntil client 10000 ( fun msg ->
2645+ match msg[ " method" ] with
2646+ | :? JsonValue as mv ->
2647+ try mv.GetValue< string>() = " textDocument/publishDiagnostics" with _ -> false
2648+ | _ -> false )
2649+ |> ignore
2650+
2651+ let requestHover ( requestId : int ) ( line : int ) ( character : int ) =
2652+ let hoverParams = JsonObject()
2653+ let textDocument = JsonObject()
2654+ textDocument[ " uri" ] <- JsonValue.Create( uri)
2655+ let position = JsonObject()
2656+ position[ " line" ] <- JsonValue.Create( line)
2657+ position[ " character" ] <- JsonValue.Create( character)
2658+ hoverParams[ " textDocument" ] <- textDocument
2659+ hoverParams[ " position" ] <- position
2660+ LspClient.sendRequest client requestId " textDocument/hover" ( Some hoverParams)
2661+ LspClient.readUntil client 10000 ( fun msg ->
2662+ match msg[ " id" ] with
2663+ | :? JsonValue as idv ->
2664+ try idv.GetValue< int>() = requestId with _ -> false
2665+ | _ -> false )
2666+
2667+ let hoverText ( resp : JsonNode ) =
2668+ match resp[ " result" ] with
2669+ | :? JsonObject as result ->
2670+ match result[ " contents" ] with
2671+ | :? JsonObject as contents ->
2672+ match contents[ " value" ] with
2673+ | :? JsonValue as value -> value.GetValue< string>()
2674+ | _ -> " "
2675+ | _ -> " "
2676+ | _ -> " "
2677+
2678+ let hasLocalHoverType ( text : string ) ( name : string ) ( typeText : string ) =
2679+ text.Contains( $" {name} : {typeText}" , StringComparison.Ordinal)
2680+ && text.Contains( " local-variable" , StringComparison.Ordinal)
2681+
2682+ let hoverI = requestHover 41 3 21
2683+ let hoverX = requestHover 42 4 24
2684+ let hoverIText = hoverText hoverI
2685+ let hoverXText = hoverText hoverX
2686+
2687+ Assert.That( hasLocalHoverType hoverIText " i" " int" , Is.True, $" Unexpected hover for i: {hoverIText}" )
2688+ Assert.That( hasLocalHoverType hoverXText " x" " int" , Is.True, $" Unexpected hover for x: {hoverXText}" )
2689+ finally
2690+ try shutdown client with _ -> ()
2691+ LspClient.stop client
2692+
26192693 [<Test>]
26202694 member _. ``Rename returns workspace edit for all symbol occurrences`` () =
26212695 let client = LspClient.start ()
0 commit comments