Skip to content

Commit 5b8c582

Browse files
committed
Import type: try getting parent modules when importing module attribute
1 parent b0e3a5f commit 5b8c582

File tree

8 files changed

+54
-1
lines changed

8 files changed

+54
-1
lines changed

ReSharper.FSharp/src/FSharp.Psi.Features/src/Util/OpensUtil.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ let rec getModuleToOpen (typeElement: ITypeElement): IClrDeclaredElement =
6161

6262
let findModuleToInsert (fsFile: IFSharpFile) (offset: DocumentOffset) (settings: IContextBoundSettingsStore) =
6363
if not (settings.GetValue(fun key -> key.TopLevelOpenCompletion)) then
64-
fsFile.GetNode<IModuleLikeDeclaration>(offset)
64+
match fsFile.GetNode<IModuleLikeDeclaration>(offset) with
65+
| :? IDeclaredModuleLikeDeclaration as moduleDecl when
66+
let keyword = moduleDecl.ModuleOrNamespaceKeyword
67+
isNotNull keyword && keyword.GetTreeStartOffset().Offset < offset.Offset ->
68+
moduleDecl :> IModuleLikeDeclaration
69+
| moduleDecl ->
70+
moduleDecl.GetContainingNode<IModuleLikeDeclaration>()
6571
else
6672
match fsFile.GetNode<ITopLevelModuleLikeDeclaration>(offset) with
6773
| null -> fsFile.GetNode<IAnonModuleDeclaration>(offset) :> _
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Ns
2+
3+
[<Optional{caret}>]
4+
module Module =
5+
()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Ns
2+
3+
open System.Runtime.InteropServices
4+
5+
[<Optional{caret}>]
6+
module Module =
7+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Ns
2+
3+
[<Optional{caret}>]
4+
module Module =
5+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Ns
2+
3+
open System.Runtime.InteropServices
4+
5+
[<Optional{caret}>]
6+
module Module =
7+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Ns
2+
3+
module Module =
4+
[<Optional{caret}>]
5+
module Nested =
6+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Ns
2+
3+
module Module =
4+
5+
open System.Runtime.InteropServices
6+
7+
[<Optional{caret}>]
8+
module Nested =
9+
()

ReSharper.FSharp/test/src/FSharp.Tests/QuickFixes/ImportTypeTest.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace JetBrains.ReSharper.Plugins.FSharp.Tests.Features
22

33
open JetBrains.ReSharper.Intentions.QuickFixes
4+
open JetBrains.ReSharper.Plugins.FSharp.Settings
45
open JetBrains.ReSharper.Plugins.FSharp.Tests
6+
open JetBrains.ReSharper.TestFramework
57
open NUnit.Framework
68

79
[<FSharpTest>]
@@ -23,6 +25,12 @@ type ImportTypeTest() =
2325
[<Test>] member x.``Type arguments - Count 01``() = x.DoNamedTest()
2426
[<Test>] member x.``Module name - Escaped 01``() = x.DoNamedTest()
2527

28+
[<Test>] member x.``Nested Module - Attribute 01``() = x.DoNamedTest()
29+
[<TestSetting(typeof<FSharpOptions>, "TopLevelOpenCompletion", "false")>]
30+
[<Test>] member x.``Nested Module - Attribute 02 - Prefer nested``() = x.DoNamedTest()
31+
[<TestSetting(typeof<FSharpOptions>, "TopLevelOpenCompletion", "false")>]
32+
[<Test>] member x.``Nested Module - Attribute 03 - Nested modules``() = x.DoNamedTest()
33+
2634
[<Test>] member x.``Qualifiers - Expr - Imported 01``() = x.DoNamedTest()
2735
[<Test>] member x.``Qualifiers - Expr - Imported 02 - Nested``() = x.DoNamedTest()
2836
[<Test>] member x.``Qualifiers - Expr 01``() = x.DoNamedTest()

0 commit comments

Comments
 (0)