ionide / FsAutoComplete

F# language server using Language Server Protocol
Other
409 stars 154 forks source link

`Index was outside the bounds of the array.` in SignatureHelp.getSignatureHelpFor #950

Closed kojo12228 closed 2 years ago

kojo12228 commented 2 years ago

In PmaBolero, I was seeing VSCode crash after about 10-30 minutes of coding 5 or 6 times yesterday. Taking a look at the logs, I was seeing a lot of:

[18:31:13.402 ERR] [LSP] PositionHandler - Failed during child operation on file <path_omitted>\PmaBolero\src\PmaBolero.Client\Pages\Main.fs
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@213.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 213
   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.loop@231-22(NamedText lines, Char ch, Position pos) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 232
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@230.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 240
   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-Core>.$CompilerServiceInterface.ParseAndCheckFileInProject@340-11.Invoke(AsyncActivation`1 ctxt) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/CompilerServiceInterface.fs:line 340
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
[Error - 18:31:33] Request textDocument/documentHighlight failed.
  Message: No symbol information found
  Code: -32603 
[Error - 18:31:35] Request textDocument/documentHighlight failed.
  Message: No symbol information found
  Code: -32603 
[18:32:21.624 ERR] [LSP] PositionHandler - Failed during child operation on file <path_omitted>\PmaBolero\src\PmaBolero.Client\Pages\Main.fs
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@213.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 213
   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.loop@231-22(NamedText lines, Char ch, Position pos) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 232
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@230.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 240
   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-Core>.$CompilerServiceInterface.ParseAndCheckFileInProject@340-11.Invoke(AsyncActivation`1 ctxt) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/CompilerServiceInterface.fs:line 340
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
[Error - 18:32:21] Request textDocument/signatureHelp failed.
  Message: Index was outside the bounds of the array.
  Code: -32603 
[18:33:03.450 ERR] [LSP] PositionHandler - Failed during child operation on file <path_omitted>\PmaBolero\src\PmaBolero.Client\Pages\Main.fs
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at <StartupCode$FsAutoComplete-Core>.$FileSystem.TryGetPrevChar@213.Invoke(Position np) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/FileSystem.fs:line 213
   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.loop@231-22(NamedText lines, Char ch, Position pos) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 232
   at FsAutoComplete.SignatureHelp.getSignatureHelpFor@230.Invoke(Unit unitVar) in /home/runner/work/FsAutoComplete/FsAutoComplete/src/FsAutoComplete.Core/SignatureHelp.fs:line 240
   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 Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
[Error - 18:33:03] Request textDocument/signatureHelp failed.
  Message: Index was outside the bounds of the array.
  Code: -32603 
[Error - 18:33:17] Request textDocument/signatureHelp failed.
  Message: Index was outside the bounds of the array.
  Code: -32603

Before each crash, the final log in exthost.log would be something akin to:

[2022-06-03 19:10:16.944] [exthost] [info] Extension host terminating: renderer closed the socket
[2022-06-03 19:10:17.019] [exthost] [warning] {"name":"Canceled"}
[2022-06-03 19:10:17.019] [exthost] [warning] {"name":"Canceled"}
[2022-06-03 19:10:17.020] [exthost] [warning] {"name":"Canceled"}
[2022-06-03 19:10:17.066] [exthost] [info] Extension host with pid 11316 exiting with code 0

The exception occurred for various files in PmaBolero\src\PmaBolero.Client\Pages that I was editing yesterday.

I've been able to reproduce the error (by taking a look at the logs) in other repos, but far less frequently and it didn't cause VSCode to crash.

WillEhrendreich commented 2 years ago

I'm seeing this from time to time too, in Neovim on windows, and I'm completely unsure what it's even referring to.

baronfel commented 2 years ago

I believe @Booksbaum has fixed this in one of his more recent contributions, but we haven't released a version of FSAC that contains it yet. I'm busy the next few days with personal things, but I'm hoping to release it over the weekend.

juergenhoetzel commented 2 years ago

Same issue in Emacs eglot-fsharp CI tests:

https://github.com/fsharp/emacs-fsharp-mode/issues/316

Can't reproduce this on my i9 desktop setup. The tests fail reproducibly on an i3 Intel NUC: Seems to be a timing/race-condition.

Booksbaum commented 2 years ago

I believe @Booksbaum has fixed this in one of his more recent contributions, but we haven't released a version of FSAC that contains it yet.

fsharp/FsAutoComplete#947 -- which is already in current FSAC & ionide

But this here is a similar issue: Again line comparison of FCS Position with 0 instead of 1:
https://github.com/fsharp/FsAutoComplete/blob/9f58993f9630c8250a9558c60e5ece817c2ccb52/src/FsAutoComplete.Core/FileSystem.fs#L230

I'll submit a PR later today