From ff6f797c9c7f2e8ece00d5409a09f61ec12642db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Slupik?= Date: Thu, 19 Nov 2020 19:25:20 -0500 Subject: [PATCH] Fix unused open type declaration detection --- src/fsharp/service/ServiceAnalysis.fs | 7 ++++--- vsintegration/tests/UnitTests/UnusedOpensTests.fs | 11 ++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/fsharp/service/ServiceAnalysis.fs b/src/fsharp/service/ServiceAnalysis.fs index f549065fc1cc..71dbdce532af 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 28738bfe1cb3..ba474f9561c5 100644 --- a/vsintegration/tests/UnitTests/UnusedOpensTests.fs +++ b/vsintegration/tests/UnitTests/UnusedOpensTests.fs @@ -808,4 +808,13 @@ open Nested let _ = f 1 """ - => [] \ No newline at end of file + => [] + +[] +let ``open type``() = + """ +open type System.Console + +WriteLine("Hello World") + """ + => [2, (10, 24)] \ No newline at end of file