ionide / ionide-vscode-fsharp

VS Code plugin for F# development
http://ionide.io
MIT License
858 stars 277 forks source link

Tooltip failing on type aliases #1947

Open jcmrva opened 11 months ago

jcmrva commented 11 months ago

Describe the bug

Tooltip sometimes does not appear, accompanied by errors in the output. It may be a coincidence, but I only see it on Giraffe's HttpHandler, HttpFunc, etc.

[08:07:46.233 ERR] [FsAutoComplete.Lsp.AdaptiveFSharpLspServer] TextDocumentHover Request Errored {"TextDocument": {"Uri": "file:///c%3A/code/my-project/my-code.fs", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 29, "Character": 23, "$type": "Position"}, "$type": "TextDocumentPositionParams"}
System.InvalidOperationException: not a named type
   at <StartupCode$FSharp-Compiler-Service>.$Symbols.get_TypeDefinition@2486.Invoke(Unit unitVar0) in D:\a\_work\1\s\src\Compiler\Symbols\Symbols.fs:line 2493
   at FSharp.Compiler.Symbols.Impl.protect[a](FSharpFunc`2 f) in D:\a\_work\1\s\src\Compiler\Symbols\Symbols.fs:line 79
   at FsAutoComplete.TypedAstExtensionHelpers.FSharpSymbol.GetAbbreviatedParent(FSharpSymbol) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/TypedAstUtils.fs:line 235
   at FsAutoComplete.ParseAndCheckResults.TryGetToolTipEnhanced(Position pos, String lineStr) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/ParseAndCheckResults.fs:line 391
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.FsAutoComplete-Lsp-IFSharpLspServer-TextDocumentHover@2831-19.Invoke(FSharpResult`2 input) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs:line 2834
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.clo@1098-116.Invoke(AsyncActivation`1 ctxt)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 148
[Error - 8:07:46 AM] Request textDocument/hover failed.
  Message: System.InvalidOperationException: not a named type
   at <StartupCode$FSharp-Compiler-Service>.$Symbols.get_TypeDefinition@2486.Invoke(Unit unitVar0) in D:\a\_work\1\s\src\Compiler\Symbols\Symbols.fs:line 2493
   at FSharp.Compiler.Symbols.Impl.protect[a](FSharpFunc`2 f) in D:\a\_work\1\s\src\Compiler\Symbols\Symbols.fs:line 79
   at FsAutoComplete.TypedAstExtensionHelpers.FSharpSymbol.GetAbbreviatedParent(FSharpSymbol) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/TypedAstUtils.fs:line 235
   at FsAutoComplete.ParseAndCheckResults.TryGetToolTipEnhanced(Position pos, String lineStr) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/ParseAndCheckResults.fs:line 391
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.FsAutoComplete-Lsp-IFSharpLspServer-TextDocumentHover@2831-19.Invoke(FSharpResult`2 input) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs:line 2834
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.clo@1098-116.Invoke(AsyncActivation`1 ctxt)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 148
  Code: -32603

This part stood out: "Position": {"Line": 29, "Character": 23, "$type": "Position"}

In that example, HttpHandler is at line 30, cols 22-33.

Code navigation also seems to fail (initially) with [10:10:14.892 WRN] [ParseAndCheckResults] Got a declresult of (28,9--28,20) that doesn't exist but after 30 seconds or so, the source panel appeared.

Steps to reproduce

Try getting tooltips in your own Giraffe project?

Expected behaviour

Tooltip appears as normal.

Machine info

TheAngryByrd commented 11 months ago

I'm guessing this is because HttpHandler and HttpFunc are aliases.

Looks to be failing here. Since this error is coming in the compiler itself, this might be something that has to bubble up the F# repo unless we're using it wrong. cc @vzarytovskii

jcmrva commented 11 months ago

Good call, I'm able to repro here:

type StringChange = string -> string

let makeEmpty : StringChange =
    fun _ -> ""