Skip to content

Commit 959f05a

Browse files
authored
Include attributes in range of SynModuleOrNamespace(Sig). (#11483)
1 parent 5eec9a0 commit 959f05a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/fsharp/pars.fsy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ fileModuleSpec:
722722
| opt_attributes opt_declVisibility moduleIntro moduleSpfnsPossiblyEmptyBlock
723723
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
724724
let m2 = rhs parseState 3
725-
let m = (rhs2 parseState 1 4)
725+
let mDeclsAndAttrs = (List.map (fun (a: SynAttributeList) -> a.Range) $1) @ (List.map (fun (d: SynModuleSigDecl) -> d.Range) $4)
726+
let m = (m2, mDeclsAndAttrs) ||> unionRangeWithListBy id
726727
let isRec, path2, xml, vis = $3
727728
(fun (isRec2, path, _) ->
728729
if not (isNil path) then errorR(Error(FSComp.SR.parsNamespaceOrModuleNotBoth(), m2))
@@ -1156,7 +1157,8 @@ fileModuleImpl:
11561157
| opt_attributes opt_declVisibility moduleIntro moduleDefnsOrExprPossiblyEmptyOrBlock
11571158
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
11581159
let m2 = rhs parseState 3
1159-
let m = (m2, $4) ||> unionRangeWithListBy (fun modu -> modu.Range)
1160+
let mDeclsAndAttrs = (List.map (fun (a: SynAttributeList) -> a.Range) $1) @ (List.map (fun (d: SynModuleDecl) -> d.Range) $4)
1161+
let m = (m2, mDeclsAndAttrs) ||> unionRangeWithListBy id
11601162
let isRec2, path2, xml, vis = $3
11611163
(fun (isRec, path, _) ->
11621164
if not (isNil path) then errorR(Error(FSComp.SR.parsNamespaceOrModuleNotBoth(), m2))

tests/service/Symbols.fs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,23 @@ type X = int
491491
assertRange (3, 0) (5, 12) r
492492
| _ -> Assert.Fail "Could not get valid AST"
493493

494+
[<Test>]
495+
let ``Module range should start at first attribute`` () =
496+
let parseResults =
497+
getParseResults
498+
"""
499+
[< Foo >]
500+
module Bar
501+
502+
let s : string = "s"
503+
"""
504+
505+
match parseResults with
506+
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [
507+
SynModuleOrNamespace.SynModuleOrNamespace(kind = SynModuleOrNamespaceKind.NamedModule; range = r) ])) ->
508+
assertRange (2, 0) (5, 20) r
509+
| _ -> Assert.Fail "Could not get valid AST"
510+
494511
module SynConsts =
495512
[<Test>]
496513
let ``Measure contains the range of the constant`` () =
@@ -545,6 +562,23 @@ type Bar = | Bar of string * int
545562
assertRange (3, 0) (5, 32) r
546563
| _ -> Assert.Fail "Could not get valid AST"
547564

565+
[<Test>]
566+
let ``Module range should start at first attribute`` () =
567+
let parseResults =
568+
getParseResultsOfSignatureFile
569+
"""
570+
[< Foo >]
571+
module Bar
572+
573+
val s : string
574+
"""
575+
576+
match parseResults with
577+
| ParsedInput.SigFile (ParsedSigFileInput (modules = [
578+
SynModuleOrNamespaceSig.SynModuleOrNamespaceSig(kind = SynModuleOrNamespaceKind.NamedModule; range = r) ])) ->
579+
assertRange (2, 1) (5, 14) r
580+
| _ -> Assert.Fail "Could not get valid AST"
581+
548582
module SignatureTypes =
549583
[<Test>]
550584
let ``Range of Type should end at end keyword`` () =

0 commit comments

Comments
 (0)