@@ -89,13 +89,33 @@ module TcResolutionsExtensions =
8989 | _ -> None
9090 | _ -> None
9191
92+ // Custome builders like 'async { }' are both Item.Value and Item.CustomBuilder.
93+ // We should prefer the latter, otherwise they would not get classified as CEs.
94+ let takeCustomBuilder ( cnrs : CapturedNameResolution []) =
95+ assert ( cnrs.Length > 0 )
96+ if cnrs.Length = 1 then
97+ cnrs
98+ elif cnrs.Length = 2 then
99+ match cnrs.[ 0 ]. Item, cnrs.[ 1 ]. Item with
100+ | Item.Value _, Item.CustomBuilder _ ->
101+ [| cnrs.[ 1 ] |]
102+ | Item.CustomBuilder _, Item.Value _ ->
103+ [| cnrs.[ 0 ] |]
104+ | _ ->
105+ cnrs
106+ else
107+ cnrs
108+
92109 let resolutions =
93110 match range with
94111 | Some range ->
95- sResolutions.CapturedNameResolutions
96- |> Seq.filter ( fun cnr -> rangeContainsPos range cnr.Range.Start || rangeContainsPos range cnr.Range.End)
112+ sResolutions.CapturedNameResolutions.ToArray()
113+ |> Array.filter ( fun cnr -> rangeContainsPos range cnr.Range.Start || rangeContainsPos range cnr.Range.End)
114+ |> Array.groupBy ( fun cnr -> cnr.Range)
115+ |> Array.map ( fun ( _ , cnrs ) -> takeCustomBuilder cnrs)
116+ |> Array.concat
97117 | None ->
98- sResolutions.CapturedNameResolutions :> seq <_>
118+ sResolutions.CapturedNameResolutions.ToArray ()
99119
100120 let isDisposableTy ( ty : TType ) =
101121 not ( typeEquiv g ty g.system_ IDisposable_ ty) &&
@@ -129,11 +149,11 @@ module TcResolutionsExtensions =
129149 let inline add m typ =
130150 if duplicates.Add m then
131151 results.Add struct ( m, typ)
152+
132153 resolutions
133- |> Seq.iter ( fun cnr ->
134- match cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.NameResolutionEnv, cnr.AccessorDomain, cnr.Range with
135- // 'seq' in 'seq { ... }' gets colored as keywords
136- | ( Item.Value vref), ItemOccurence.Use, _, _, _, m when valRefEq g g.seq_ vref vref ->
154+ |> Array.iter ( fun cnr ->
155+ match cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.NameResolutionEnv, cnr.AccessorDomain, cnr.Range with
156+ | ( Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m ->
137157 add m SemanticClassificationType.ComputationExpression
138158
139159 | ( Item.Value vref), _, _, _, _, m when isValRefMutable vref ->
@@ -208,9 +228,6 @@ module TcResolutionsExtensions =
208228 else
209229 add m SemanticClassificationType.Method
210230
211- | ( Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m ->
212- add m SemanticClassificationType.ComputationExpression
213-
214231 // Special case measures for struct types
215232 | Item.Types(_, TType_ app( tyconRef, TType_ measure _ :: _) :: _), LegitTypeOccurence, _, _, _, m when isStructTyconRef tyconRef ->
216233 add m SemanticClassificationType.ValueType
0 commit comments