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

Filter type test completion list #12930

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/fsharp/service/ServiceParseTreeWalk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ module SyntaxTraversal =

| SynExpr.Match (expr=synExpr; clauses=synMatchClauseList) ->
[yield dive synExpr synExpr.Range traverseSynExpr
yield! synMatchClauseList |> List.map (fun x -> dive x x.RangeOfGuardAndRhs (traverseSynMatchClause path))]
yield! synMatchClauseList |> List.map (fun x -> dive x x.Range (traverseSynMatchClause path))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why RangeOfGuardAndRhs was used here. MatchLambda and TryWith traversals use Range, so this change seemed appropriate. Without it VisitPat is never fired in a match clause pattern, and so we don't get a chance to create the right completion context.

|> pick expr

| SynExpr.Do (synExpr, _range) -> traverseSynExpr synExpr
Expand Down Expand Up @@ -632,7 +632,8 @@ module SyntaxTraversal =
let path = SyntaxNode.SynPat p :: origPath
match p with
| SynPat.Paren (p, _) -> traversePat path p
| SynPat.Or (p1, p2, _, _) -> [ p1; p2] |> List.tryPick (traversePat path)
| SynPat.As (p1, p2, _)
Copy link
Contributor Author

@kerams kerams Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked like an omission. I don't see why we wouldn't want to dive into both subpatterns here. Without it VisitPat is not fired for IsInst when the type test is paired with an as (which it very often is).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely agree with this logic

| SynPat.Or (p1, p2, _, _) -> [ p1; p2 ] |> List.tryPick (traversePat path)
| SynPat.Ands (ps, _)
| SynPat.Tuple (_, ps, _)
| SynPat.ArrayOrList (_, ps, _) -> ps |> List.tryPick (traversePat path)
Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/service/ServiceParsedInputOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,12 @@ module ParsedInput =
None
| _ -> None)

member _.VisitPat (_, defaultTraverse, pat) =
match pat with
| SynPat.IsInst (_, range) when rangeContainsPos range pos ->
Some CompletionContext.PatternType
| _ -> defaultTraverse pat

member _.VisitModuleDecl(_path, defaultTraverse, decl) =
match decl with
| SynModuleDecl.Open(target, m) ->
Expand Down
19 changes: 19 additions & 0 deletions vsintegration/tests/UnitTests/CompletionProviderTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,25 @@ let _ = fun (p:l) -> ()
"""
VerifyCompletionList(fileContents, "let _ = fun (p:l", ["LanguagePrimitives"; "List"], ["let"; "log"])

[<Test>]
let ``Completions in match clause type test contain modules and types but not keywords or functions``() =
let fileContents = """
match box 5 with
| :? l as x -> ()
| _ -> ()
"""
VerifyCompletionList(fileContents, ":? l", ["LanguagePrimitives"; "List"], ["let"; "log"])

[<Test>]
let ``Completions in catch clause type test contain modules and types but not keywords or functions``() =
let fileContents = """
try
()
with :? l as x ->
()
"""
VerifyCompletionList(fileContents, ":? l", ["LanguagePrimitives"; "List"], ["let"; "log"])

[<Test>]
let ``Extensions.Bug5162``() =
let fileContents = """
Expand Down