Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 22 additions & 10 deletions src/fsharp/service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,11 @@ type TypeCheckInfo
scope.IsRelativeNameResolvable(cursorPos, plid, symbol.Item)

/// Get the auto-complete items at a location
member __.GetDeclarations (ctok, parseResultsOpt, line, lineStr, partialName, getAllSymbols, hasTextChangedSinceLastTypecheck) =
member __.GetDeclarations (ctok, parseResultsOpt, line, lineStr, partialName, getAllEntities, hasTextChangedSinceLastTypecheck) =
let isInterfaceFile = SourceFileImpl.IsInterfaceFile mainInputFileName
ErrorScope.Protect Range.range0
(fun () ->
match GetDeclItemsForNamesAtPosition(ctok, parseResultsOpt, Some partialName.QualifyingIdents, Some partialName.PartialIdent, partialName.LastDotPos, line, lineStr, partialName.EndColumn + 1, ResolveTypeNamesToCtors, ResolveOverloads.Yes, getAllSymbols, hasTextChangedSinceLastTypecheck) with
match GetDeclItemsForNamesAtPosition(ctok, parseResultsOpt, Some partialName.QualifyingIdents, Some partialName.PartialIdent, partialName.LastDotPos, line, lineStr, partialName.EndColumn + 1, ResolveTypeNamesToCtors, ResolveOverloads.Yes, getAllEntities, hasTextChangedSinceLastTypecheck) with
| None -> FSharpDeclarationListInfo.Empty
| Some (items, denv, ctx, m) ->
let items = if isInterfaceFile then items |> List.filter (fun x -> IsValidSignatureFileItem x.Item) else items
Expand All @@ -950,11 +950,11 @@ type TypeCheckInfo
FSharpDeclarationListInfo.Error msg)

/// Get the symbols for auto-complete items at a location
member __.GetDeclarationListSymbols (ctok, parseResultsOpt, line, lineStr, partialName, hasTextChangedSinceLastTypecheck) =
member __.GetDeclarationListSymbols (ctok, parseResultsOpt, line, lineStr, partialName, getAllEntities, hasTextChangedSinceLastTypecheck) =
let isInterfaceFile = SourceFileImpl.IsInterfaceFile mainInputFileName
ErrorScope.Protect Range.range0
(fun () ->
match GetDeclItemsForNamesAtPosition(ctok, parseResultsOpt, Some partialName.QualifyingIdents, Some partialName.PartialIdent, partialName.LastDotPos, line, lineStr, partialName.EndColumn + 1, ResolveTypeNamesToCtors, ResolveOverloads.Yes, (fun () -> []), hasTextChangedSinceLastTypecheck) with
match GetDeclItemsForNamesAtPosition(ctok, parseResultsOpt, Some partialName.QualifyingIdents, Some partialName.PartialIdent, partialName.LastDotPos, line, lineStr, partialName.EndColumn + 1, ResolveTypeNamesToCtors, ResolveOverloads.Yes, getAllEntities, hasTextChangedSinceLastTypecheck) with
| None -> List.Empty
| Some (items, denv, _, m) ->
let items = if isInterfaceFile then items |> List.filter (fun x -> IsValidSignatureFileItem x.Item) else items
Expand All @@ -966,7 +966,7 @@ type TypeCheckInfo
// - show types with fewer generic parameters first
// - show types before over other related items - they usually have very useful XmlDocs
let items =
items |> List.sortBy (fun d ->
items |> List.sortBy (fun d ->
let n =
match d.Item with
| Item.Types (_,(TType_app(tcref,_) :: _)) -> 1 + tcref.TyparsNoRange.Length
Expand All @@ -981,8 +981,18 @@ type TypeCheckInfo
// Remove all duplicates. We've put the types first, so this removes the DelegateCtor and DefaultStructCtor's.
let items = items |> RemoveDuplicateCompletionItems g

// Group by display name
let items = items |> List.groupBy (fun d -> d.Item.DisplayName)
// Group by compiled name for types, display name for functions
// (We don't want types with the same display name to be grouped as overloads)
let items =
items |> List.groupBy (fun d ->
match d.Item with
| Item.Types (_,(TType_app(tcref,_) :: _))
| Item.ExnCase tcref -> tcref.LogicalName
| Item.UnqualifiedType(tcref :: _)
| Item.FakeInterfaceCtor (TType_app(tcref,_))
| Item.DelegateCtor (TType_app(tcref,_)) -> tcref.CompiledName
| Item.CtorGroup (_, (cinfo :: _)) -> (tcrefOfAppTy g cinfo.EnclosingType).CompiledName
| _ -> d.Item.DisplayName)

// Filter out operators (and list)
let items =
Expand Down Expand Up @@ -1919,16 +1929,18 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
member info.HasFullTypeCheckInfo = details.IsSome

/// Intellisense autocompletions
member info.GetDeclarationListInfo(parseResultsOpt, line, lineStr, partialName, getAllEntities, ?hasTextChangedSinceLastTypecheck, ?userOpName: string) =
member info.GetDeclarationListInfo(parseResultsOpt, line, lineStr, partialName, ?getAllEntities, ?hasTextChangedSinceLastTypecheck, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
let getAllEntities = defaultArg getAllEntities (fun() -> [])
let hasTextChangedSinceLastTypecheck = defaultArg hasTextChangedSinceLastTypecheck (fun _ -> false)
reactorOp userOpName "GetDeclarations" FSharpDeclarationListInfo.Empty (fun ctok scope ->
scope.GetDeclarations(ctok, parseResultsOpt, line, lineStr, partialName, getAllEntities, hasTextChangedSinceLastTypecheck))

member info.GetDeclarationListSymbols(parseResultsOpt, line, lineStr, partialName, ?hasTextChangedSinceLastTypecheck, ?userOpName: string) =
member info.GetDeclarationListSymbols(parseResultsOpt, line, lineStr, partialName, ?getAllEntities, ?hasTextChangedSinceLastTypecheck, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
let hasTextChangedSinceLastTypecheck = defaultArg hasTextChangedSinceLastTypecheck (fun _ -> false)
reactorOp userOpName "GetDeclarationListSymbols" List.empty (fun ctok scope -> scope.GetDeclarationListSymbols(ctok, parseResultsOpt, line, lineStr, partialName, hasTextChangedSinceLastTypecheck))
let getAllEntities = defaultArg getAllEntities (fun() -> [])
reactorOp userOpName "GetDeclarationListSymbols" List.empty (fun ctok scope -> scope.GetDeclarationListSymbols(ctok, parseResultsOpt, line, lineStr, partialName, getAllEntities, hasTextChangedSinceLastTypecheck))

/// Resolve the names at the given location to give a data tip
member info.GetStructuredToolTipText(line, colAtEndOfNames, lineStr, names, tokenTag, ?userOpName: string) =
Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/service/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ type public FSharpCheckFileResults =
/// The text of the line where the completion is happening. This is only used to make a couple
/// of adhoc corrections to completion accuracy (e.g. checking for "..")
/// </param>
/// <param name="getAllSymbols">
/// Function that returns all symbols from current and referenced assemblies.
/// <param name="getAllEntities">
/// Function that returns all entities from current and referenced assemblies.
/// </param>
/// <param name="hasTextChangedSinceLastTypecheck">
/// If text has been used from a captured name resolution from the typecheck, then
/// callback to the client to check if the text has changed. If it has, then give up
/// and assume that we're going to repeat the operation later on.
/// </param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member GetDeclarationListInfo : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * getAllSymbols: (unit -> AssemblySymbol list) * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) * ?userOpName: string -> Async<FSharpDeclarationListInfo>
member GetDeclarationListInfo : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * ?getAllEntities: (unit -> AssemblySymbol list) * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) * ?userOpName: string -> Async<FSharpDeclarationListInfo>

/// <summary>Get the items for a declaration list in FSharpSymbol format</summary>
///
Expand All @@ -145,16 +145,16 @@ type public FSharpCheckFileResults =
/// The text of the line where the completion is happening. This is only used to make a couple
/// of adhoc corrections to completion accuracy (e.g. checking for "..")
/// </param>
/// <param name="getAllSymbols">
/// Function that returns all symbols from current and referenced assemblies.
/// <param name="getAllEntities">
/// Function that returns all entities from current and referenced assemblies.
/// </param>
/// <param name="hasTextChangedSinceLastTypecheck">
/// If text has been used from a captured name resolution from the typecheck, then
/// callback to the client to check if the text has changed. If it has, then give up
/// and assume that we're going to repeat the operation later on.
/// </param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member GetDeclarationListSymbols : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) * ?userOpName: string -> Async<FSharpSymbolUse list list>
member GetDeclarationListSymbols : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * ?getAllEntities: (unit -> AssemblySymbol list) * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) * ?userOpName: string -> Async<FSharpSymbolUse list list>


/// <summary>Compute a formatted tooltip for the given location</summary>
Expand Down
6 changes: 3 additions & 3 deletions tests/service/EditorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ type Test() =
let file = "/home/user/Test.fsx"
let parseResult, typeCheckResults = parseAndCheckScript(file, input)

let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(20), fun _ -> false)|> Async.RunSynchronously
let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(20), (fun () -> []), fun _ -> false)|> Async.RunSynchronously
//decls |> List.map (fun d -> d.Head.Symbol.DisplayName) |> printfn "---> decls = %A"
decls |> Seq.exists (fun d -> d.Head.Symbol.DisplayName = "abc") |> shouldEqual true

Expand All @@ -374,7 +374,7 @@ type Test() =
let file = "/home/user/Test.fsx"
let parseResult, typeCheckResults = parseAndCheckScript(file, input)

let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(21), fun _ -> false)|> Async.RunSynchronously
let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(21), (fun () -> []), fun _ -> false)|> Async.RunSynchronously
//decls |> List.map (fun d -> d.Head.Symbol.DisplayName) |> printfn "---> decls = %A"
decls |> Seq.exists (fun d -> d.Head.Symbol.DisplayName = "abc") |> shouldEqual true

Expand All @@ -391,7 +391,7 @@ type Test() =
let file = "/home/user/Test.fsx"
let parseResult, typeCheckResults = parseAndCheckScript(file, input)

let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(14), fun _ -> false)|> Async.RunSynchronously
let decls = typeCheckResults.GetDeclarationListSymbols(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(14), (fun () -> []), fun _ -> false)|> Async.RunSynchronously
//decls |> List.map (fun d -> d.Head.Symbol.DisplayName) |> printfn "---> decls = %A"
decls |> Seq.exists (fun d -> d.Head.Symbol.DisplayName = "abc") |> shouldEqual true

Expand Down