未验证 提交 1f27dcdc 编写于 作者: E Eugene Auduchinok 提交者: GitHub

Don't check isFunction for every captured type, don't store end pos (#8791)

* Get expr type: don't check isFunction for every types

* Don't store end pos in captured expression types

* Cleanup
上级 8331d821
......@@ -1446,7 +1446,7 @@ type FormatStringCheckContext =
/// An abstract type for reporting the results of name resolution and type checking.
type ITypecheckResultsSink =
abstract NotifyEnvWithScope: range * NameResolutionEnv * AccessorDomain -> unit
abstract NotifyExprHasType: pos * TType * NameResolutionEnv * AccessorDomain * range -> unit
abstract NotifyExprHasType: TType * NameResolutionEnv * AccessorDomain * range -> unit
abstract NotifyNameResolution: pos * item: Item * TyparInst * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit
abstract NotifyMethodGroupNameResolution : pos * item: Item * itemMethodGroup: Item * TyparInst * ItemOccurence * NameResolutionEnv * AccessorDomain * range * replace: bool -> unit
abstract NotifyFormatSpecifierLocation: range * int -> unit
......@@ -1674,7 +1674,7 @@ type CapturedNameResolution(i: Item, tpinst, io: ItemOccurence, nre: NameResolut
/// Represents container for all name resolutions that were met so far when typechecking some particular file
type TcResolutions
(capturedEnvs: ResizeArray<range * NameResolutionEnv * AccessorDomain>,
capturedExprTypes: ResizeArray<pos * TType * NameResolutionEnv * AccessorDomain * range>,
capturedExprTypes: ResizeArray<TType * NameResolutionEnv * AccessorDomain * range>,
capturedNameResolutions: ResizeArray<CapturedNameResolution>,
capturedMethodGroupResolutions: ResizeArray<CapturedNameResolution>) =
......@@ -1805,9 +1805,9 @@ type TcResultsSinkImpl(g, ?sourceText: ISourceText) =
if allowedRange m then
capturedEnvs.Add((m, nenv, ad))
member sink.NotifyExprHasType(endPos, ty, nenv, ad, m) =
member sink.NotifyExprHasType(ty, nenv, ad, m) =
if allowedRange m then
capturedExprTypings.Add((endPos, ty, nenv, ad, m))
capturedExprTypings.Add((ty, nenv, ad, m))
member sink.NotifyNameResolution(endPos, item, tpinst, occurenceType, nenv, ad, m, replace) =
if allowedRange m then
......@@ -1880,7 +1880,7 @@ let CallNameResolutionSinkReplacing (sink: TcResultsSink) (m: range, nenv, item,
let CallExprHasTypeSink (sink: TcResultsSink) (m: range, nenv, ty, ad) =
match sink.CurrentSink with
| None -> ()
| Some sink -> sink.NotifyExprHasType(m.End, ty, nenv, ad, m)
| Some sink -> sink.NotifyExprHasType(ty, nenv, ad, m)
let CallOpenDeclarationSink (sink: TcResultsSink) (openDeclaration: OpenDeclaration) =
match sink.CurrentSink with
......
......@@ -338,7 +338,7 @@ type internal TcResolutions =
/// Information of exact types found for expressions, that can be to the left of a dot.
/// typ - the inferred type for an expression
member CapturedExpressionTypings : ResizeArray<pos * TType * NameResolutionEnv * AccessorDomain * range>
member CapturedExpressionTypings : ResizeArray<TType * NameResolutionEnv * AccessorDomain * range>
/// Exact name resolutions
member CapturedNameResolutions : ResizeArray<CapturedNameResolution>
......@@ -409,7 +409,7 @@ type ITypecheckResultsSink =
abstract NotifyEnvWithScope : range * NameResolutionEnv * AccessorDomain -> unit
/// Record that an expression has a specific type at the given range.
abstract NotifyExprHasType : pos * TType * NameResolutionEnv * AccessorDomain * range -> unit
abstract NotifyExprHasType : TType * NameResolutionEnv * AccessorDomain * range -> unit
/// Record that a name resolution occurred at a specific location in the source
abstract NotifyNameResolution : pos * Item * TyparInst * ItemOccurence * NameResolutionEnv * AccessorDomain * range * bool -> unit
......
......@@ -1880,7 +1880,7 @@ let MakeAndPublishSimpleValsForMergedScope cenv env m (names: NameMap<_>) =
member this.NotifyMethodGroupNameResolution(pos, item, itemGroup, itemTyparInst, occurence, nenv, ad, m, replacing) =
notifyNameResolution (pos, item, itemGroup, itemTyparInst, occurence, nenv, ad, m, replacing)
member this.NotifyExprHasType(_, _, _, _, _) = assert false // no expr typings in MakeAndPublishSimpleVals
member this.NotifyExprHasType(_, _, _, _) = assert false // no expr typings in MakeAndPublishSimpleVals
member this.NotifyFormatSpecifierLocation(_, _) = ()
member this.NotifyOpenDeclaration(_) = ()
member this.CurrentSourceText = None
......
......@@ -364,21 +364,21 @@ type internal TypeCheckInfo
let GetExprTypingForPosition(endOfExprPos) =
let quals =
sResolutions.CapturedExpressionTypings
|> Seq.filter (fun (pos,ty,nenv,_,_) ->
|> Seq.filter (fun (ty,nenv,_,m) ->
// We only want expression types that end at the particular position in the file we are looking at.
let isLocationWeCareAbout = posEq pos endOfExprPos
posEq m.End endOfExprPos &&
// Get rid of function types. True, given a 2-arg curried function "f x y", it is legal to do "(f x).GetType()",
// but you almost never want to do this in practice, and we choose not to offer up any intellisense for
// F# function types.
let isFunction = isFunTy nenv.DisplayEnv.g ty
isLocationWeCareAbout && not isFunction)
not (isFunTy nenv.DisplayEnv.g ty))
|> Seq.toArray
let thereWereSomeQuals = not (Array.isEmpty quals)
// filter out errors
let quals = quals
|> Array.filter (fun (_,ty,nenv,_,_) ->
|> Array.filter (fun (ty,nenv,_,_) ->
let denv = nenv.DisplayEnv
not (isTyparTy denv.g ty && (destTyparTy denv.g ty).IsFromError))
thereWereSomeQuals, quals
......@@ -391,11 +391,11 @@ type internal TypeCheckInfo
match quals with
| [||] -> None
| quals ->
quals |> Array.tryFind (fun (_,_,_,_,rq) ->
quals |> Array.tryFind (fun (_,_,_,rq) ->
ignore(r) // for breakpoint
posEq r.Start rq.Start)
match bestQual with
| Some (_,ty,nenv,ad,m) when isRecdTy nenv.DisplayEnv.g ty ->
| Some (ty,nenv,ad,m) when isRecdTy nenv.DisplayEnv.g ty ->
let items = NameResolution.ResolveRecordOrClassFieldsOfType ncenv m ad ty false
Some (items, nenv.DisplayEnv, m)
| _ -> None
......@@ -426,7 +426,7 @@ type internal TypeCheckInfo
// If not, then the stale typecheck info does not have a capturedExpressionTyping for this exact expression, and the
// user can wait for typechecking to catch up and second-chance intellisense to give the right result.
let qual =
quals |> Array.tryFind (fun (_,_,_,_,r) ->
quals |> Array.tryFind (fun (_,_,_,r) ->
ignore(r) // for breakpoint
posEq exprRange.Start r.Start)
qual, false
......@@ -439,7 +439,7 @@ type internal TypeCheckInfo
match bestQual with
| Some bestQual ->
let (_,ty,nenv,ad,m) = bestQual
let (ty,nenv,ad,m) = bestQual
let items = ResolveCompletionsInType ncenv nenv (ResolveCompletionTargets.All(ConstraintSolver.IsApplicableMethApprox g amap m)) m ad false ty
let items = items |> List.map ItemWithNoInst
let items = items |> RemoveDuplicateItems g
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册