Skip to content
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
48 changes: 26 additions & 22 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3376,14 +3376,14 @@ let ComputeQualifiedNameOfFileFromUniquePath (m, p: string list) = QualifiedName

let QualFileNameOfSpecs filename specs =
match specs with
| [SynModuleOrNamespaceSig(modname, _, true, _, _, _, _, m)] -> QualFileNameOfModuleName m filename modname
| [SynModuleOrNamespaceSig(_, _, false, _, _, _, _, m)] -> QualFileNameOfFilename m filename
| [SynModuleOrNamespaceSig(modname, _, kind, _, _, _, _, m)] when kind.IsModule -> QualFileNameOfModuleName m filename modname
| [SynModuleOrNamespaceSig(_, _, kind, _, _, _, _, m)] when not kind.IsModule -> QualFileNameOfFilename m filename
| _ -> QualFileNameOfFilename (mkRange filename pos0 pos0) filename

let QualFileNameOfImpls filename specs =
match specs with
| [SynModuleOrNamespace(modname, _, true, _, _, _, _, m)] -> QualFileNameOfModuleName m filename modname
| [SynModuleOrNamespace(_, _, false, _, _, _, _, m)] -> QualFileNameOfFilename m filename
| [SynModuleOrNamespace(modname, _, kind, _, _, _, _, m)] when kind.IsModule -> QualFileNameOfModuleName m filename modname
| [SynModuleOrNamespace(_, _, kind, _, _, _, _, m)] when not kind.IsModule -> QualFileNameOfFilename m filename
| _ -> QualFileNameOfFilename (mkRange filename pos0 pos0) filename

let PrepandPathToQualFileName x (QualifiedNameOfFile(q)) = ComputeQualifiedNameOfFileFromUniquePath (q.idRange, pathOfLid x@[q.idText])
Expand Down Expand Up @@ -3412,13 +3412,14 @@ let ComputeAnonModuleName check defaultNamespace filename (m: range) =

let PostParseModuleImpl (_i, defaultNamespace, isLastCompiland, filename, impl) =
match impl with
| ParsedImplFileFragment.NamedModule(SynModuleOrNamespace(lid, isRec, isModule, decls, xmlDoc, attribs, access, m)) ->
| ParsedImplFileFragment.NamedModule(SynModuleOrNamespace(lid, isRec, kind, decls, xmlDoc, attribs, access, m)) ->
let lid =
match lid with
| [id] when isModule && id.idText = MangledGlobalName -> error(Error(FSComp.SR.buildInvalidModuleOrNamespaceName(), id.idRange))
| [id] when kind.IsModule && id.idText = MangledGlobalName ->
error(Error(FSComp.SR.buildInvalidModuleOrNamespaceName(), id.idRange))
| id :: rest when id.idText = MangledGlobalName -> rest
| _ -> lid
SynModuleOrNamespace(lid, isRec, isModule, decls, xmlDoc, attribs, access, m)
SynModuleOrNamespace(lid, isRec, kind, decls, xmlDoc, attribs, access, m)

| ParsedImplFileFragment.AnonModule (defs, m)->
let isLast, isExe = isLastCompiland
Expand All @@ -3429,24 +3430,26 @@ let PostParseModuleImpl (_i, defaultNamespace, isLastCompiland, filename, impl)
| _ -> errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(), trimRangeToLine m))

let modname = ComputeAnonModuleName (not (isNil defs)) defaultNamespace filename (trimRangeToLine m)
SynModuleOrNamespace(modname, false, true, defs, PreXmlDoc.Empty, [], None, m)
SynModuleOrNamespace(modname, false, AnonModule, defs, PreXmlDoc.Empty, [], None, m)

| ParsedImplFileFragment.NamespaceFragment (lid, a, b, c, d, e, m)->
let lid =
| ParsedImplFileFragment.NamespaceFragment (lid, a, kind, c, d, e, m)->
let lid, kind =
match lid with
| id :: rest when id.idText = MangledGlobalName -> rest
| _ -> lid
SynModuleOrNamespace(lid, a, b, c, d, e, None, m)
| id :: rest when id.idText = MangledGlobalName ->
rest, if List.isEmpty rest then GlobalNamespace else kind
| _ -> lid, kind
SynModuleOrNamespace(lid, a, kind, c, d, e, None, m)

let PostParseModuleSpec (_i, defaultNamespace, isLastCompiland, filename, intf) =
match intf with
| ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(lid, isRec, isModule, decls, xmlDoc, attribs, access, m)) ->
| ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(lid, isRec, kind, decls, xmlDoc, attribs, access, m)) ->
let lid =
match lid with
| [id] when isModule && id.idText = MangledGlobalName -> error(Error(FSComp.SR.buildInvalidModuleOrNamespaceName(), id.idRange))
| [id] when kind.IsModule && id.idText = MangledGlobalName ->
error(Error(FSComp.SR.buildInvalidModuleOrNamespaceName(), id.idRange))
| id :: rest when id.idText = MangledGlobalName -> rest
| _ -> lid
SynModuleOrNamespaceSig(lid, isRec, isModule, decls, xmlDoc, attribs, access, m)
SynModuleOrNamespaceSig(lid, isRec, NamedModule, decls, xmlDoc, attribs, access, m)

| ParsedSigFileFragment.AnonModule (defs, m) ->
let isLast, isExe = isLastCompiland
Expand All @@ -3457,14 +3460,15 @@ let PostParseModuleSpec (_i, defaultNamespace, isLastCompiland, filename, intf)
| _ -> errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(), m))

let modname = ComputeAnonModuleName (not (isNil defs)) defaultNamespace filename (trimRangeToLine m)
SynModuleOrNamespaceSig(modname, false, true, defs, PreXmlDoc.Empty, [], None, m)
SynModuleOrNamespaceSig(modname, false, AnonModule, defs, PreXmlDoc.Empty, [], None, m)

| ParsedSigFileFragment.NamespaceFragment (lid, a, b, c, d, e, m)->
let lid =
| ParsedSigFileFragment.NamespaceFragment (lid, a, kind, c, d, e, m)->
let lid, kind =
match lid with
| id :: rest when id.idText = MangledGlobalName -> rest
| _ -> lid
SynModuleOrNamespaceSig(lid, a, b, c, d, e, None, m)
| id :: rest when id.idText = MangledGlobalName ->
rest, if List.isEmpty rest then GlobalNamespace else kind
| _ -> lid, kind
SynModuleOrNamespaceSig(lid, a, kind, c, d, e, None, m)



Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16713,7 +16713,7 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
return env


| SynModuleSigDecl.NamespaceFragment (SynModuleOrNamespaceSig(longId, isRec, isModule, defs, xml, attribs, vis, m)) ->
| SynModuleSigDecl.NamespaceFragment (SynModuleOrNamespaceSig(longId, isRec, kind, defs, xml, attribs, vis, m)) ->

do for id in longId do
CheckNamespaceModuleOrTypeName cenv.g id
Expand All @@ -16725,7 +16725,7 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
// namespace [rec] A.B
// module M = ...
let enclosingNamespacePath, defs =
if isModule then
if kind.IsModule then
let nsp, modName = List.frontAndBack longId
let modDecl = [SynModuleSigDecl.NestedModule(ComponentInfo(attribs, [], [], [modName], xml, false, vis, m), false, defs, m)]
nsp, modDecl
Expand Down Expand Up @@ -17022,7 +17022,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv:cenv) parent typeNames scopem
return ((fun modDefs -> modDefn :: modDefs), topAttrsNew), env, envAtEnd


| SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(longId, isRec, isModule, defs, xml, attribs, vis, m)) ->
| SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(longId, isRec, kind, defs, xml, attribs, vis, m)) ->

if !progress then dprintn ("Typecheck implementation " + textOfLid longId)
let endm = m.EndRange
Expand All @@ -17037,7 +17037,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv:cenv) parent typeNames scopem
// namespace [rec] A.B
// module M = ...
let enclosingNamespacePath, defs =
if isModule then
if kind.IsModule then
let nsp, modName = List.frontAndBack longId
let modDecl = [SynModuleDecl.NestedModule(ComponentInfo(attribs, [], [], [modName], xml, false, vis, m), false, defs, true, m)]
nsp, modDecl
Expand Down
22 changes: 17 additions & 5 deletions src/fsharp/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,19 +1462,31 @@ and

and SynModuleSigDecls = SynModuleSigDecl list

/// SynModuleOrNamespace(lid,isRec,isModule,decls,xmlDoc,attribs,SynAccess,m)
and
[<Struct>]
SynModuleOrNamespaceKind =
| NamedModule
| AnonModule
| DeclaredNamespace
| GlobalNamespace

member x.IsModule =
match x with
| NamedModule | AnonModule -> true
| _ -> false

and
[<NoEquality; NoComparison>]
SynModuleOrNamespace =
| SynModuleOrNamespace of longId:LongIdent * isRecursive:bool * isModule:bool * decls:SynModuleDecls * xmlDoc:PreXmlDoc * attribs:SynAttributes * accessibility:SynAccess option * range:range
| SynModuleOrNamespace of longId:LongIdent * isRecursive:bool * kind:SynModuleOrNamespaceKind * decls:SynModuleDecls * xmlDoc:PreXmlDoc * attribs:SynAttributes * accessibility:SynAccess option * range:range
member this.Range =
match this with
| SynModuleOrNamespace (range=m) -> m

and
[<NoEquality; NoComparison>]
SynModuleOrNamespaceSig =
| SynModuleOrNamespaceSig of longId:LongIdent * isRecursive:bool * isModule:bool * SynModuleSigDecls * xmlDoc:PreXmlDoc * attribs:SynAttributes * accessibility:SynAccess option * range:range
| SynModuleOrNamespaceSig of longId:LongIdent * isRecursive:bool * kind:SynModuleOrNamespaceKind * SynModuleSigDecls * xmlDoc:PreXmlDoc * attribs:SynAttributes * accessibility:SynAccess option * range:range

and [<NoEquality; NoComparison>]
ParsedHashDirective =
Expand All @@ -1484,13 +1496,13 @@ and [<NoEquality; NoComparison>]
type ParsedImplFileFragment =
| AnonModule of SynModuleDecls * range:range
| NamedModule of SynModuleOrNamespace
| NamespaceFragment of longId:LongIdent * bool * bool * SynModuleDecls * xmlDoc:PreXmlDoc * SynAttributes * range:range
| NamespaceFragment of longId:LongIdent * bool * SynModuleOrNamespaceKind * SynModuleDecls * xmlDoc:PreXmlDoc * SynAttributes * range:range

[<NoEquality; NoComparison; RequireQualifiedAccess>]
type ParsedSigFileFragment =
| AnonModule of SynModuleSigDecls * range:range
| NamedModule of SynModuleOrNamespaceSig
| NamespaceFragment of longId:LongIdent * bool * bool * SynModuleSigDecls * xmlDoc:PreXmlDoc * SynAttributes * range:range
| NamespaceFragment of longId:LongIdent * bool * SynModuleOrNamespaceKind * SynModuleSigDecls * xmlDoc:PreXmlDoc * SynAttributes * range:range

[<NoEquality; NoComparison>]
type ParsedFsiInteraction =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/fsi/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ type internal FsiDynamicCompiler
let i = nextFragmentId()
let prefix = mkFragmentPath i
let prefixPath = pathOfLid prefix
let impl = SynModuleOrNamespace(prefix,(*isRec*)false, (* isModule: *) true,defs,PreXmlDoc.Empty,[],None,rangeStdin)
let impl = SynModuleOrNamespace(prefix,(*isRec*)false, NamedModule,defs,PreXmlDoc.Empty,[],None,rangeStdin)
let input = ParsedInput.ImplFile(ParsedImplFileInput(filename,true, ComputeQualifiedNameOfFileFromUniquePath (rangeStdin,prefixPath),[],[],[impl],(true (* isLastCompiland *), false (* isExe *)) ))
let istate,tcEnvAtEndOfLastInput,declaredImpls = ProcessInputs (ctok, errorLogger, istate, [input], showTypes, true, isInteractiveItExpr, prefix)
let tcState = istate.tcState
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,14 @@ fileModuleSpec:
(fun (isRec2,path,_) ->
if not (isNil path) then errorR(Error(FSComp.SR.parsNamespaceOrModuleNotBoth(),m2))
let lid = path@path2
ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(lid, (isRec || isRec2), true, $4, xml,$1,vis,m))) }
ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(lid, (isRec || isRec2), NamedModule, $4, xml,$1,vis,m))) }

| moduleSpfnsPossiblyEmptyBlock
{ let m = (rhs parseState 1)
(fun (isRec, path, xml) ->
match path with
| [] -> ParsedSigFileFragment.AnonModule($1, m)
| _ -> ParsedSigFileFragment.NamespaceFragment(path, isRec, false, $1, xml,[],m)) }
| _ -> ParsedSigFileFragment.NamespaceFragment(path, isRec, DeclaredNamespace, $1, xml,[],m)) }


moduleSpfnsPossiblyEmptyBlock:
Expand Down Expand Up @@ -1097,14 +1097,14 @@ fileModuleImpl:
(fun (isRec, path, _) ->
if not (isNil path) then errorR(Error(FSComp.SR.parsNamespaceOrModuleNotBoth(),m2))
let lid = path@path2
ParsedImplFileFragment.NamedModule(SynModuleOrNamespace(lid, (isRec || isRec2), true, $4, xml,$1,vis,m))) }
ParsedImplFileFragment.NamedModule(SynModuleOrNamespace(lid, (isRec || isRec2), NamedModule, $4, xml,$1,vis,m))) }

| moduleDefnsOrExprPossiblyEmptyOrBlock
{ let m = (rhs parseState 1)
(fun (isRec, path, xml) ->
match path with
| [] -> ParsedImplFileFragment.AnonModule($1,m)
| _ -> ParsedImplFileFragment.NamespaceFragment(path, isRec, false, $1, xml,[],m)) }
| _ -> ParsedImplFileFragment.NamespaceFragment(path, isRec, DeclaredNamespace, $1, xml,[],m)) }


/* A collection/block of definitions or expressions making up a module or namespace, possibly empty */
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/service/ServiceAssemblyContent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,9 @@ module ParsedInput =
let rec walkImplFileInput (ParsedImplFileInput(modules = moduleOrNamespaceList)) =
List.iter (walkSynModuleOrNamespace []) moduleOrNamespaceList

and walkSynModuleOrNamespace (parent: LongIdent) (SynModuleOrNamespace(ident, _, isModule, decls, _, _, _, range)) =
and walkSynModuleOrNamespace (parent: LongIdent) (SynModuleOrNamespace(ident, _, kind, decls, _, _, _, range)) =
if range.EndLine >= currentLine then
let isModule = kind.IsModule
match isModule, parent, ident with
| false, _, _ -> ns := Some (longIdentToIdents ident)
// top level module with "inlined" namespace like Ns1.Ns2.TopModule
Expand Down
14 changes: 8 additions & 6 deletions src/fsharp/service/ServiceNavigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module NavigationImpl =
let items =
// Show base name for this module only if it's not the root one
let singleTopLevel = (modules.Length = 1)
modules |> List.collect (fun (SynModuleOrNamespace(id, _isRec, isModule, decls, _, _, access, m)) ->
modules |> List.collect (fun (SynModuleOrNamespace(id, _isRec, kind, decls, _, _, access, m)) ->
let baseName = if (not singleTopLevel) then textOfLid id else ""
// Find let bindings (for the right dropdown)
let nested = processNestedDeclarations(decls)
Expand All @@ -283,7 +283,7 @@ module NavigationImpl =
| _ ->
let decl =
FSharpNavigationDeclarationItem.Create
(textOfLid id, (if isModule then ModuleFileDecl else NamespaceDecl),
(textOfLid id, (if kind.IsModule then ModuleFileDecl else NamespaceDecl),
FSharpGlyph.Module, m,
unionRangesChecked (rangeOfDecls nested) (moduleRange (rangeOfLid id) other),
singleTopLevel, FSharpEnclosingEntityKind.Module, false, access), (addItemName(textOfLid id)), nested
Expand Down Expand Up @@ -410,7 +410,7 @@ module NavigationImpl =
let items =
// Show base name for this module only if it's not the root one
let singleTopLevel = (modules.Length = 1)
modules |> List.collect (fun (SynModuleOrNamespaceSig(id, _isRec, isModule, decls, _, _, access, m)) ->
modules |> List.collect (fun (SynModuleOrNamespaceSig(id, _isRec, kind, decls, _, _, access, m)) ->
let baseName = if (not singleTopLevel) then textOfLid id else ""
// Find let bindings (for the right dropdown)
let nested = processNestedSigDeclarations(decls)
Expand All @@ -420,7 +420,7 @@ module NavigationImpl =
// Create explicitly - it can be 'single top level' thing that is hidden
let decl =
FSharpNavigationDeclarationItem.Create
(textOfLid id, (if isModule then ModuleFileDecl else NamespaceDecl),
(textOfLid id, (if kind.IsModule then ModuleFileDecl else NamespaceDecl),
FSharpGlyph.Module, m,
unionRangesChecked (rangeOfDecls nested) (moduleRange (rangeOfLid id) other),
singleTopLevel, FSharpEnclosingEntityKind.Module, false, access), (addItemName(textOfLid id)), nested
Expand Down Expand Up @@ -574,7 +574,8 @@ module NavigateTo =
for item in moduleOrNamespaceList do
walkSynModuleOrNamespaceSig item { Type = ContainerType.File; Name = fileName }

and walkSynModuleOrNamespaceSig (SynModuleOrNamespaceSig(lid, _, isModule, decls, _, _, _, _)) container =
and walkSynModuleOrNamespaceSig (SynModuleOrNamespaceSig(lid, _, kind, decls, _, _, _, _)) container =
let isModule = kind.IsModule
if isModule then
addModule lid true container
let container =
Expand Down Expand Up @@ -631,7 +632,8 @@ module NavigateTo =
for item in moduleOrNamespaceList do
walkSynModuleOrNamespace item container

and walkSynModuleOrNamespace(SynModuleOrNamespace(lid, _, isModule, decls, _, _, _, _)) container =
and walkSynModuleOrNamespace(SynModuleOrNamespace(lid, _, kind, decls, _, _, _, _)) container =
let isModule = kind.IsModule
if isModule then
addModule lid false container
let container =
Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/service/ServiceStructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ module Structure =
parseAttributes attrs
| _ -> ()

let parseModuleOrNamespace isScript (SynModuleOrNamespace (longId,_,isModule,decls,_,attribs,_,r)) =
let parseModuleOrNamespace (SynModuleOrNamespace (longId,_,kind,decls,_,attribs,_,r)) =
parseAttributes attribs
let idRange = longIdentRange longId
let fullrange = Range.startToEnd idRange r
let collapse = Range.endToEnd idRange r

// do not return range for top level implicit module in scripts
if isModule && not isScript then
if kind = NamedModule then
rcheck Scope.Module Collapse.Below fullrange collapse

collectHashDirectives decls
Expand Down Expand Up @@ -833,23 +833,23 @@ module Structure =
List.iter parseModuleSigDeclaration decls
| _ -> ()

let parseModuleOrNamespaceSigs (SynModuleOrNamespaceSig(longId,_,isModule,decls,_,attribs,_,r)) =
let parseModuleOrNamespaceSigs (SynModuleOrNamespaceSig(longId,_,kind,decls,_,attribs,_,r)) =
parseAttributes attribs
let rangeEnd = lastModuleSigDeclRangeElse r decls
let idrange = longIdentRange longId
let fullrange = Range.startToEnd idrange rangeEnd
let collapse = Range.endToEnd idrange rangeEnd

if isModule then
if kind.IsModule then
rcheck Scope.Module Collapse.Below fullrange collapse

collectSigHashDirectives decls
collectSigOpens decls
List.iter parseModuleSigDeclaration decls

match parsedInput with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = modules; isScript = isScript)) ->
modules |> List.iter (parseModuleOrNamespace isScript)
| ParsedInput.ImplFile (ParsedImplFileInput (modules = modules)) ->
modules |> List.iter parseModuleOrNamespace
getCommentRanges sourceLines
| ParsedInput.SigFile (ParsedSigFileInput (modules = moduleSigs)) ->
List.iter parseModuleOrNamespaceSigs moduleSigs
Expand Down
Loading