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

Commit05e7d26

Browse files
symbol use for open declarations
refactoring
1 parent961f0e9 commit05e7d26

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,15 @@ type ItemOccurence =
12231223
| RelatedText
12241224

12251225
typeOpenDeclaration=
1226-
| OpenoflongId:Identlist*moduleRefs:ModuleOrNamespaceReflist*appliedScope:range
1227-
| AutoOpenModuleofidents:stringlist*moduleRef:ModuleOrNamespaceRef*appliedScope:range
1226+
{ Idents:Ident list
1227+
ModuleRefs:ModuleOrNamespaceRef list
1228+
AppliedScope:range}
1229+
memberthis.Range=
1230+
match this.Identswith
1231+
|[]-> None
1232+
| first:: rest->
1233+
letlast= rest|> List.tryLast|> Option.defaultValue first
1234+
Some(mkRange this.AppliedScope.FileName first.idRange.Start last.idRange.End)
12281235

12291236
/// An abstract type for reporting the results of name resolution and type checking.
12301237
typeITypecheckResultsSink=

‎src/fsharp/NameResolution.fsi‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,17 @@ type internal TcSymbolUses =
312312

313313
/// Represents open declaration statement.
314314
type internal OpenDeclaration=
315-
/// Ordinary open declaration, i.e. one which opens a namespace or module.
316-
| OpenoflongId:Identlist*moduleRefs:ModuleOrNamespaceReflist*appliedScope:range
317-
/// Syntethic open declaration generated for auto open modules.
318-
| AutoOpenModuleofidents:stringlist*moduleRef:ModuleOrNamespaceRef*appliedScope:range
315+
{/// Idents.
316+
Idents:Ident list
317+
318+
/// Modules or namespaces which is opened with this declaration.
319+
ModuleRefs:ModuleOrNamespaceRef list
320+
321+
/// Scope in which open declaration is visible.
322+
AppliedScope:range}
323+
324+
/// Range of the open declaration.
325+
memberRange:range option
319326

320327
/// An abstract type for reporting the results of name resolution and type checking
321328
type ITypecheckResultsSink=

‎src/fsharp/TypeChecker.fs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ let OpenModulesOrNamespaces tcSink g amap scopem root env mvvs openDeclaration =
447447
ModifyNameResEnv (fun nenv -> AddModulesAndNamespacesContentsToNameEnv g amap env.eAccessRights scopem root nenv mvvs) env
448448
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
449449
CallOpenDeclarationSink tcSink openDeclaration
450+
match openDeclaration.Range with
451+
| None -> ()
452+
| Some range ->
453+
let item = Item.ModuleOrNamespaces mvvs
454+
CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
450455
env
451456

452457
let AddRootModuleOrNamespaceRefs g amap m env modrefs =
@@ -694,7 +699,7 @@ let ImplicitlyOpenOwnNamespace tcSink g amap scopem enclosingNamespacePath env =
694699
match ResolveLongIndentAsModuleOrNamespace ResultCollectionSettings.AllResults amap scopem OpenQualified env.eNameResEnv ad enclosingNamespacePathToOpen with
695700
| Result modrefs ->
696701
let modrefs = List.map p23 modrefs
697-
OpenModulesOrNamespaces tcSink g amap scopem false env modrefs(OpenDeclaration.Open (enclosingNamespacePathToOpen,modrefs,scopem))
702+
OpenModulesOrNamespaces tcSink g amap scopem false env modrefs{ Idents =enclosingNamespacePathToOpen; ModuleRefs =modrefs; AppliedScope =scopem }
698703
| Exception _ -> env
699704

700705

@@ -12074,7 +12079,7 @@ let TcOpenDecl tcSink (g:TcGlobals) amap m scopem env (longId : Ident list) =
1207412079
let modrefs = List.map p23 modrefs
1207512080
modrefs |> List.iter (fun modref -> CheckEntityAttributes g modref m |> CommitOperationResult)
1207612081

12077-
let env = OpenModulesOrNamespaces tcSink g amap scopem false env modrefs(OpenDeclaration.Open (longId,modrefs,scopem))
12082+
let env = OpenModulesOrNamespaces tcSink g amap scopem false env modrefs{ Idents =longId; ModuleRefs =modrefs; AppliedScope =scopem }
1207812083
env
1207912084

1208012085

@@ -16839,7 +16844,7 @@ let ApplyAssemblyLevelAutoOpenAttributeToTcEnv g amap (ccu: CcuThunk) scopem env
1683916844
let modref = mkNonLocalTyconRef (mkNonLocalEntityRef ccu (Array.ofList h)) t
1684016845
match modref.TryDeref with
1684116846
| VNone -> warn()
16842-
| VSome _ -> OpenModulesOrNamespaces TcResultsSink.NoSink g amap scopem root env [modref](OpenDeclaration.AutoOpenModule (p,modref,scopem))
16847+
| VSome _ -> OpenModulesOrNamespaces TcResultsSink.NoSink g amap scopem root env [modref]{ Idents = []; ModuleRefs = [modref]; AppliedScope =scopem }
1684316848

1684416849
// Add the CCU and apply the "AutoOpen" attributes
1684516850
let AddCcuToTcEnv(g, amap, scopem, env, assemblyName, ccu, autoOpens, internalsVisible) =

‎src/fsharp/symbols/Symbols.fs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,10 +2269,10 @@ type FSharpSymbol with
22692269

22702270
/// Represents open declaration in F# code.
22712271
typeFSharpOpenDeclaration=
2272-
/// Ordinary open declaration, i.e. one which opens a namespace or module.
2273-
| OpenoflongId:Identlist*modules:FSharpEntitylist*appliedScope:range
2274-
/// Syntethic open declaration generated for auto open modules.
2275-
| AutoOpenModuleofidents:stringlist*modul:FSharpEntity*appliedScope:range
2272+
{ LongId:Ident list
2273+
Range:range option
2274+
Modules:FSharpEntity list
2275+
AppliedScope:range}
22762276

22772277
[<Sealed>]
22782278
typeFSharpSymbolUse(g:TcGlobals,denv: DisplayEnv,symbol:FSharpSymbol,itemOcc,range: range)=

‎src/fsharp/symbols/Symbols.fsi‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,17 @@ type FSharpOpenDeclaration =
10751075
#else
10761076
typeinternalFSharpOpenDeclaration=
10771077
#endif
1078-
/// Ordinary open declaration, i.e. one which opens a namespace or module.
1079-
| OpenoflongId:Identlist*modules:FSharpEntitylist*appliedScope:range
1080-
/// Syntethic open declaration generated for auto open modules.
1081-
| AutoOpenModuleofidents:stringlist*modul:FSharpEntity*appliedScope:range
1078+
{/// Idents.
1079+
LongId:Ident list
1080+
1081+
/// Range of the open declaration.
1082+
Range:range option
1083+
1084+
/// Modules or namespaces which is opened with this declaration.
1085+
Modules:FSharpEntity list
1086+
1087+
/// Scope in which open declaration is visible.
1088+
AppliedScope:range}
10821089

10831090
/// Represents the use of an F# symbol from F# source code
10841091
[<Sealed>]

‎src/fsharp/vs/ServiceAnalysis.fs‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,23 @@ module UnusedOpens =
5252

5353
letgetOpenStatements(openDeclarations:FSharpOpenDeclaration list):OpenStatement list=
5454
openDeclarations
55-
|> List.choose(funopenDeclaration->
56-
matchopenDeclarationwith
57-
|FSharpOpenDeclaration.Open((firstId::_)as longId, modules, appliedScope)->
55+
|> List.choose(funopenDecl->
56+
matchopenDecl.LongId, openDecl.Rangewith
57+
| firstId::_, Some range->
5858
Some{ Idents=
59-
modules
59+
openDecl.Modules
6060
|> List.choose(fun x-> x.TryFullName|> Option.map(fun fullName-> x, fullName))
6161
|> List.collect(fun(modul,fullName)->
6262
[yield fullName
6363
if modul.HasFSharpModuleSuffixthen
6464
yield fullName.[..fullName.Length-7]// "Module" length plus zero index correction
6565
])
6666
|> Set.ofList
67-
Modules= modules
68-
Range=
69-
letlastId= List.last longId
70-
mkRange appliedScope.FileName firstId.idRange.Start lastId.idRange.End
71-
AppliedScope= appliedScope
67+
Modules= openDecl.Modules
68+
Range= range
69+
AppliedScope= openDecl.AppliedScope
7270
IsGlobal= firstId.idText= MangledGlobalName}
73-
|_-> None// for now
74-
)
71+
|_-> None)
7572

7673
letfilterSymbolUses(getSourceLineStr:int->string)(symbolUses:FSharpSymbolUse[]):FSharpSymbolUse[]=
7774
symbolUses

‎src/fsharp/vs/service.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,11 +2036,11 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
20362036
scopeOptX
20372037
|> Option.map(fun scope->
20382038
letcenv= Impl.cenv(scope.TcGlobals, scope.ThisCcu, scope.TcImports)
2039-
scope.OpenDeclarations|> List.map(function
2040-
| OpenDeclaration.Open(id, mods, appliedScope)->
2041-
FSharpOpenDeclaration.Open(id, mods|> List.map(fun x-> FSharpEntity(cenv, x)), appliedScope)
2042-
| OpenDeclaration.AutoOpenModule(ids, modul, appliedScope)->
2043-
FSharpOpenDeclaration.AutoOpenModule(ids, FSharpEntity(cenv, modul), appliedScope)))
2039+
scope.OpenDeclarations|> List.map(fun x->
2040+
{ LongId= x.Idents
2041+
Range= x.Range
2042+
Modules= x.ModuleRefs|> List.map(fun x-> FSharpEntity(cenv, x))
2043+
AppliedScope= x.AppliedScope}))
20442044
|> Option.defaultValue[]
20452045

20462046
overrideinfo.ToString()="FSharpCheckFileResults("+ filename+")"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp