diff --git a/src/fsharp/service/ServiceAnalysis.fs b/src/fsharp/service/ServiceAnalysis.fs index f549065fc1c..71dbdce532a 100644 --- a/src/fsharp/service/ServiceAnalysis.fs +++ b/src/fsharp/service/ServiceAnalysis.fs @@ -67,9 +67,9 @@ module UnusedOpens = yield! getModuleAndItsAutoOpens true ent |] { OpenedModules = getModuleAndItsAutoOpens false modul } - /// Represents single open statement. + /// Represents a single open statement type OpenStatement = - { /// All namespaces and modules which this open declaration effectively opens, including the AutoOpen ones + { /// All namespaces, modules and types which this open declaration effectively opens, including the AutoOpen ones OpenedGroups: OpenedModuleGroup list /// The range of open statement itself @@ -90,7 +90,8 @@ module UnusedOpens = if firstId.idText = MangledGlobalName then None else - Some { OpenedGroups = openDecl.Modules |> List.map OpenedModuleGroup.Create + let openedModulesAndTypes = List.concat [openDecl.Modules; openDecl.Types |> List.map(fun ty -> ty.TypeDefinition)] + Some { OpenedGroups = openedModulesAndTypes |> List.map OpenedModuleGroup.Create Range = range AppliedScope = openDecl.AppliedScope } | _ -> None) diff --git a/vsintegration/tests/UnitTests/UnusedOpensTests.fs b/vsintegration/tests/UnitTests/UnusedOpensTests.fs index 28738bfe1cb..58ba173e4ca 100644 --- a/vsintegration/tests/UnitTests/UnusedOpensTests.fs +++ b/vsintegration/tests/UnitTests/UnusedOpensTests.fs @@ -808,4 +808,49 @@ open Nested let _ = f 1 """ - => [] \ No newline at end of file + => [] + +[] +let ``used open C# type``() = + """ +open type System.Console + +WriteLine("Hello World") + """ + => [] + +[] +let ``unused open C# type``() = + """ +open type System.Console + +printfn "%s" "Hello World" + """ + => [2, (10, 24)] + +[] +let ``used open type from module``() = + """ +module MyModule = + type Thingy = + static member Thing = () + +open type MyModule.Thingy + +printfn "%A" Thing + """ + => [] + +[] +let ``unused open type from module``() = + """ +module MyModule = + type Thingy = + static member Thing = () + +open type MyModule.Thingy + +printfn "%A" MyModule.Thingy.Thing + """ + => [6, (10, 25)] +