未验证 提交 43572a1e 编写于 作者: S Steffen Forkmann 提交者: GitHub

Cleanup FSharpCheckerResults (#9111)

上级 22bcd737
......@@ -147,8 +147,8 @@ type internal TypeCheckInfo
let getToolTipTextCache = AgedLookup<CompilationThreadToken, int*int*string, FSharpToolTipText<Layout>>(getToolTipTextSize,areSimilar=(fun (x,y) -> x = y))
let amap = tcImports.GetImportMap()
let infoReader = new InfoReader(g,amap)
let ncenv = new NameResolver(g,amap,infoReader,NameResolution.FakeInstantiationGenerator)
let infoReader = InfoReader(g,amap)
let ncenv = NameResolver(g,amap,infoReader,NameResolution.FakeInstantiationGenerator)
let cenv = SymbolEnv(g, thisCcu, Some ccuSigForFile, tcImports, amap, infoReader)
/// Find the most precise naming environment for the given line and column
......@@ -229,7 +229,8 @@ type internal TypeCheckInfo
NameResResult.TypecheckStaleAndTextChanged // typecheck is stale, wait for second-chance IntelliSense to bring up right result
else
NameResResult.Members (items, denv, m)
else NameResResult.Empty
else
NameResResult.Empty
let GetCapturedNameResolutions (endOfNamesPos: pos) resolveOverloads =
let filter (endPos: pos) items =
......@@ -274,7 +275,7 @@ type internal TypeCheckInfo
// then the expression typings get confused (thinking 'varA:int'), so we use name resolution even for usual values.
| CNR(Item.Value(vref), occurence, denv, nenv, ad, m)::_, Some _ ->
if (occurence = ItemOccurence.Binding || occurence = ItemOccurence.Pattern) then
if occurence = ItemOccurence.Binding || occurence = ItemOccurence.Pattern then
// Return empty list to stop further lookup - for value declarations
NameResResult.Cancel(denv, m)
else
......@@ -1035,9 +1036,8 @@ type internal TypeCheckInfo
| None -> []
| Some(loadClosure) ->
loadClosure.References
|> List.map snd
|> List.concat
|> List.filter(fun ar->isPosMatch(pos, ar.originalReference))
|> List.collect snd
|> List.filter(fun ar -> isPosMatch(pos, ar.originalReference))
match matches with
| resolved::_ // Take the first seen
......@@ -1551,23 +1551,26 @@ module internal ParseAndCheckFile =
// Join the sets and report errors.
// It is by-design that these messages are only present in the language service. A true build would report the errors at their
// spots in the individual source files.
for (fileOfHashLoad, rangesOfHashLoad) in hashLoadsInFile do
for (file, errorGroupedByFileName) in hashLoadBackgroundDiagnosticsGroupedByFileName do
for fileOfHashLoad, rangesOfHashLoad in hashLoadsInFile do
for file, errorGroupedByFileName in hashLoadBackgroundDiagnosticsGroupedByFileName do
if sameFile file fileOfHashLoad then
for rangeOfHashLoad in rangesOfHashLoad do // Handle the case of two #loads of the same file
let diagnostics = errorGroupedByFileName |> Array.map(fun (_,(pe,f)) -> pe.Exception,f) // Strip the build phase here. It will be replaced, in total, with TypeCheck
let errors = [ for (err,sev) in diagnostics do if sev = FSharpErrorSeverity.Error then yield err ]
let warnings = [ for (err,sev) in diagnostics do if sev = FSharpErrorSeverity.Warning then yield err ]
let errors = [ for err, sev in diagnostics do if sev = FSharpErrorSeverity.Error then yield err ]
let warnings = [ for err, sev in diagnostics do if sev = FSharpErrorSeverity.Warning then yield err ]
let message = HashLoadedSourceHasIssues(warnings,errors,rangeOfHashLoad)
if errors=[] then warning(message)
else errorR(message)
if isNil errors then
warning message
else
errorR message
// Replay other background errors.
for (phasedError,sev) in otherBackgroundDiagnostics do
for phasedError, sev in otherBackgroundDiagnostics do
if sev = FSharpErrorSeverity.Warning then
warning phasedError.Exception
else errorR phasedError.Exception
else
errorR phasedError.Exception
| None ->
// For non-scripts, check for disallow #r and #load.
......@@ -1615,7 +1618,7 @@ module internal ParseAndCheckFile =
errHandler.ErrorSeverityOptions <- tcConfig.errorSeverityOptions
// Play background errors and warnings for this file.
for (err,sev) in backgroundDiagnostics do
for err, sev in backgroundDiagnostics do
diagnosticSink (err, (sev = FSharpErrorSeverity.Error))
// If additional references were brought in by the preprocessor then we need to process them
......@@ -1738,7 +1741,7 @@ type FSharpCheckFileResults
member __.HasFullTypeCheckInfo = details.IsSome
member info.TryGetCurrentTcImports () =
member __.TryGetCurrentTcImports () =
match builderX with
| Some builder -> builder.TryGetCurrentTcImports ()
| _ -> None
......@@ -2065,8 +2068,8 @@ type FSharpCheckProjectResults
tcSymbolUses
|> Seq.collect (fun r -> r.GetUsesOfSymbol symbol.Item)
|> Seq.distinctBy (fun symbolUse -> symbolUse.ItemOccurence, symbolUse.Range)
|> Seq.filter (fun symbolUse -> symbolUse.ItemOccurence <> ItemOccurence.RelatedText)
|> Seq.filter (fun symbolUse -> symbolUse.ItemOccurence <> ItemOccurence.RelatedText)
|> Seq.distinctBy (fun symbolUse -> symbolUse.ItemOccurence, symbolUse.Range)
|> Seq.map (fun symbolUse -> FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range))
|> Seq.toArray
|> async.Return
......@@ -2077,18 +2080,18 @@ type FSharpCheckProjectResults
let cenv = SymbolEnv(tcGlobals, thisCcu, Some ccuSig, tcImports)
[| for r in tcSymbolUses do
for symbolUseChunk in r.AllUsesOfSymbols do
for symbolUseChunk in r.AllUsesOfSymbols do
for symbolUse in symbolUseChunk do
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
yield FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range) |]
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
yield FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range) |]
|> async.Return
member __.ProjectContext =
let (tcGlobals, tcImports, thisCcu, _ccuSig, _tcSymbolUses, _topAttribs, _tcAssemblyData, _ilAssemRef, ad, _tcAssemblyExpr, _dependencyFiles) = getDetails()
let assemblies =
[ for x in tcImports.GetImportedAssemblies() do
yield FSharpAssembly(tcGlobals, tcImports, x.FSharpViewOfMetadata) ]
tcImports.GetImportedAssemblies()
|> List.map (fun x -> FSharpAssembly(tcGlobals, tcImports, x.FSharpViewOfMetadata))
FSharpProjectContext(thisCcu, assemblies, ad)
member __.RawFSharpAssemblyData =
......@@ -2151,7 +2154,7 @@ type FsiInteractiveChecker(legacyReferenceResolver,
return
match tcFileInfo with
| Result.Ok tcFileInfo ->
let errors = [| yield! parseErrors; yield! tcErrors |]
let errors = Array.append parseErrors tcErrors
let typeCheckResults = FSharpCheckFileResults (filename, errors, Some tcFileInfo, dependencyFiles, None, reactorOps, false)
let projectResults =
FSharpCheckProjectResults (filename, Some tcConfig,
......
......@@ -857,11 +857,13 @@ module internal SymbolHelpers =
member x.GetHashCode item = hash item.Stamp }
/// Remove all duplicate items
let RemoveDuplicateItems g (items: ItemWithInst list) =
let RemoveDuplicateItems g (items: ItemWithInst list) =
if isNil items then items else
items |> IPartialEqualityComparer.partialDistinctBy (IPartialEqualityComparer.On (fun item -> item.Item) (ItemDisplayPartialEquality g))
/// Remove all duplicate items
let RemoveDuplicateCompletionItems g items =
let RemoveDuplicateCompletionItems g items =
if isNil items then items else
items |> IPartialEqualityComparer.partialDistinctBy (CompletionItemDisplayPartialEquality g)
let IsExplicitlySuppressed (g: TcGlobals) (item: Item) =
......@@ -886,12 +888,12 @@ module internal SymbolHelpers =
| _ -> false)
/// Filter types that are explicitly suppressed from the IntelliSense (such as uppercase "FSharpList", "Option", etc.)
let RemoveExplicitlySuppressed (g: TcGlobals) (items: ItemWithInst list) =
items |> List.filter (fun item -> not (IsExplicitlySuppressed g item.Item))
let RemoveExplicitlySuppressed (g: TcGlobals) (items: ItemWithInst list) =
items |> List.filter (fun item -> not (IsExplicitlySuppressed g item.Item))
/// Filter types that are explicitly suppressed from the IntelliSense (such as uppercase "FSharpList", "Option", etc.)
let RemoveExplicitlySuppressedCompletionItems (g: TcGlobals) (items: CompletionItem list) =
items |> List.filter (fun item -> not (IsExplicitlySuppressed g item.Item))
items |> List.filter (fun item -> not (IsExplicitlySuppressed g item.Item))
let SimplerDisplayEnv denv =
{ denv with suppressInlineKeyword=true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册