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

Add test and fix signature off-by-one #782

Merged
merged 2 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,50 @@ let analyzerTests state =
do! server.Shutdown()
})
]

let signatureTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Tooltips")
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 character expectedSignature =
testCaseAsync (sprintf "fsharp/signature for line %d character %d should be '%s'" line character expectedSignature) (async {
let! server, scriptPath = server
let pos: TextDocumentPositionParams = {
TextDocument = { Uri = sprintf "file://%s" scriptPath }
baronfel marked this conversation as resolved.
Show resolved Hide resolved
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'" expectedSignature)
| Result.Error errors ->
failtestf "Error while getting signature: %A" errors
})

testSequenced <|
testList "signature evaluation" [
testList "tests" [
verifySignature 0 4 "val arrayOfTuples : (int * int) []" // verify that even first letter of the signature triggers correctly
baronfel marked this conversation as resolved.
Show resolved Hide resolved
verifySignature 0 5 "val arrayOfTuples : (int * int) []"
]
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