Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextDocumentSignatureHelp throws IndexOutOfRangeException #1040

Closed
oskarskog opened this issue Nov 14, 2022 · 4 comments · Fixed by #1067
Closed

TextDocumentSignatureHelp throws IndexOutOfRangeException #1040

oskarskog opened this issue Nov 14, 2022 · 4 comments · Fixed by #1067
Labels

Comments

@oskarskog
Copy link

oskarskog commented Nov 14, 2022

I'm seeing a lot of these in my Neovim :messages, happens after I open a file and move the cursor around for a bit.

RPC[Error] code_name = InternalError, message = "System.IndexOutOfRangeException: Index was outside the bounds of the array.\
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@248.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 248\
   at Microsoft.FSharp.Core.OptionModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpOption`1 option) in D:\\a\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\option.fs:line 53\
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@215.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 224\
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\\a\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\async.fs:line 447\
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.FsAutoComplete-Lsp-IFSharpLspServer-TextDocumentSignatureHelp@1890-3.Invoke(AsyncActivation`1 ctxt)\
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\async.fs:line 139"

Edit: I'm on 0.58.2

@vain0x
Copy link
Contributor

vain0x commented Feb 27, 2023

Repro

Let Program.fs be:

().ToString(

)

Put the cursor on the second empty line and press ,.

Request is:

[Trace - 23:45:49] Sending request 'textDocument/signatureHelp - (137)'.
Params: {
    "textDocument": {
        "uri": "file:///home/owner/repo/fs-playground/Program.fs"
    },
    "position": {
        "line": 1,
        "character": 1
    },
    "context": {
        "isRetrigger": false,
        "triggerCharacter": ",",
        "triggerKind": 2
    }
}

Response is:

[23:45:49.052 ERR] [FsAutoComplete.Lsp.AdaptiveFSharpLspServer] TextDocumentSignatureHelp Request: {"TextDocument": {"Uri": "file:///home/owner/repo/fs-playground/Program.fs", "$type": "TextDocumentIdentifier"}, "Position": {"Line": 1, "Character": 1, "$type": "Position"}, "Context": {"Value": {"TriggerKind": "TriggerCharacter", "TriggerCharacter": {"Value": ",", "$type": "Some"}, "IsRetrigger": false, "ActiveSignatureHelp": null, "$type": "SignatureHelpContext"}, "$type": "Some"}, "$type": "SignatureHelpParams"}
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.String.get_Chars(Int32 index)
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@248.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 248
   at Microsoft.FSharp.Core.OptionModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpOption`1 option) in D:\a\_work\1\s\src\FSharp.Core\option.fs:line 98
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@214.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 223
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at FsToolkit.ErrorHandling.AsyncResult.zip@198-8.Invoke(AsyncActivation`1 ctxt)
   at FsToolkit.ErrorHandling.Async.zip@25-3.Invoke(AsyncActivation`1 ctxt)
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.FsAutoComplete-Lsp-IFSharpLspServer-TextDocumentSignatureHelp@2434-9.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
[Trace - 23:45:49] Received response 'textDocument/signatureHelp - (137)' in 3ms. Request failed: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.String.get_Chars(Int32 index)
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@248.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 248
   at Microsoft.FSharp.Core.OptionModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpOption`1 option) in D:\a\_work\1\s\src\FSharp.Core\option.fs:line 98
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@214.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 223
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at FsToolkit.ErrorHandling.AsyncResult.zip@198-8.Invoke(AsyncActivation`1 ctxt)
   at FsToolkit.ErrorHandling.Async.zip@25-3.Invoke(AsyncActivation`1 ctxt)
   at <StartupCode$fsautocomplete>.$AdaptiveFSharpLspServer.FsAutoComplete-Lsp-IFSharpLspServer-TextDocumentSignatureHelp@2434-9.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 (-32603).

Machine infos

  • Operating system: Linux
  • Arch: x64
  • VSCode: 1.75.1
  • UI Kind: Desktop
  • Ionide: 7.5.1
  • Runtime: netcore
  • Dotnet version: 7.0.200

Cause

Remarks:

  • PrevPos probably needs to skip empty lines in a loop to find the previous character
  • Column - 1 and mkPos (..) 0 in NextPos, and pos.Column = 0 in TryGetChar are suspicious since a column number should start with 1 here (I don't find any case to cause an actual error)

EDIT: Link fixed

@baronfel
Copy link
Contributor

Excellent diagnosis - would you be interested in contributing a test + fix for this?

@baronfel baronfel added the bug label Feb 27, 2023
@vain0x
Copy link
Contributor

vain0x commented Feb 27, 2023

Yes, I would like to try.

@baronfel
Copy link
Contributor

baronfel commented Feb 27, 2023

I'd start by adding a test to SignatureHelpTests and debug that with dotnet run --filter "<fully qualified test name>" with the scenario you've provided above. Let me know if that doesn't work and we can look at other approaches!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants