Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix missing completion items in constructors of inherited types (#6002)
* Do not notify env sink about base constructor (fixes #3699)

* Extract function
  • Loading branch information
auduchinok authored and KevinRansom committed Jan 31, 2019
commit 7523db9fb4a4797c6fc13cc937824d749c411263
33 changes: 19 additions & 14 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,21 +1509,26 @@ let MakeAndPublishVal cenv env (altActualParent, inSig, declKind, vrec, (ValSche

PublishValueDefn cenv env declKind vspec

let shouldNotifySink (vspec: Val) =
match vspec.MemberInfo with
// `this` reference named `__`. It's either:
// * generated by compiler for auto properties or
// * provided by source code (i.e. `member __.Method = ...`)
// We don't notify sink about it to prevent generating `FSharpSymbol` for it and appearing in completion list.
| None when
let baseOrThisInfo = vspec.BaseOrThisInfo
baseOrThisInfo = ValBaseOrThisInfo.BaseVal || // visualfsharp#3699
baseOrThisInfo = ValBaseOrThisInfo.MemberThisVal && vspec.LogicalName = "__" -> false
| _ -> true

match cenv.tcSink.CurrentSink with
| None -> ()
| Some _ ->
if not vspec.IsCompilerGenerated then
match vspec.MemberInfo with
// `this` reference named `__`. It's either:
// * generated by compiler for auto properties or
// * provided by source code (i.e. `member __.Method = ...`)
// We don't notify sink about it to prevent generating `FSharpSymbol` for it and appearing in completion list.
| None when vspec.BaseOrThisInfo = ValBaseOrThisInfo.MemberThisVal && vspec.LogicalName = "__" -> ()
| _ ->
let nenv = AddFakeNamedValRefToNameEnv vspec.DisplayName env.NameEnv (mkLocalValRef vspec)
CallEnvSink cenv.tcSink (vspec.Range, nenv, env.eAccessRights)
let item = Item.Value(mkLocalValRef vspec)
CallNameResolutionSink cenv.tcSink (vspec.Range, nenv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights)
| Some _ when not vspec.IsCompilerGenerated && shouldNotifySink vspec ->
let nenv = AddFakeNamedValRefToNameEnv vspec.DisplayName env.NameEnv (mkLocalValRef vspec)
CallEnvSink cenv.tcSink (vspec.Range, nenv, env.eAccessRights)
let item = Item.Value(mkLocalValRef vspec)
CallNameResolutionSink cenv.tcSink (vspec.Range, nenv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights)
| _ -> ()

vspec

let MakeAndPublishVals cenv env (altActualParent, inSig, declKind, vrec, valSchemes, attrs, doc, konst) =
Expand Down
44 changes: 44 additions & 0 deletions tests/service/EditorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,50 @@ type Test() =
let decls = typeCheckResults.GetDeclarationListInfo(Some parseResult, 4, inputLines.[3], PartialLongName.Empty(14), (fun _ -> []), fun _ -> false)|> Async.RunSynchronously
decls.Items |> Seq.exists (fun d -> d.Name = "abc") |> shouldEqual true


[<Test>]
let ``Completion in base constructor`` () =
let input =
"""
type A(foo) =
class
end

type B(bar) =
inherit A(bar)"""

// Split the input & define file name
let inputLines = input.Split('\n')
let file = "/home/user/Test.fsx"
let parseResult, typeCheckResults = parseAndCheckScript(file, input)

let decls = typeCheckResults.GetDeclarationListInfo(Some parseResult, 7, inputLines.[6], PartialLongName.Empty(17), (fun _ -> []), fun _ -> false)|> Async.RunSynchronously
decls.Items |> Seq.exists (fun d -> d.Name = "bar") |> shouldEqual true



[<Test>]
let ``Completion in do in base constructor`` () =
let input =
"""
type A() =
class
end

type B(bar) =
inherit A()

do bar"""

// Split the input & define file name
let inputLines = input.Split('\n')
let file = "/home/user/Test.fsx"
let parseResult, typeCheckResults = parseAndCheckScript(file, input)

let decls = typeCheckResults.GetDeclarationListInfo(Some parseResult, 9, inputLines.[8], PartialLongName.Empty(7), (fun _ -> []), fun _ -> false)|> Async.RunSynchronously
decls.Items |> Seq.exists (fun d -> d.Name = "bar") |> shouldEqual true


[<Test; Ignore("SKIPPED: see #139")>]
let ``Symbol based find function from member 1`` () =
let input =
Expand Down