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

Fix missing completion items in constructors of inherited types #6002

Merged
merged 2 commits into from
Jan 31, 2019
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
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 @@ -336,6 +336,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