Skip to content

Commit

Permalink
Add support for single identifier module abbreviations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 29, 2022
1 parent 789174c commit 48e4194
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/ParallelTypeCheckingTests/Code/FileContentMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ let visitLongIdent (lid: LongIdent) =
| [ _ ] -> []
| lid -> [ FileContentEntry.PrefixedIdentifier(longIdentToPath true lid) ]

let visitLongIdentForModuleAbbrev (lid: LongIdent) =
match lid with
| [] -> []
| lid -> [ FileContentEntry.PrefixedIdentifier(longIdentToPath false lid) ]

let visitSynAttribute (a: SynAttribute) : FileContentEntry list =
[ yield! visitSynLongIdent a.TypeName; yield! visitSynExpr a.ArgExpr ]

Expand Down Expand Up @@ -55,7 +60,7 @@ let visitSynModuleDecl (decl: SynModuleDecl) : FileContentEntry list =
| SynModuleDecl.ModuleAbbrev (longId = longId) ->
// I believe this is enough
// A module abbreviation doesn't appear to be exposed as part of the current module/namespace
visitLongIdent longId
visitLongIdentForModuleAbbrev longId
| SynModuleDecl.NamespaceFragment _ -> []
| SynModuleDecl.Exception(exnDefn = SynExceptionDefn (exnRepr = SynExceptionDefnRepr (attributes = attributes
caseName = caseName
Expand All @@ -79,7 +84,7 @@ let visitSynModuleSigDecl (md: SynModuleSigDecl) =
yield FileContentEntry.NestedModule(ident.idText, lc visitSynModuleSigDecl decls)
]
| SynModuleSigDecl.NestedModule _ -> failwith "A nested module cannot have multiple identifiers"
| SynModuleSigDecl.ModuleAbbrev _ -> failwith "no support for module abbreviations"
| SynModuleSigDecl.ModuleAbbrev (longId = longId) -> visitLongIdentForModuleAbbrev longId
| SynModuleSigDecl.Val (valSig, _) -> visitSynValSig valSig
| SynModuleSigDecl.Types (types = types) -> lc visitSynTypeDefnSig types
| SynModuleSigDecl.Exception(exnSig = SynExceptionSig (exnRepr = SynExceptionDefnRepr (attributes = attributes
Expand Down
15 changes: 15 additions & 0 deletions tests/ParallelTypeCheckingTests/Tests/FileContentMappingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,18 @@ module Z =
match content with
| [ TopLevelNamespace "X" [ NestedModule "Z" [] ] ] -> Assert.Pass()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
let ``Single ident module abbreviation`` () =
let content =
getContent
true
"""
module A
module B = C
"""

match content with
| [ TopLevelNamespace "" [ PrefixedIdentifier "C" ] ] -> Assert.Pass()
| content -> Assert.Fail($"Unexpected content: {content}")
2 changes: 2 additions & 0 deletions tests/ParallelTypeCheckingTests/Tests/Scenarios.fs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ exception BakedInMemberConstraintName of string
"""
namespace FSharp.Compiler.CodeAnalysis
open FSharp.Compiler
module Tc = CheckExpressions
"""
(set [| 0 |])
Expand Down

0 comments on commit 48e4194

Please sign in to comment.