未验证 提交 2c43ded9 编写于 作者: K kerams 提交者: GitHub

Reuse some default values in FCS (#13035)

上级 bdee5ba9
......@@ -1246,7 +1246,7 @@ type internal TypeCheckInfo
loadClosure.PackageReferences
|> Array.tryFind (fun (m, _) -> rangeContainsPos m pos)
match matches with
| None -> ToolTipText.ToolTipText []
| None -> emptyToolTip
| Some (_, lines) ->
let lines = lines |> List.filter (fun line -> not (line.StartsWith("//")) && not (String.IsNullOrEmpty line))
ToolTipText.ToolTipText
......@@ -1283,7 +1283,7 @@ type internal TypeCheckInfo
ResolveOverloads.Yes, None, (fun() -> []))
match declItemsOpt with
| None -> ToolTipText []
| None -> emptyToolTip
| Some(items, denv, _, m) ->
ToolTipText(items |> List.map (fun x -> FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst)))
......@@ -1976,6 +1976,8 @@ type FSharpCheckFileResults
| None -> dflt()
| Some (scope, _builderOpt) -> f scope
static let emptyFindDeclResult = FindDeclResult.DeclNotFound (FindDeclFailureReason.Unknown "")
member _.Diagnostics = errors
member _.HasFullTypeCheckInfo = details.IsSome
......@@ -1998,19 +2000,18 @@ type FSharpCheckFileResults
/// Resolve the names at the given location to give a data tip
member _.GetToolTip(line, colAtEndOfNames, lineText, names, tokenTag) =
let dflt = ToolTipText []
match tokenTagToTokenId tokenTag with
| TOKEN_IDENT ->
threadSafeOp (fun () -> dflt) (fun scope ->
threadSafeOp (fun () -> emptyToolTip) (fun scope ->
scope.GetStructuredToolTipText(line, lineText, colAtEndOfNames, names))
| TOKEN_STRING | TOKEN_STRING_TEXT ->
threadSafeOp (fun () -> dflt) (fun scope ->
threadSafeOp (fun () -> emptyToolTip) (fun scope ->
scope.GetReferenceResolutionStructuredToolTipText(line, colAtEndOfNames) )
| _ ->
dflt
emptyToolTip
member _.GetDescription(symbol: FSharpSymbol, inst: (FSharpGenericParameter * FSharpType) list, displayFullName, range: range) =
threadSafeOp (fun () -> ToolTipText []) (fun scope ->
threadSafeOp (fun () -> emptyToolTip) (fun scope ->
scope.GetDescription(symbol, inst, displayFullName, range))
member _.GetF1Keyword (line, colAtEndOfNames, lineText, names) =
......@@ -2019,13 +2020,11 @@ type FSharpCheckFileResults
// Resolve the names at the given location to a set of methods
member _.GetMethods(line, colAtEndOfNames, lineText, names) =
let dflt = MethodGroup("",[| |])
threadSafeOp (fun () -> dflt) (fun scope ->
threadSafeOp (fun () -> MethodGroup.Empty) (fun scope ->
scope.GetMethods (line, lineText, colAtEndOfNames, names))
member _.GetDeclarationLocation (line, colAtEndOfNames, lineText, names, ?preferFlag) =
let dflt = FindDeclResult.DeclNotFound (FindDeclFailureReason.Unknown "")
threadSafeOp (fun () -> dflt) (fun scope ->
threadSafeOp (fun () -> emptyFindDeclResult) (fun scope ->
scope.GetDeclarationLocation (line, lineText, colAtEndOfNames, names, preferFlag))
member _.GetSymbolUseAtLocation (line, colAtEndOfNames, lineText, names) =
......
......@@ -59,7 +59,7 @@ type ToolTipElement =
/// Information for building a data tip box.
type ToolTipText =
/// A list of data tip elements to display.
| ToolTipText of ToolTipElement list
| ToolTipText of ToolTipElement list
[<RequireQualifiedAccess>]
type CompletionItemKind =
......@@ -87,7 +87,9 @@ type CompletionItem =
[<AutoOpen>]
module DeclarationListHelpers =
let mutable ToolTipFault = None
let mutable ToolTipFault = None
let emptyToolTip = ToolTipText []
/// Generate the structured tooltip for a method info
let FormatOverloadsToList (infoReader: InfoReader) m denv (item: ItemWithInst) minfos : ToolTipElement =
......@@ -942,6 +944,8 @@ type DeclarationListItem(textInDeclList: string, textInCode: string, fullName: s
type DeclarationListInfo(declarations: DeclarationListItem[], isForType: bool, isError: bool) =
static let fsharpNamespace = [|"Microsoft"; "FSharp"|]
static let empty = DeclarationListInfo ([| |], false, false)
// Check whether this item looks like an operator.
static let isOperatorItem name (items: CompletionItem list) =
match items with
......@@ -1088,7 +1092,7 @@ type DeclarationListInfo(declarations: DeclarationListItem[], isForType: bool, i
[| DeclarationListItem("<Note>", "<Note>", "<Note>", FSharpGlyph.Error, Choice2Of2 (ToolTipText [ToolTipElement.CompositionError message]),
FSharpAccessibility(taccessPublic), CompletionItemKind.Other, false, 0, false, None) |], false, true)
static member Empty = DeclarationListInfo([| |], false, false)
static member Empty = empty
......@@ -1134,6 +1138,8 @@ type MethodGroup( name: string, unsortedMethods: MethodGroupItem[] ) =
static let methodOverloadsCache = System.Runtime.CompilerServices.ConditionalWeakTable<ItemWithInst, MethodGroupItem[]>()
#endif
static let empty = MethodGroup ("", [| |])
let methods =
unsortedMethods
// Methods with zero arguments show up here as taking a single argument of type 'unit'. Patch them now to appear as having zero arguments.
......@@ -1154,7 +1160,7 @@ type MethodGroup( name: string, unsortedMethods: MethodGroupItem[] ) =
static member Create (infoReader: InfoReader, ad, m, denv, items:ItemWithInst list) =
let g = infoReader.g
if isNil items then MethodGroup("", [| |]) else
if isNil items then empty else
let name = items.Head.Item.DisplayName
let methods =
......@@ -1210,5 +1216,5 @@ type MethodGroup( name: string, unsortedMethods: MethodGroupItem[] ) =
MethodGroup(name, methods)
static member internal Empty = empty
......@@ -51,7 +51,7 @@ type public ToolTipElement =
type public ToolTipText =
/// A list of data tip elements to display.
| ToolTipText of ToolTipElement list
| ToolTipText of ToolTipElement list
[<RequireQualifiedAccess>]
type public CompletionItemKind =
......@@ -209,6 +209,8 @@ type public MethodGroup =
static member internal Create: InfoReader * AccessorDomain * range * DisplayEnv * ItemWithInst list -> MethodGroup
static member internal Empty: MethodGroup
module internal DeclarationListHelpers =
val FormatStructuredDescriptionOfItem: isDecl:bool -> InfoReader -> AccessorDomain -> range -> DisplayEnv -> ItemWithInst -> ToolTipElement
......@@ -218,3 +220,5 @@ module internal DeclarationListHelpers =
val mutable ToolTipFault: string option
val emptyToolTip: ToolTipText
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册