Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9cf6a4

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Symbol uses for namespaces (#3932)
* name resolution environment captures last ident range in long ident instead of full range* fixed: wrong symbols for namespaces* notify name resolution sink about all intermediate namespaces in open declarations* Revert "name resolution environment captures last ident range in long ident instead of full range"This reverts commit 65f866a80625725fb490a90b91a539078b96373c.* fix ranges* we need all modules* return namespace uses in the order they appear in source code* fix a test* fix a test* notify name resolution sink with each root namespace fragments* fix `open global.xxx` compilation
1 parentf1a5d16 commitb9cf6a4

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,24 @@ let OpenModulesOrNamespaces tcSink g amap scopem root env mvvs openDeclaration =
449449
CallOpenDeclarationSink tcSink openDeclaration
450450
match openDeclaration.Range with
451451
| None -> ()
452-
| Some range ->
453-
for modul in mvvs do
454-
let item = Item.ModuleOrNamespaces [modul]
455-
CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
452+
| Some _ ->
453+
let rec loop (acc: (Item * range) list) (idents: Ident list) =
454+
match idents with
455+
| [] -> acc
456+
| [id] when id.idText = MangledGlobalName -> acc
457+
| id :: rest ->
458+
let idents = List.rev idents
459+
let range = id.idRange
460+
let acc =
461+
match ResolveLongIndentAsModuleOrNamespace ResultCollectionSettings.AllResults amap range OpenQualified env.NameEnv env.eAccessRights idents with
462+
| Result modrefs ->
463+
(acc, modrefs) ||> List.fold (fun acc (_, modref, _) ->
464+
(Item.ModuleOrNamespaces [modref], range) :: acc)
465+
| _ -> acc
466+
loop acc rest
467+
468+
for item, range in loop [] (List.rev openDeclaration.LongId) do
469+
CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
456470
env
457471

458472
let AddRootModuleOrNamespaceRefs g amap m env modrefs =
@@ -665,11 +679,11 @@ let LocateEnv ccu env enclosingNamespacePath =
665679
env
666680

667681
let BuildRootModuleType enclosingNamespacePath (cpath:CompilationPath) mtyp =
668-
(enclosingNamespacePath, (cpath, (mtyp,None)))
669-
||> List.foldBack (fun id (cpath, (mtyp,mspec)) ->
682+
(enclosingNamespacePath, (cpath, (mtyp,[])))
683+
||> List.foldBack (fun id (cpath, (mtyp,mspecs)) ->
670684
let a, b = wrapModuleOrNamespaceTypeInNamespace id cpath.ParentCompPath mtyp
671-
cpath.ParentCompPath, (a,match mspec with Some _ -> mspec | None -> Some b))
672-
|>snd
685+
cpath.ParentCompPath, (a,b :: mspecs))
686+
|>fun (_, (mtyp, mspecs)) -> mtyp, List.rev mspecs
673687

674688
let BuildRootModuleExpr enclosingNamespacePath (cpath:CompilationPath) mexpr =
675689
(enclosingNamespacePath, (cpath, mexpr))
@@ -16383,7 +16397,13 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
1638316397

1638416398
// For 'namespace rec' and 'module rec' we add the thing being defined
1638516399
let mtypNS = !(envNS.eModuleOrNamespaceTypeAccumulator)
16386-
let mtypRoot, mspecNSOpt = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16400+
let mtypRoot, mspecNSs = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16401+
let mspecNSOpt = List.tryHead mspecNSs
16402+
16403+
mspecNSs |> List.iter (fun mspec ->
16404+
let modref = mkLocalModRef mspec
16405+
let item = Item.ModuleOrNamespaces [modref]
16406+
CallNameResolutionSink cenv.tcSink (mspec.Range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights))
1638716407

1638816408
// For 'namespace rec' and 'module rec' we add the thing being defined
1638916409
let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink cenv.g cenv.amap m envNS mtypRoot else envNS
@@ -16688,7 +16708,13 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv:cenv) parent typeNames scopem
1668816708
let envNS = ImplicitlyOpenOwnNamespace cenv.tcSink cenv.g cenv.amap m enclosingNamespacePath envNS
1668916709

1669016710
let mtypNS = !(envNS.eModuleOrNamespaceTypeAccumulator)
16691-
let mtypRoot, mspecNSOpt = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16711+
let mtypRoot, mspecNSs = BuildRootModuleType enclosingNamespacePath envNS.eCompPath mtypNS
16712+
let mspecNSOpt = List.tryHead mspecNSs
16713+
16714+
mspecNSs |> List.iter (fun mspec ->
16715+
let modref = mkLocalModRef mspec
16716+
let item = Item.ModuleOrNamespaces [modref]
16717+
CallNameResolutionSink cenv.tcSink (mspec.Range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Binding, env.DisplayEnv, env.eAccessRights))
1669216718

1669316719
// For 'namespace rec' and 'module rec' we add the thing being defined
1669416720
let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink cenv.g cenv.amap m envNS mtypRoot else envNS

‎src/fsharp/symbols/Symbols.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ and FSharpEntity(cenv:cenv, entity:EntityRef) =
230230
inherit FSharpSymbol(cenv,
231231
(fun()->
232232
checkEntityIsResolved(entity);
233-
if entity.IsModulethen Item.ModuleOrNamespaces[entity]
233+
if entity.IsModuleOrNamespacethen Item.ModuleOrNamespaces[entity]
234234
else Item.UnqualifiedType[entity]),
235235
(fun _this thisCcu2 ad->
236236
checkForCrossProjectAccessibility(thisCcu2, ad)(cenv.thisCcu, getApproxFSharpAccessibilityOfEntity entity))

‎tests/service/CSharpProjectAnalysis.fs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ let _ = CSharpOuterClass.InnerClass.StaticMember()
111111
|> Async.RunSynchronously
112112
|> Array.map(fun su-> su.Symbol.ToString())
113113
|> shouldEqual
114-
[|"Tests";"InnerEnum";"CSharpOuterClass";"field Case1";"InnerClass";
115-
"CSharpOuterClass";"member StaticMember";"NestedEnumClass"|]
114+
[|"FSharp";"FSharp";"Compiler";"Service";"Tests";"InnerEnum";
115+
"CSharpOuterClass";"field Case1";"InnerClass";"CSharpOuterClass";
116+
"member StaticMember";"NestedEnumClass"|]
116117

117118
[<Test>]
118119
let``Ctor test``()=

‎tests/service/ProjectAnalysisTests.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,8 +3688,10 @@ let ``Test Project25 symbol uses of type-provided members`` () =
36883688

36893689
allUses|> shouldEqual
36903690

3691-
[|("FSharp.Data","file1",((3,5),(3,16)),["namespace";"provided"]);
3692-
("Microsoft.FSharp.Data","file1",((3,5),(3,16)),["namespace"]);
3691+
[|("Microsoft.FSharp","file1",((3,5),(3,11)),["namespace"]);
3692+
("FSharp","file1",((3,5),(3,11)),["namespace"]);
3693+
("Microsoft.FSharp.Data","file1",((3,12),(3,16)),["namespace"]);
3694+
("FSharp.Data","file1",((3,12),(3,16)),["namespace";"provided"]);
36933695
("FSharp.Data.XmlProvider","file1",((4,15),(4,26)),
36943696
["class";"provided";"erased"]);
36953697
("FSharp.Data.XmlProvider","file1",((4,15),(4,26)),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp