From 16ab4ebac60e838fc5c586fa80762a81b1b9b242 Mon Sep 17 00:00:00 2001 From: vain0x Date: Thu, 2 Mar 2023 22:44:08 +0900 Subject: [PATCH] Fix signatureHelp IndexOutOfRangeException issue (#1040) --- src/FsAutoComplete.Core/FileSystem.fs | 7 ++++++- test/FsAutoComplete.Tests.Lsp/SignatureHelpTests.fs | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/FsAutoComplete.Core/FileSystem.fs b/src/FsAutoComplete.Core/FileSystem.fs index 0159ed758..5f4f48690 100644 --- a/src/FsAutoComplete.Core/FileSystem.fs +++ b/src/FsAutoComplete.Core/FileSystem.fs @@ -245,7 +245,12 @@ type NamedText(fileName: string, str: string) = member x.TryGetPrevChar(pos: FSharp.Compiler.Text.Position) : (FSharp.Compiler.Text.Position * char) option = option { let! np = x.PrevPos pos - return np, x.GetCharUnsafe np + let! prevLineLength = x.GetLineLength(np) + + if np.Column < 1 || prevLineLength < np.Column then + return! x.TryGetPrevChar(np) + else + return np, x.GetCharUnsafe np } /// split the TotalRange of this document at the range specified. diff --git a/test/FsAutoComplete.Tests.Lsp/SignatureHelpTests.fs b/test/FsAutoComplete.Tests.Lsp/SignatureHelpTests.fs index 2a51c01ad..8f54bd1f1 100644 --- a/test/FsAutoComplete.Tests.Lsp/SignatureHelpTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/SignatureHelpTests.fs @@ -199,7 +199,11 @@ let issuesTests server = Expect.equal sigText "val count: x: int -> int" - "Should have no backticks because signatures are only ever rendered in `code` form") ] + "Should have no backticks because signatures are only ever rendered in `code` form") + testCaseAsync "issue #1040" // IndexOutOfRangeException + <| testSignatureHelp server "().ToString(\n\n,$0\n)" Manual (fun sigs -> + Expect.isSome sigs "Should have sigs" + ) ] let tests state = serverTestList "signature help" state defaultConfigDto None (fun server ->