Skip to content

Commit

Permalink
Walk SynModuleSigDecl.Types
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 14, 2023
1 parent 6ee40d2 commit 88c743f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
18 changes: 17 additions & 1 deletion src/FSharp.Analyzers.SDK/ASTCollecting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down Expand Up @@ -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

Expand All @@ -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 _ -> ()
Expand Down
66 changes: 34 additions & 32 deletions src/FSharp.Analyzers.SDK/ASTCollecting.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 88c743f

Please sign in to comment.