Provides methods to generate links, code snippets, and documentation for code elements. These wrap around a collection of useful helpers originating from the doc utils. To create an instance, use makeDocContextForTypes (although if you are writing a wiki, you get such an instance).

interface GeneralDocContext {
    cliOption<
        ScriptName extends
            | "slicer"
            | "stats"
            | "benchmark"
            | "summarizer"
            | "export-quads"
            | "stats-helper"
            | "benchmark-helper"
            | "flowr",
        OptionName extends string,
    >(
        scriptName: ScriptName,
        optionName: OptionName,
        withAlias?: boolean,
        quote?: boolean,
    ): string;
    code(
        element: ElementIdOrRef,
        fmt?: Omit<FnElementInfo, "info" | "program">,
        filter?: ElementFilter,
    ): string;
    doc(element: ElementIdOrRef, filter?: Omit<ElementFilter, "file">): string;
    header(filename: string, purpose: string): Promise<string>;
    hierarchy(
        element: ElementIdOrRef,
        fmt?: Omit<PrintHierarchyArguments, "info" | "root" | "program">,
        filter?: ElementFilter,
    ): string;
    link(
        element: ElementIdOrRef,
        fmt?: LinkFormat,
        filter?: ElementFilter,
    ): string;
    linkCode(path: PathLike, lineNumber?: number): string;
    linkFile(element: ElementIdOrRef): string;
    linkM<T extends NamedPrototype>(
        cls: T,
        element: ProtoKeys<T> | StaticKeys<T>,
        fmt?: LinkFormat & { hideClass?: boolean },
        filter?: ElementFilter,
    ): string;
    linkPage(
        pageName:
            | ""
            | "wiki/FAQ"
            | "wiki/Search API"
            | "wiki/Control Flow Graph"
            | "wiki/Query API"
            | "wiki/Onboarding"
            | "wiki/Analyzer"
            | "wiki/Engines"
            | "wiki/Normalized AST"
            | "wiki/Core"
            | "wiki/Setup"
            | "wiki/Overview"
            | "wiki/Interface"
            | "wiki/Dataflow Graph"
            | "wiki/Linting and Testing"
            | "wiki/Linter"
            | "README"
            | "wiki/Capabilities",
        linkText?: string,
    ): string;
    mermaid(element: ElementIdOrRef, inlineTypes?: string[]): string;
    replCmd(
        commandName: ReplCommandNames,
        quote?: boolean,
        showStar?: boolean,
    ): string;
}

Methods

  • Generates the CLI long option for a given script and option name.

    Type Parameters

    • ScriptName extends
          | "slicer"
          | "stats"
          | "benchmark"
          | "summarizer"
          | "export-quads"
          | "stats-helper"
          | "benchmark-helper"
          | "flowr"
    • OptionName extends string

    Parameters

    • scriptName: ScriptName

      The name of the script (e.g., 'flowr', 'analyze', etc.)

    • optionName: OptionName

      The name of the option for which to generate the long option string.

    • OptionalwithAlias: boolean

      Whether to include the alias in the output. Default is false.

    • Optionalquote: boolean

      Whether to wrap the option in backticks. Default is true.

    Returns string

    cliOption('flowr', 'help')
    

    Returns --help with the accompanying docs.

  • Returns the code snippet for a code element as markdown string.

    Parameters

    • element: ElementIdOrRef

      The element to create a code snippet for, the name can be qualified with :: to specify the class.

    • Optionalfmt: Omit<FnElementInfo, "info" | "program">

      Formatting options for the code snippet (see FnElementInfo)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to get the code for, in case multiple elements with the same name exist.

    Returns string

    code(exampleFn.name, { dropLinesStart: 1, dropLinesEnd: 2  })
    

    Creates a code snippet for the exampleFn function in the code base, dropping the first and last two lines of the function definition. If, for example, the function looks like this:

    function exampleFn(a: number, b: number): number {
    // This is an example
    const result = a + b;
    return result;
    }

    The resulting code snippet will be (auto-gobbled by default):

    // This is an example
    const result = a + b;

    printCodeOfElement - for the underlying impl.

  • Returns the documentation for a code element as markdown string. If you want to, e.g., prefix all of these lines with indentation or > for blockquotes, use prefixLines.

    Parameters

    • element: ElementIdOrRef

      The element to create documentation for, the name can be qualified with :: to specify the class.

    • Optionalfilter: Omit<ElementFilter, "file">

      An optional filter to further specify the element to get the documentation for, in case multiple elements with the same name exist.

    Returns string

    doc(exampleFn.name)
    

    Creates the documentation for the exampleFn function in the code base as markdown string.

    • getDocumentationForType - for the underlying impl.
    • removeCommentSymbolsFromTypeScriptComment - to clean up TS doc comments.
  • Generates an auto-generation header for the wiki page.

    Parameters

    • filename: string

      The name of the file being generated. Probably use module.filename.

    • purpose: string

      The purpose of the file, e.g., 'wiki context for types'.

    Returns Promise<string>

  • Returns the hierarchy (e.g., class inheritance) for a code element as markdown string, including their documentation and snippets.

    Parameters

    • element: ElementIdOrRef

      The element to create a hierarchy for, the name can be qualified with :: to specify the class.

    • Optionalfmt: Omit<PrintHierarchyArguments, "info" | "root" | "program">

      Formatting options for the hierarchy (see PrintHierarchyArguments)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to get the hierarchy for, in case multiple elements with the same name exist.

    Returns string

    hierarchy(MyClass.name, { maxDepth: 2 })
    

    Creates the hierarchy for the MyClass class in the code base, including up to two levels of inheritance.

    printHierarchy - for the underlying impl.

  • Generate a hyperlink to a code element in the wiki. If you want to reference the member of a class, use ClassName::MemberName as element name. For ease of use, you can also call linkM to create a link to a member.

    Parameters

    • element: ElementIdOrRef

      The element to create a link for, the name can be qualified with :: to specify the class. This causes the link to be usually printed as ClassName::ElementName. If you want to avoid showing the class name, use ::: as separator. Please note that for elements with a sensible (.name), you can also pass the function/constructor reference directly (e.g., link(MyClass)).

    • Optionalfmt: LinkFormat

      Formatting options for the link (see LinkFormat)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to link to, in case multiple elements with the same name exist.

    Returns string

    link(registerPluginMaker.name)
    

    Creates a (markdown) link to the registerPluginMaker function in the code base and, if available, attaches the TS documentation as tooltip. By using the .name, the link text will be registerPluginMaker but respect, e.g., renaming refactorings done in the code base.

    • linkFile - to create a link using the file path as name.
    • shortLink - for the underlying impl.
    • dropGenericsFromTypeName - to clean up type names for display.
  • Generates a link to a code file in the code base.

    Parameters

    • path: PathLike

      The path to the code file.

    • OptionallineNumber: number

      An optional line number to link to within the file.

    Returns string

  • Generate a hyperlink to a type/element definition in the code base which is displayed using the file path as name

    Parameters

    • element: ElementIdOrRef

      The element to create a link for, the name can be qualified with :: to specify the class.

    Returns string

    linkFile(registerPluginMaker.name)
    

    Creates a (markdown) link to the registerPluginMaker function in the code base using the file path as link name.

    • GeneralWikiContext#link|link - to create a link with a custom name/using the type name by default.
    • linkFile - for the underlying impl.
  • Generates a wiki link to another wiki or general docs page.

    Parameters

    • pageName:
          | ""
          | "wiki/FAQ"
          | "wiki/Search API"
          | "wiki/Control Flow Graph"
          | "wiki/Query API"
          | "wiki/Onboarding"
          | "wiki/Analyzer"
          | "wiki/Engines"
          | "wiki/Normalized AST"
          | "wiki/Core"
          | "wiki/Setup"
          | "wiki/Overview"
          | "wiki/Interface"
          | "wiki/Dataflow Graph"
          | "wiki/Linting and Testing"
          | "wiki/Linter"
          | "README"
          | "wiki/Capabilities"

      The name of the wiki page to link to.

    • OptionallinkText: string

      Optional text to display for the link. If not provided, the page name will be used.

    Returns string

    linkWikiPage('wiki/Setup')
    

    Creates a link to the wiki/Setup wiki page with the link text Setup.

  • Generates a mermaid diagram for the given code element, returned as markdown string.

    Parameters

    • element: ElementIdOrRef

      The element to create a mermaid diagram for, the name can be qualified with :: to specify the class.

    • OptionalinlineTypes: string[]

      Optional list of type names to inline in the mermaid diagram (instead of linking them out).

    Returns string

  • Generates the REPL command string for a given command name.

    Parameters

    • commandName: ReplCommandNames

      The name of the REPL command.

    • Optionalquote: boolean

      Whether to wrap the command in backticks. Default is true.

    • OptionalshowStar: boolean

      Whether to show a [*] suffix for starred commands. Default is false.

    Returns string

    replCmd('help')
    

    Returns :help with the accompanying docs.

    getReplCommand - for the underlying impl.