From af4f617a217969839426cc6f1d1f735665dfa4d0 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 2 Apr 2022 13:32:09 +0200 Subject: [PATCH] Filter type test completion list --- src/fsharp/service/ServiceParseTreeWalk.fs | 5 +++-- src/fsharp/service/ServiceParsedInputOps.fs | 6 ++++++ .../UnitTests/CompletionProviderTests.fs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/fsharp/service/ServiceParseTreeWalk.fs b/src/fsharp/service/ServiceParseTreeWalk.fs index c736c4543a8..d34b5cf36fe 100755 --- a/src/fsharp/service/ServiceParseTreeWalk.fs +++ b/src/fsharp/service/ServiceParseTreeWalk.fs @@ -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))] |> pick expr | SynExpr.Do (synExpr, _range) -> traverseSynExpr synExpr @@ -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, _) + | SynPat.Or (p1, p2, _, _) -> [ p1; p2 ] |> List.tryPick (traversePat path) | SynPat.Ands (ps, _) | SynPat.Tuple (_, ps, _) | SynPat.ArrayOrList (_, ps, _) -> ps |> List.tryPick (traversePat path) diff --git a/src/fsharp/service/ServiceParsedInputOps.fs b/src/fsharp/service/ServiceParsedInputOps.fs index 1dc3c049dbe..c4ca1c925ad 100644 --- a/src/fsharp/service/ServiceParsedInputOps.fs +++ b/src/fsharp/service/ServiceParsedInputOps.fs @@ -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) -> diff --git a/vsintegration/tests/UnitTests/CompletionProviderTests.fs b/vsintegration/tests/UnitTests/CompletionProviderTests.fs index 9d9a60eecd1..528ce6eeac8 100644 --- a/vsintegration/tests/UnitTests/CompletionProviderTests.fs +++ b/vsintegration/tests/UnitTests/CompletionProviderTests.fs @@ -647,6 +647,25 @@ let _ = fun (p:l) -> () """ VerifyCompletionList(fileContents, "let _ = fun (p:l", ["LanguagePrimitives"; "List"], ["let"; "log"]) +[] +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"]) + +[] +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"]) + [] let ``Extensions.Bug5162``() = let fileContents = """