Skip to content

Commit 3c7f59e

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Custom operations are at the top of completion list & remove active pattern values from the list (#4831)
* custom operations are at the top of completion list * do not pick rhs NameResolutionEnvironment in completion if it corresponds to a computation expression * Revert "do not pick rhs NameResolutionEnvironment in completion if it corresponds to a computation expression" This reverts commit 4548ca2ea2fb730f9b896462bd00745621e3b245. * fix after merge * put active patterns (as functions) to the very end of completion list * filter out active patterns-as-value from completion list * Revert "put active patterns (as functions) to the very end of completion list" This reverts commit c26b24cc4a730bb0f741b73f39cc4601b7810127.
1 parent 1af4f56 commit 3c7f59e

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

src/fsharp/service/ServiceDeclarationLists.fs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,15 +615,23 @@ type FSharpDeclarationListInfo(declarations: FSharpDeclarationListItem[], isForT
615615
| None -> item.Item.DisplayName
616616
name, items)
617617

618-
// Filter out operators (and list)
618+
// Filter out operators, active patterns (as values) and the empty list
619619
let items =
620620
// Check whether this item looks like an operator.
621621
let isOperatorItem(name, items: CompletionItem list) =
622622
match items |> List.map (fun x -> x.Item) with
623623
| [Item.Value _ | Item.MethodGroup _ | Item.UnionCase _] -> IsOperatorName name
624624
| _ -> false
625-
let isFSharpList name = (name = "[]") // list shows up as a Type and a UnionCase, only such entity with a symbolic name, but want to filter out of intellisense
626-
items |> List.filter (fun (displayName, items) -> not (isOperatorItem(displayName, items)) && not (isFSharpList displayName))
625+
626+
let isActivePatternItem (items: CompletionItem list) =
627+
match items |> List.map (fun x -> x.Item) with
628+
| [Item.Value vref] -> IsActivePatternName vref.CompiledName
629+
| _ -> false
630+
631+
items |> List.filter (fun (displayName, items) ->
632+
not (isOperatorItem(displayName, items)) &&
633+
not (displayName = "[]") && // list shows up as a Type and a UnionCase, only such entity with a symbolic name, but want to filter out of intellisense
634+
not (isActivePatternItem items))
627635

628636
let decls =
629637
items

src/fsharp/service/service.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ type TypeCheckInfo
577577
| Item.Event _ -> CompletionItemKind.Event
578578
| Item.ILField _
579579
| Item.Value _ -> CompletionItemKind.Field
580+
| Item.CustomOperation _ -> CompletionItemKind.CustomOperation
580581
| _ -> CompletionItemKind.Other
581582

582583
{ ItemWithInst = item

src/fsharp/symbols/SymbolHelpers.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ type CompletionItemKind =
275275
| Method of isExtension : bool
276276
| Event
277277
| Argument
278+
| CustomOperation
278279
| Other
279280

280281
type UnresolvedSymbol =

src/fsharp/symbols/SymbolHelpers.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type public CompletionItemKind =
113113
| Method of isExtension : bool
114114
| Event
115115
| Argument
116+
| CustomOperation
116117
| Other
117118

118119
type UnresolvedSymbol =

vsintegration/src/FSharp.Editor/Completion/CompletionUtils.fs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ module internal CompletionUtils =
102102

103103
let inline getKindPriority kind =
104104
match kind with
105-
| CompletionItemKind.Property -> 0
106-
| CompletionItemKind.Field -> 1
107-
| CompletionItemKind.Method (isExtension = false) -> 2
108-
| CompletionItemKind.Event -> 3
109-
| CompletionItemKind.Argument -> 4
110-
| CompletionItemKind.Other -> 5
111-
| CompletionItemKind.Method (isExtension = true) -> 6
105+
| CompletionItemKind.CustomOperation -> 0
106+
| CompletionItemKind.Property -> 1
107+
| CompletionItemKind.Field -> 2
108+
| CompletionItemKind.Method (isExtension = false) -> 3
109+
| CompletionItemKind.Event -> 4
110+
| CompletionItemKind.Argument -> 5
111+
| CompletionItemKind.Other -> 6
112+
| CompletionItemKind.Method (isExtension = true) -> 7

vsintegration/tests/UnitTests/CompletionProviderTests.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,20 @@ module M2 =
603603
"""
604604
VerifyCompletionList(fileContents, " Ext", ["Extensions"; "ExtraTopLevelOperators"], [])
605605

606+
[<Test>]
607+
let ``Custom operations should be at the top of completion list inside computation expression``() =
608+
let fileContents = """
609+
let joinLocal = 1
610+
611+
let _ =
612+
query {
613+
for i in 1..10 do
614+
select i
615+
join
616+
}
617+
"""
618+
VerifyCompletionList(fileContents, " join", ["groupJoin"; "join"; "leftOuterJoin"; "joinLocal"], [])
619+
606620
#if EXE
607621
ShouldDisplaySystemNamespace()
608622
#endif

0 commit comments

Comments
 (0)