From 88c743fb13077323a4cccff12a8e2cc1c0be0e8b Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 14 Nov 2023 11:39:32 +0100 Subject: [PATCH 1/4] Walk SynModuleSigDecl.Types --- src/FSharp.Analyzers.SDK/ASTCollecting.fs | 18 +++++- src/FSharp.Analyzers.SDK/ASTCollecting.fsi | 66 +++++++++++----------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/FSharp.Analyzers.SDK/ASTCollecting.fs b/src/FSharp.Analyzers.SDK/ASTCollecting.fs index 9194e24..b06772f 100644 --- a/src/FSharp.Analyzers.SDK/ASTCollecting.fs +++ b/src/FSharp.Analyzers.SDK/ASTCollecting.fs @@ -96,6 +96,8 @@ module ASTCollecting = default _.WalkTypeDefnRepr typeDefnRepr = () abstract WalkTypeDefn: SynTypeDefn -> unit default _.WalkTypeDefn typeDefn = () + abstract WalkTypeDefnSig: typeDefn: SynTypeDefnSig -> unit + default _.WalkTypeDefnSig typeDefn = () let walkAst (walker: SyntaxCollectorBase) (input: ParsedInput) : unit = @@ -562,6 +564,20 @@ module ASTCollecting = Option.iter walkMember implicitCtor List.iter walkMember members + and walkTypeDefnSig (SynTypeDefnSig(info, repr, members, r, _) as s) = + walker.WalkTypeDefnSig s + + let isTypeExtensionOrAlias = + match repr with + | SynTypeDefnSigRepr.ObjectModel(kind = SynTypeDefnKind.Augmentation _) + | SynTypeDefnSigRepr.ObjectModel(kind = SynTypeDefnKind.Abbrev) + | SynTypeDefnSigRepr.Simple(repr = SynTypeDefnSimpleRepr.TypeAbbrev _) -> true + | _ -> false + + walkComponentInfo isTypeExtensionOrAlias info + walkTypeDefnSigRepr repr + List.iter walkMemberSig members + and walkSynModuleDecl (decl: SynModuleDecl) = walker.WalkSynModuleDecl decl @@ -587,7 +603,7 @@ module ASTCollecting = | SynModuleSigDecl.ModuleAbbrev _ -> () | SynModuleSigDecl.NestedModule _ -> () | SynModuleSigDecl.Val(s, _range) -> walkValSig s - | SynModuleSigDecl.Types _ -> () + | SynModuleSigDecl.Types(types, _) -> List.iter walkTypeDefnSig types | SynModuleSigDecl.Exception _ -> () | SynModuleSigDecl.Open _ -> () | SynModuleSigDecl.HashDirective _ -> () diff --git a/src/FSharp.Analyzers.SDK/ASTCollecting.fsi b/src/FSharp.Analyzers.SDK/ASTCollecting.fsi index c1b468a..67048a4 100644 --- a/src/FSharp.Analyzers.SDK/ASTCollecting.fsi +++ b/src/FSharp.Analyzers.SDK/ASTCollecting.fsi @@ -10,127 +10,129 @@ module ASTCollecting = /// Overwriting this member hooks up a custom operation for a module or namespace syntax element. abstract WalkSynModuleOrNamespace: moduleOrNamespace: SynModuleOrNamespace -> unit - default WalkSynModuleOrNamespace: moduleOrNamespace: FSharp.Compiler.Syntax.SynModuleOrNamespace -> unit + default WalkSynModuleOrNamespace: moduleOrNamespace: SynModuleOrNamespace -> unit /// Overwriting this member hooks up a custom operation for a module or namespace syntax element in a signature file. abstract WalkSynModuleOrNamespaceSig: moduleOrNamespaceSig: SynModuleOrNamespaceSig -> unit - default WalkSynModuleOrNamespaceSig: - moduleOrNamespaceSig: FSharp.Compiler.Syntax.SynModuleOrNamespaceSig -> unit + default WalkSynModuleOrNamespaceSig: moduleOrNamespaceSig: SynModuleOrNamespaceSig -> unit /// Overwriting this member hooks up a custom operation for an attribute. abstract WalkAttribute: attribute: SynAttribute -> unit - default WalkAttribute: attribute: FSharp.Compiler.Syntax.SynAttribute -> unit + default WalkAttribute: attribute: SynAttribute -> unit /// Overwriting this member hooks up a custom operation for declarations inside a module. abstract WalkSynModuleDecl: moduleDecl: SynModuleDecl -> unit - default WalkSynModuleDecl: moduleDecl: FSharp.Compiler.Syntax.SynModuleDecl -> unit + default WalkSynModuleDecl: moduleDecl: SynModuleDecl -> unit /// Overwriting this member hooks up a custom operation for declarations inside a module or namespace in a signature file. abstract WalkSynModuleSigDecl: moduleSigDecl: SynModuleSigDecl -> unit - default WalkSynModuleSigDecl: moduleSigDecl: FSharp.Compiler.Syntax.SynModuleSigDecl -> unit + default WalkSynModuleSigDecl: moduleSigDecl: SynModuleSigDecl -> unit /// Overwriting this member hooks up a custom operation for syntax expressions. abstract WalkExpr: expr: SynExpr -> unit - default WalkExpr: expr: FSharp.Compiler.Syntax.SynExpr -> unit + default WalkExpr: expr: SynExpr -> unit /// Overwriting this member hooks up a custom operation for type parameters. abstract WalkTypar: typar: SynTypar -> unit - default WalkTypar: typar: FSharp.Compiler.Syntax.SynTypar -> unit + default WalkTypar: typar: SynTypar -> unit /// Overwriting this member hooks up a custom operation for explicit declarations of type parameters. abstract WalkTyparDecl: typarDecl: SynTyparDecl -> unit - default WalkTyparDecl: typarDecl: FSharp.Compiler.Syntax.SynTyparDecl -> unit + default WalkTyparDecl: typarDecl: SynTyparDecl -> unit /// Overwriting this member hooks up a custom operation for type constraints. abstract WalkTypeConstraint: typeConstraint: SynTypeConstraint -> unit - default WalkTypeConstraint: typeConstraint: FSharp.Compiler.Syntax.SynTypeConstraint -> unit + default WalkTypeConstraint: typeConstraint: SynTypeConstraint -> unit /// Overwriting this member hooks up a custom operation for types. abstract WalkType: ``type``: SynType -> unit - default WalkType: ``type``: FSharp.Compiler.Syntax.SynType -> unit + default WalkType: ``type``: SynType -> unit /// Overwriting this member hooks up a custom operation for member signatures. abstract WalkMemberSig: memberSig: SynMemberSig -> unit - default WalkMemberSig: memberSig: FSharp.Compiler.Syntax.SynMemberSig -> unit + default WalkMemberSig: memberSig: SynMemberSig -> unit /// Overwriting this member hooks up a custom operation for F# patterns. abstract WalkPat: pat: SynPat -> unit - default WalkPat: pat: FSharp.Compiler.Syntax.SynPat -> unit + default WalkPat: pat: SynPat -> unit /// Overwriting this member hooks up a custom operation for type parameters for a member of function. abstract WalkValTyparDecls: valTyparDecls: SynValTyparDecls -> unit - default WalkValTyparDecls: valTyparDecls: FSharp.Compiler.Syntax.SynValTyparDecls -> unit + default WalkValTyparDecls: valTyparDecls: SynValTyparDecls -> unit /// Overwriting this member hooks up a custom operation for a binding of a 'let' or 'member' declaration. abstract WalkBinding: binding: SynBinding -> unit - default WalkBinding: binding: FSharp.Compiler.Syntax.SynBinding -> unit + default WalkBinding: binding: SynBinding -> unit /// Overwriting this member hooks up a custom operation for simple F# patterns. abstract WalkSimplePat: simplePat: SynSimplePat -> unit - default WalkSimplePat: simplePat: FSharp.Compiler.Syntax.SynSimplePat -> unit + default WalkSimplePat: simplePat: SynSimplePat -> unit /// Overwriting this member hooks up a custom operation for interface implementations. abstract WalkInterfaceImpl: interfaceImpl: SynInterfaceImpl -> unit - default WalkInterfaceImpl: interfaceImpl: FSharp.Compiler.Syntax.SynInterfaceImpl -> unit + default WalkInterfaceImpl: interfaceImpl: SynInterfaceImpl -> unit /// Overwriting this member hooks up a custom operation for clauses in a 'match' expression. abstract WalkClause: matchClause: SynMatchClause -> unit - default WalkClause: matchClause: FSharp.Compiler.Syntax.SynMatchClause -> unit + default WalkClause: matchClause: SynMatchClause -> unit /// Overwriting this member hooks up a custom operation for the parts of an interpolated string. abstract WalkInterpolatedStringPart: interpolatedStringPart: SynInterpolatedStringPart -> unit - default WalkInterpolatedStringPart: - interpolatedStringPart: FSharp.Compiler.Syntax.SynInterpolatedStringPart -> unit + default WalkInterpolatedStringPart: interpolatedStringPart: SynInterpolatedStringPart -> unit /// Overwriting this member hooks up a custom operation for units of measure annotations. abstract WalkMeasure: measure: SynMeasure -> unit - default WalkMeasure: measure: FSharp.Compiler.Syntax.SynMeasure -> unit + default WalkMeasure: measure: SynMeasure -> unit /// Overwriting this member hooks up a custom operation for the name of a type definition or module. abstract WalkComponentInfo: componentInfo: SynComponentInfo -> unit - default WalkComponentInfo: componentInfo: FSharp.Compiler.Syntax.SynComponentInfo -> unit + default WalkComponentInfo: componentInfo: SynComponentInfo -> unit /// Overwriting this member hooks up a custom operation for the right-hand-side of a type definition. abstract WalkTypeDefnSigRepr: typeDefnSigRepr: SynTypeDefnSigRepr -> unit - default WalkTypeDefnSigRepr: typeDefnSigRepr: FSharp.Compiler.Syntax.SynTypeDefnSigRepr -> unit + default WalkTypeDefnSigRepr: typeDefnSigRepr: SynTypeDefnSigRepr -> unit /// Overwriting this member hooks up a custom operation for the right-hand-side of union definition, excluding members. abstract WalkUnionCaseType: unionCaseKind: SynUnionCaseKind -> unit - default WalkUnionCaseType: unionCaseKind: FSharp.Compiler.Syntax.SynUnionCaseKind -> unit + default WalkUnionCaseType: unionCaseKind: SynUnionCaseKind -> unit /// Overwriting this member hooks up a custom operation for the cases of an enum definition. abstract WalkEnumCase: enumCase: SynEnumCase -> unit - default WalkEnumCase: enumCase: FSharp.Compiler.Syntax.SynEnumCase -> unit + default WalkEnumCase: enumCase: SynEnumCase -> unit /// Overwriting this member hooks up a custom operation for field declarations in a record or class. abstract WalkField: field: SynField -> unit - default WalkField: field: FSharp.Compiler.Syntax.SynField -> unit + default WalkField: field: SynField -> unit /// Overwriting this member hooks up a custom operation for the core of a simple type definition. abstract WalkTypeDefnSimple: typeDefnSimpleRepr: SynTypeDefnSimpleRepr -> unit - default WalkTypeDefnSimple: typeDefnSimpleRepr: FSharp.Compiler.Syntax.SynTypeDefnSimpleRepr -> unit + default WalkTypeDefnSimple: typeDefnSimpleRepr: SynTypeDefnSimpleRepr -> unit /// Overwriting this member hooks up a custom operation for a 'val' definition in an abstract slot or a signature file. abstract WalkValSig: valSig: SynValSig -> unit - default WalkValSig: valSig: FSharp.Compiler.Syntax.SynValSig -> unit + default WalkValSig: valSig: SynValSig -> unit /// Overwriting this member hooks up a custom operation for an element within a type definition. abstract WalkMember: memberDefn: SynMemberDefn -> unit - default WalkMember: memberDefn: FSharp.Compiler.Syntax.SynMemberDefn -> unit + default WalkMember: memberDefn: SynMemberDefn -> unit /// Overwriting this member hooks up a custom operation for the cases of an union definition. abstract WalkUnionCase: unionCase: SynUnionCase -> unit - default WalkUnionCase: unionCase: FSharp.Compiler.Syntax.SynUnionCase -> unit + default WalkUnionCase: unionCase: SynUnionCase -> unit /// Overwriting this member hooks up a custom operation for the right hand side of a type or exception declaration. abstract WalkTypeDefnRepr: typeDefnRepr: SynTypeDefnRepr -> unit - default WalkTypeDefnRepr: typeDefnRepr: FSharp.Compiler.Syntax.SynTypeDefnRepr -> unit + default WalkTypeDefnRepr: typeDefnRepr: SynTypeDefnRepr -> unit /// Overwriting this member hooks up a custom operation for a type or exception declaration. abstract WalkTypeDefn: typeDefn: SynTypeDefn -> unit - default WalkTypeDefn: typeDefn: FSharp.Compiler.Syntax.SynTypeDefn -> unit + default WalkTypeDefn: typeDefn: SynTypeDefn -> unit + + /// Overwriting this member hooks up a custom operation for a type or exception signature declaration. + abstract WalkTypeDefnSig: typeDefn: SynTypeDefnSig -> unit + default WalkTypeDefnSig: typeDefn: SynTypeDefnSig -> unit /// Traverses the whole AST and calls the appropriate members of the given SyntaxCollectorBase /// to process the syntax elements. From 40c9b51efd502d3d66d54a6cb5378b49968b9b88 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 14 Nov 2023 11:41:04 +0100 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6720b81..81f283e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.20.1] - 2023-11-14 + +### Fixed +* [Extend signature AST walking](https://github.com/ionide/FSharp.Analyzers.SDK/pull/161) (thanks @nojaf!) + ## [0.20.0] - 2023-11-13 ### Fixed From 651ca2e37ddfb744aff8c975fd725e1eacc2b2ea Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 14 Nov 2023 11:41:58 +0100 Subject: [PATCH 3/4] Walk UnionCase in SynModuleSigDecl.Exception --- src/FSharp.Analyzers.SDK/ASTCollecting.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FSharp.Analyzers.SDK/ASTCollecting.fs b/src/FSharp.Analyzers.SDK/ASTCollecting.fs index b06772f..4db3f23 100644 --- a/src/FSharp.Analyzers.SDK/ASTCollecting.fs +++ b/src/FSharp.Analyzers.SDK/ASTCollecting.fs @@ -604,7 +604,8 @@ module ASTCollecting = | SynModuleSigDecl.NestedModule _ -> () | SynModuleSigDecl.Val(s, _range) -> walkValSig s | SynModuleSigDecl.Types(types, _) -> List.iter walkTypeDefnSig types - | SynModuleSigDecl.Exception _ -> () + | SynModuleSigDecl.Exception(exnSig = SynExceptionSig(exnRepr = SynExceptionDefnRepr(caseName = unionCase))) -> + walkUnionCase unionCase | SynModuleSigDecl.Open _ -> () | SynModuleSigDecl.HashDirective _ -> () | SynModuleSigDecl.NamespaceFragment _ -> () From 069287d41fe3e013db5ae3445a10c56baddeb5ef Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 14 Nov 2023 11:42:59 +0100 Subject: [PATCH 4/4] Walk SynModuleSigDecl.NestedModule --- src/FSharp.Analyzers.SDK/ASTCollecting.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FSharp.Analyzers.SDK/ASTCollecting.fs b/src/FSharp.Analyzers.SDK/ASTCollecting.fs index 4db3f23..2c82266 100644 --- a/src/FSharp.Analyzers.SDK/ASTCollecting.fs +++ b/src/FSharp.Analyzers.SDK/ASTCollecting.fs @@ -601,7 +601,9 @@ module ASTCollecting = match decl with | SynModuleSigDecl.ModuleAbbrev _ -> () - | SynModuleSigDecl.NestedModule _ -> () + | SynModuleSigDecl.NestedModule(moduleInfo = info; moduleDecls = decls) -> + walkComponentInfo false info + List.iter walkSynModuleSigDecl decls | SynModuleSigDecl.Val(s, _range) -> walkValSig s | SynModuleSigDecl.Types(types, _) -> List.iter walkTypeDefnSig types | SynModuleSigDecl.Exception(exnSig = SynExceptionSig(exnRepr = SynExceptionDefnRepr(caseName = unionCase))) ->