Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize completion #5066

Merged
merged 20 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
823cb99
optimize completion
Jun 1, 2018
c86ab75
cache UnresolvedSymbol
Jun 1, 2018
375abe7
more cancellable completion provider
vasily-kirichenko Jun 1, 2018
9b4c541
Merge remote-tracking branch 'origin/master' into optimize-completion
vasily-kirichenko Jun 2, 2018
15734b2
don't call isAttribute twice
vasily-kirichenko Jun 2, 2018
fc7b105
optimize IsExplicitlySuppressed, traverseMemberFunctionAndValues
vasily-kirichenko Jun 2, 2018
cab4150
cache ILTypeDef.CustomAttrs
vasily-kirichenko Jun 2, 2018
0fc55de
optimize IsExplicitlySuppressed
vasily-kirichenko Jun 2, 2018
c63e49d
avoid using Lazy to store custom attributes in ILTypeDef
vasily-kirichenko Jun 2, 2018
320f56c
CompletionProvider item's cache: replace dictionary with array
vasily-kirichenko Jun 2, 2018
1732849
provide fast generic comparer for bool values
vasily-kirichenko Jun 2, 2018
21f7fe6
make getKindPriority inline
vasily-kirichenko Jun 2, 2018
613fe0f
more defensive unresolvedSymbol
vasily-kirichenko Jun 2, 2018
205f5cf
Merge remote-tracking branch 'origin/master' into optimize-completion
vasily-kirichenko Jun 2, 2018
c4ef4ad
empty array singleton table
vasily-kirichenko Jun 2, 2018
a8051fe
faster IsOperatorName
vasily-kirichenko Jun 3, 2018
a3c6fba
optimize CompletionProvider
vasily-kirichenko Jun 3, 2018
0148fe9
Revert "empty array singleton table"
vasily-kirichenko Jun 3, 2018
7724011
Merge branch 'master' into optimize-completion
vasily-kirichenko Jun 4, 2018
fad5bdb
Merge remote-tracking branch 'origin/master' into optimize-completion
vasily-kirichenko Jun 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/fsharp/service/ServiceAssemblyContent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ type AssemblySymbol =
TopRequireQualifiedAccessParent: Idents option
AutoOpenParent: Idents option
Symbol: FSharpSymbol
Kind: LookupType -> EntityKind }
Kind: LookupType -> EntityKind
UnresolvedSymbol: UnresolvedSymbol }
override x.ToString() = sprintf "%A" x

type AssemblyPath = string
Expand Down Expand Up @@ -186,14 +187,30 @@ type IAssemblyContentCache =
module AssemblyContentProvider =
open System.IO

let private createEntity ns (parent: Parent) (entity: FSharpEntity) =
let unresolvedSymbol (topRequireQualifiedAccessParent: Idents option) (cleanedIdents: Idents) =
let getNamespace (idents: Idents) =
if idents.Length > 1 then Some idents.[..idents.Length - 2] else None

let ns =
topRequireQualifiedAccessParent
|> Option.bind getNamespace
|> Option.orElseWith (fun () -> getNamespace cleanedIdents)
|> Option.defaultValue [||]
cartermp marked this conversation as resolved.
Show resolved Hide resolved

let displayName = cleanedIdents |> Array.skip ns.Length |> String.concat "."
cartermp marked this conversation as resolved.
Show resolved Hide resolved

{ DisplayName = displayName
Namespace = ns }

let createEntity ns (parent: Parent) (entity: FSharpEntity) =
parent.FormatEntityFullName entity
|> Option.map (fun (fullName, cleanIdents) ->
let topRequireQualifiedAccessParent = parent.TopRequiresQualifiedAccess false |> Option.map parent.FixParentModuleSuffix
{ FullName = fullName
CleanedIdents = cleanIdents
Namespace = ns
NearestRequireQualifiedAccessParent = parent.ThisRequiresQualifiedAccess false |> Option.map parent.FixParentModuleSuffix
TopRequireQualifiedAccessParent = parent.TopRequiresQualifiedAccess false |> Option.map parent.FixParentModuleSuffix
TopRequireQualifiedAccessParent = topRequireQualifiedAccessParent
AutoOpenParent = parent.AutoOpen |> Option.map parent.FixParentModuleSuffix
Symbol = entity
Kind = fun lookupType ->
Expand All @@ -208,21 +225,25 @@ module AssemblyContentProvider =
match entity with
| Symbol.Attribute -> EntityKind.Attribute
| _ -> EntityKind.Type
UnresolvedSymbol = unresolvedSymbol topRequireQualifiedAccessParent cleanIdents
})

let private traverseMemberFunctionAndValues ns (parent: Parent) (membersFunctionsAndValues: seq<FSharpMemberOrFunctionOrValue>) =
let traverseMemberFunctionAndValues ns (parent: Parent) (membersFunctionsAndValues: seq<FSharpMemberOrFunctionOrValue>) =
membersFunctionsAndValues
|> Seq.filter (fun x -> not x.IsInstanceMember && not x.IsPropertyGetterMethod && not x.IsPropertySetterMethod)
|> Seq.collect (fun func ->
let processIdents fullName idents =
let topRequireQualifiedAccessParent = parent.TopRequiresQualifiedAccess true |> Option.map parent.FixParentModuleSuffix
cartermp marked this conversation as resolved.
Show resolved Hide resolved
let cleanedIdentes = parent.FixParentModuleSuffix idents
{ FullName = fullName
CleanedIdents = parent.FixParentModuleSuffix idents
CleanedIdents = cleanedIdentes
Namespace = ns
NearestRequireQualifiedAccessParent = parent.ThisRequiresQualifiedAccess true |> Option.map parent.FixParentModuleSuffix
TopRequireQualifiedAccessParent = parent.TopRequiresQualifiedAccess true |> Option.map parent.FixParentModuleSuffix
TopRequireQualifiedAccessParent = topRequireQualifiedAccessParent
AutoOpenParent = parent.AutoOpen |> Option.map parent.FixParentModuleSuffix
cartermp marked this conversation as resolved.
Show resolved Hide resolved
Symbol = func
Kind = fun _ -> EntityKind.FunctionOrValue func.IsActivePattern }
Kind = fun _ -> EntityKind.FunctionOrValue func.IsActivePattern
UnresolvedSymbol = unresolvedSymbol topRequireQualifiedAccessParent cleanedIdentes }

[ yield! func.TryGetFullDisplayName()
|> Option.map (fun fullDisplayName -> processIdents func.FullName (fullDisplayName.Split '.'))
Expand All @@ -241,7 +262,7 @@ module AssemblyContentProvider =
processIdents (fullCompiledIdents |> String.concat ".") fullCompiledIdents)
|> Option.toList ])

let rec private traverseEntity contentType (parent: Parent) (entity: FSharpEntity) =
cartermp marked this conversation as resolved.
Show resolved Hide resolved
let rec traverseEntity contentType (parent: Parent) (entity: FSharpEntity) =

seq {
#if !NO_EXTENSIONTYPING
Expand Down Expand Up @@ -308,7 +329,7 @@ module AssemblyContentProvider =
|> Seq.distinctBy (fun {FullName = fullName; CleanedIdents = cleanIdents} -> (fullName, cleanIdents))
|> Seq.toList

let private getAssemblySignaturesContent contentType (assemblies: FSharpAssembly list) =
cartermp marked this conversation as resolved.
Show resolved Hide resolved
let getAssemblySignaturesContent contentType (assemblies: FSharpAssembly list) =
assemblies |> List.collect (fun asm -> getAssemblySignatureContent contentType asm.Contents)

let getAssemblyContent (withCache: (IAssemblyContentCache -> _) -> _) contentType (fileName: string option) (assemblies: FSharpAssembly list) =
Expand Down
4 changes: 3 additions & 1 deletion src/fsharp/service/ServiceAssemblyContent.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ type public AssemblySymbol =
AutoOpenParent: Idents option
Symbol: FSharpSymbol
/// Function that returns `EntityKind` based of given `LookupKind`.
Kind: LookupType -> EntityKind }
Kind: LookupType -> EntityKind
/// Cache display name and namespace, used for completion.
UnresolvedSymbol: UnresolvedSymbol }

/// `RawEntity` list retrieved from an assembly.
type internal AssemblyContentCacheEntry =
Expand Down
16 changes: 10 additions & 6 deletions src/fsharp/service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ type FSharpDeclarationListItem(name: string, nameInCode: string, fullName: strin
/// A table of declarations for Intellisense completion
[<Sealed>]
type FSharpDeclarationListInfo(declarations: FSharpDeclarationListItem[], isForType: bool, isError: bool) =
static let fsharpNamespace = [|"Microsoft"; "FSharp"|]

member __.Items = declarations
member __.IsForType = isForType
member __.IsError = isError
Expand Down Expand Up @@ -650,22 +652,24 @@ type FSharpDeclarationListInfo(declarations: FSharpDeclarationListItem[], isForT
| Some _ -> displayName
| None -> Lexhelp.Keywords.QuoteIdentifierIfNeeded displayName

let isAttribute = SymbolHelpers.IsAttribute infoReader item.Item

let cutAttributeSuffix (name: string) =
if isAttributeApplicationContext && isAttribute && name <> "Attribute" && name.EndsWith "Attribute" then
cartermp marked this conversation as resolved.
Show resolved Hide resolved
if isAttributeApplicationContext && name <> "Attribute" && name.EndsWith "Attribute" && SymbolHelpers.IsAttribute infoReader item.Item then
name.[0..name.Length - "Attribute".Length - 1]
else name

let name = cutAttributeSuffix name
let nameInCode = cutAttributeSuffix nameInCode
let fullName = SymbolHelpers.FullNameOfItem g item.Item

let fullName =
match item.FullName with
| Some x -> x
| None -> SymbolHelpers.FullNameOfItem g item.Item

let namespaceToOpen =
item.Unresolved
|> Option.map (fun x -> x.Namespace)
|> Option.bind (fun ns ->
if ns |> Array.startsWith [|"Microsoft"; "FSharp"|] then None
if ns |> Array.startsWith fsharpNamespace then None
else Some ns)
|> Option.map (fun ns ->
match currentNamespaceOrModule with
Expand All @@ -676,7 +680,7 @@ type FSharpDeclarationListInfo(declarations: FSharpDeclarationListItem[], isForT
| None -> ns)
|> Option.bind (function
| [||] -> None
| ns -> Some (ns |> String.concat "."))
| ns -> Some (System.String.Join(".", ns)))
cartermp marked this conversation as resolved.
Show resolved Hide resolved

FSharpDeclarationListItem(
name, nameInCode, fullName, glyph, Choice1Of2 (items, infoReader, m, denv, reactor, checkAlive), getAccessibility item.Item,
Expand Down
23 changes: 5 additions & 18 deletions src/fsharp/service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -579,24 +579,10 @@ type TypeCheckInfo
| Item.Value _ -> CompletionItemKind.Field
| _ -> CompletionItemKind.Other

let getNamespace (idents: Idents) =
if idents.Length > 1 then Some idents.[..idents.Length - 2] else None

let unresolved =
unresolvedEntity
|> Option.map (fun x ->
let ns =
x.TopRequireQualifiedAccessParent
|> Option.bind getNamespace
|> Option.orElseWith (fun () -> getNamespace x.CleanedIdents)
|> Option.defaultValue [||]

let displayName = x.CleanedIdents |> Array.skip ns.Length |> String.concat "."

{ DisplayName = displayName
Namespace = ns })


{ ItemWithInst = item
{ FullName = unresolvedEntity |> Option.map (fun x -> x.FullName)
ItemWithInst = item
MinorPriority = 0
Kind = kind
IsOwnMember = false
Expand Down Expand Up @@ -859,7 +845,8 @@ type TypeCheckInfo
|> RemoveExplicitlySuppressed g
|> List.filter (fun item -> not (fields.Contains item.Item.DisplayName))
|> List.map (fun item ->
{ ItemWithInst = item
{ FullName = None
ItemWithInst = item
Kind = CompletionItemKind.Argument
MinorPriority = 0
IsOwnMember = false
Expand Down
8 changes: 5 additions & 3 deletions src/fsharp/symbols/SymbolHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ type UnresolvedSymbol =
Namespace: string[] }

type CompletionItem =
{ ItemWithInst: ItemWithInst
{ FullName: string option
ItemWithInst: ItemWithInst
Kind: CompletionItemKind
IsOwnMember: bool
MinorPriority: int
Expand Down Expand Up @@ -827,10 +828,11 @@ module internal SymbolHelpers =
| Item.Types(it, [ty]) ->
g.suppressed_types
|> List.exists (fun supp ->
if isAppTy g ty && isAppTy g (generalizedTyconRef supp) then
let generalizedSupp = generalizedTyconRef supp
if isAppTy g ty && isAppTy g generalizedSupp then
cartermp marked this conversation as resolved.
Show resolved Hide resolved
// check if they are the same logical type (after removing all abbreviations)
let tcr1 = tcrefOfAppTy g ty
let tcr2 = tcrefOfAppTy g (generalizedTyconRef supp)
let tcr2 = tcrefOfAppTy g generalizedSupp
tyconRefEq g tcr1 tcr2 &&
// check the display name is precisely the one we're suppressing
it = supp.DisplayName
Expand Down
5 changes: 3 additions & 2 deletions src/fsharp/symbols/SymbolHelpers.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ type public CompletionItemKind =
| Argument
| Other

type internal UnresolvedSymbol =
type UnresolvedSymbol =
{ DisplayName: string
Namespace: string[] }

type internal CompletionItem =
{ ItemWithInst: ItemWithInst
{ FullName: string option
ItemWithInst: ItemWithInst
Kind: CompletionItemKind
IsOwnMember: bool
MinorPriority: int
Expand Down