Skip to content

Commit

Permalink
Add test and fix signature off-by-one (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoogendoorn authored May 14, 2021
1 parent 5bf4bc0 commit 98afac0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/ParseAndCheckResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ type ParseAndCheckResults
}

member __.TryGetToolTip (pos: Pos) (lineStr: LineStr) =
match Lexer.findLongIdents(pos.Column - 1, lineStr) with
match Lexer.findLongIdents(pos.Column, lineStr) with
| None -> ResultOrString.Error "Cannot find ident for tooltip"
| Some(col,identIsland) ->
let identIsland = Array.toList identIsland
Expand Down
54 changes: 54 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,57 @@ let analyzerTests state =
do! server.Shutdown()
})
]

let signatureTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Signature")
let scriptPath = Path.Combine(path, "Script.fsx")
let! (server, events) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing events
do! server.TextDocumentDidOpen { TextDocument = loadDocument scriptPath }
match! waitForParseResultsForFile "Script.fsx" events with
| Ok () ->
() // all good, no parsing/checking errors
| Core.Result.Error errors ->
failtestf "Errors while parsing script %s: %A" scriptPath errors

return server, scriptPath
}
|> Async.Cache

let verifySignature line (characterStart, characterEnd) expectedSignature =
let verifyAt character = async {
let! server, scriptPath = server
let pos: TextDocumentPositionParams = {
TextDocument = { Uri = Path.FilePathToUri scriptPath }
Position = { Line = line; Character = character }
}
match! server.FSharpSignature pos with
| Ok { Content = content } ->
let r = JsonSerializer.readJson<CommandResponse.ResponseMsg<string>>(content)
Expect.equal r.Kind "typesig" "Should have a kind of 'typesig'"
Expect.equal r.Data expectedSignature (sprintf "Should have a signature of '%s' at character %d" expectedSignature character)
| Result.Error errors ->
failtestf "Error while getting signature: %A" errors
}

testCaseAsync (sprintf "fsharp/signature for line %d characters [%d, %d] should be '%s'" line characterStart characterEnd expectedSignature) (
[ for c in characterStart .. characterEnd -> verifyAt c ]
|> Async.Sequential
|> Async.map (fun _ -> ())
)

testSequenced <|
testList "signature evaluation" [
testList "tests" [
verifySignature 0 (4, 16) "val arrayOfTuples : (int * int) []"
verifySignature 1 (4, 15) "val listOfTuples : (int * int) list"
verifySignature 2 (4, 15) "val someFunction : a:'a -> unit"
]
testCaseAsync "cleanup" (async {
let! server, _ = server
do! server.Shutdown()
})
]

1 change: 1 addition & 0 deletions test/FsAutoComplete.Tests.Lsp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let tests =
// fake isn't updated to FCS 39, disabling tests until that's resolved
//fakeInteropTests toolsPath
analyzerTests state
signatureTests state
SignatureHelp.tests state
CodeFixTests.tests state
Completion.tests state
Expand Down
3 changes: 3 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/TestCases/Signature/Script.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let arrayOfTuples = [| 1, 2 |]
let listOfTuples = [ 1, 2 ]
let someFunction a = ()

0 comments on commit 98afac0

Please sign in to comment.