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

Commit6fd8ddc

Browse files
dungpaKevinRansom
authored andcommitted
Suggest opening namespaces on attributes again (dotnet#2084)
1 parent185f872 commit6fd8ddc

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

‎src/fsharp/vs/ServiceAssemblyContent.fs‎

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ type EntityKind =
197197
| ModuleofModuleKind
198198
overridex.ToString()= sprintf"%A" x
199199

200+
[<RequireQualifiedAccess>]
201+
typeLookupType=
202+
| Fuzzy
203+
| Precise
204+
205+
[<NoComparison; NoEquality>]
200206
typeRawEntity=
201207
{/// Full entity name as it's seen in compiled code (raw FSharpEntity.FullName, FSharpValueOrFunction.FullName).
202208
FullName:string
@@ -208,7 +214,7 @@ type RawEntity =
208214
IsPublic:bool
209215
TopRequireQualifiedAccessParent:Idents option
210216
AutoOpenParent:Idents option
211-
Kind:EntityKind}
217+
Kind:LookupType->EntityKind}
212218
overridex.ToString()= sprintf"%A" x
213219

214220
typeAssemblyPath= string
@@ -271,27 +277,10 @@ module internal TypedAstPatterns =
271277
if ty.HasTypeDefinitionthen Some ty.TypeDefinition
272278
else None
273279

274-
// todo FSharpEntity.BaseType causes uncatchable error dialog in debug mode, it does not allow to test VFT at all.
275-
276-
//let (|Attribute|_|) (entity: FSharpEntity) =
277-
// let isAttribute (entity: FSharpEntity) =
278-
// let getBaseType (entity: FSharpEntity) =
279-
// try
280-
// match entity.BaseType with
281-
// | Some (TypeWithDefinition def) -> Some def
282-
// | _ -> None
283-
// with _ -> None
284-
285-
// let rec isAttributeType (ty: FSharpEntity option) =
286-
// match ty with
287-
// | None -> false
288-
// | Some ty ->
289-
// match ty.TryGetFullName() with
290-
// | None -> false
291-
// | Some fullName ->
292-
// fullName = "System.Attribute" || isAttributeType (getBaseType ty)
293-
// isAttributeType (Some entity)
294-
// if isAttribute entity then Some() else None
280+
let(|Attribute|_|)(entity:FSharpEntity)=
281+
letisAttribute(entity:FSharpEntity)=
282+
try entity.IsAttributeTypewith_->false
283+
if isAttribute entitythen Some()else None
295284

296285
let(|FSharpModule|_|)(entity:FSharpEntity)=if entity.IsFSharpModulethen Some()else None
297286

@@ -317,15 +306,19 @@ module internal AssemblyContentProvider =
317306
IsPublic= entity.Accessibility.IsPublic
318307
TopRequireQualifiedAccessParent= parent.RequiresQualifiedAccess|> Option.map parent.FixParentModuleSuffix
319308
AutoOpenParent= parent.AutoOpen|> Option.map parent.FixParentModuleSuffix
320-
Kind=
321-
match entitywith
322-
// see comment above about BaseType
323-
//| TypedAstPatterns.Attribute -> EntityKind.Attribute
324-
| TypedAstPatterns.FSharpModule->
309+
Kind=fun lookupType->
310+
match entity, lookupTypewith
311+
| TypedAstPatterns.FSharpModule,_->
325312
EntityKind.Module
326313
{ IsAutoOpen= hasAttribute<AutoOpenAttribute> entity.Attributes
327314
HasModuleSuffix= hasModuleSuffixAttribute entity}
328-
|_-> EntityKind.Type})
315+
|_, LookupType.Fuzzy->
316+
EntityKind.Type
317+
|_, LookupType.Precise->
318+
match entitywith
319+
| TypedAstPatterns.Attribute-> EntityKind.Attribute
320+
|_-> EntityKind.Type
321+
})
329322

330323
letprivatetraverseMemberFunctionAndValues ns(parent:Parent)(membersFunctionsAndValues:seq<FSharpMemberOrFunctionOrValue>)=
331324
membersFunctionsAndValues
@@ -338,7 +331,7 @@ module internal AssemblyContentProvider =
338331
TopRequireQualifiedAccessParent=
339332
parent.RequiresQualifiedAccess|> Option.map parent.FixParentModuleSuffix
340333
AutoOpenParent= parent.AutoOpen|> Option.map parent.FixParentModuleSuffix
341-
Kind= EntityKind.FunctionOrValue func.IsActivePattern}
334+
Kind=fun _->EntityKind.FunctionOrValue func.IsActivePattern}
342335

343336
[yield! func.TryGetFullDisplayName()
344337
|> Option.map(fun fullDisplayName-> processIdents func.FullName(fullDisplayName.Split'.'))
@@ -373,7 +366,7 @@ module internal AssemblyContentProvider =
373366
{ RequiresQualifiedAccess=
374367
parent.RequiresQualifiedAccess
375368
|> Option.orElse(
376-
if hasAttribute<RequireQualifiedAccessAttribute> entity.Attributesthen
369+
ifentity.IsFSharp&&hasAttribute<RequireQualifiedAccessAttribute> entity.Attributesthen
377370
parent.FormatEntityFullName entity|> Option.map snd
378371
else None)
379372
AutoOpen=
@@ -405,7 +398,7 @@ module internal AssemblyContentProvider =
405398
letgetAssemblySignatureContent contentType(signature:FSharpAssemblySignature)=
406399
signature.TryGetEntities()
407400
|> Seq.collect(traverseEntity contentType Parent.Empty)
408-
|> Seq.distinct
401+
|> Seq.distinctBy(fun{FullName=fullName;CleanedIdents=cleanIdents}->(fullName, cleanIdents))
409402

410403
letprivategetAssemblySignaturesContent contentType(assemblies:FSharpAssembly list)=
411404
assemblies

‎src/fsharp/vs/Symbols.fs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ and FSharpEntity(cenv:cenv, entity:EntityRef) =
397397
[for tyin AllInterfacesOfType cenv.g cenv.amap range0 AllowMultiIntfInstantiations.Yes(generalizedTyconRef entity)do
398398
yield FSharpType(cenv, ty)]
399399
|> makeReadOnlyCollection
400-
400+
401+
memberx.IsAttributeType=
402+
if isUnresolved()thenfalseelse
403+
letty= generalizedTyconRef entity
404+
Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_Attribute
405+
401406
memberx.BaseType=
402407
checkIsResolved()
403408
GetSuperTypeOfType cenv.g cenv.amap range0(generalizedTyconRef entity)

‎src/fsharp/vs/Symbols.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ and [<Class>] internal FSharpEntity =
244244
/// Get all the interface implementations, by walking the type hierarchy
245245
memberAllInterfaces:IList<FSharpType>
246246

247+
/// Check if the entity inherits from System.Attribute in its type hierarchy
248+
memberIsAttributeType:bool
249+
247250
/// Get the base type, if any
248251
memberBaseType:FSharpType option
249252

‎vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ type internal FSharpAddOpenCodeFixProvider
191191
[yield e.TopRequireQualifiedAccessParent, e.AutoOpenParent, e.Namespace, e.CleanedIdents
192192
if isAttributethen
193193
letlastIdent= e.CleanedIdents.[e.CleanedIdents.Length-1]
194-
ife.Kind= EntityKind.Attribute&&lastIdent.EndsWith"Attribute"then
194+
iflastIdent.EndsWith"Attribute"&&e.Kind LookupType.Precise= EntityKind.Attributethen
195195
yield
196196
e.TopRequireQualifiedAccessParent,
197197
e.AutoOpenParent,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp