Interface GuardClauseProvider<T>

A provider that can be registered to handle the creation of guard clauses.

interface GuardClauseProvider<T> {
    appendSyntaxNode(
        context: DocumentContext,
        edit: TextEditorEdit,
        node: UpdatedSyntaxNode<T>,
        root: RefSyntaxNode<T>,
    ): void;
    insertSyntaxNodeAfter(
        context: DocumentContext,
        edit: TextEditorEdit,
        node: UpdatedSyntaxNode<T>,
        after: RefSyntaxNode<T>,
    ): void;
    insertSyntaxNodeBefore(
        context: DocumentContext,
        edit: TextEditorEdit,
        node: UpdatedSyntaxNode<T>,
        before: RefSyntaxNode<T>,
    ): void;
    prependSyntaxNode(
        context: DocumentContext,
        edit: TextEditorEdit,
        node: UpdatedSyntaxNode<T>,
        root: RefSyntaxNode<T>,
    ): void;
    provideConditions(
        context: DocumentContext,
        range?: Range,
    ): ProviderResult<(RefSyntaxNode<T> & ExpressionContext<T>)[]>;
    removeCondition(
        context: DocumentContext,
        edit: TextEditorEdit,
        condition: RefSyntaxNode<T> & ExpressionContext<T>,
    ): void;
    replaceCondition(
        context: DocumentContext,
        edit: TextEditorEdit,
        original: RefSyntaxNode<T>,
        replace: UpdatedSyntaxNode<T>,
    ): void;
    resolveCondition(
        context: DocumentContext,
        condition: RefSyntaxNode<T> & ExpressionContext<T>,
    ): ProviderResult<RefSyntaxNode<T> & ExpressionContext<T>>;
}

Type Parameters

  • T

Hierarchy (View Summary)

Methods

  • Append the given syntax node to the root syntax node specified. This is usually an if statement used as a guard clause.

    Parameters

    • context: DocumentContext

      The context of the document in which to add the condition

    • edit: TextEditorEdit

      The edit builder to use to add the condition

    • node: UpdatedSyntaxNode<T>

      The syntax node to append (this may not contain any references and could need to be rebuilt)

    • root: RefSyntaxNode<T>

      The root syntax node to append to (this always contains a reference to the original syntax node)

    Returns void

  • Insert the given syntax node after the specified after syntax node. This is usually an if statement used as a guard clause.

    Parameters

    • context: DocumentContext

      The context of the document in which to add the condition

    • edit: TextEditorEdit

      The edit builder to use to add the condition

    • node: UpdatedSyntaxNode<T>

      The syntax node to insert (this may not contain any references and could need to be rebuilt)

    • after: RefSyntaxNode<T>

      The syntax node to insert after (this always contains a reference to the original syntax node)

    Returns void

  • Insert the given syntax node before the specified before syntax node. This is usually an if statement used as a guard clause.

    Parameters

    • context: DocumentContext

      The context of the document in which to add the condition

    • edit: TextEditorEdit

      The edit builder to use to add the condition

    • node: UpdatedSyntaxNode<T>

      The syntax node to insert (this may not contain any references and could need to be rebuilt)

    • before: RefSyntaxNode<T>

      The syntax node to insert before (this always contains a reference to the original syntax node)

    Returns void

  • Prepend the given syntax node to the root syntax node specified. This is usually an if statement used as a guard clause.

    Parameters

    • context: DocumentContext

      The context of the document in which to add the condition

    • edit: TextEditorEdit

      The edit builder to use to add the condition

    • node: UpdatedSyntaxNode<T>

      The syntax node to prepend (this may not contain any references and could need to be rebuilt)

    • root: RefSyntaxNode<T>

      The root syntax node to prepend to (this always contains a reference to the original syntax node)

    Returns void

  • Provide conditions for the given document and range. Only top-level conditions should be returned.

    Parameters

    • context: DocumentContext

      The context of the document for which to provide conditions

    • Optionalrange: Range

      The range for which to provide conditions. (the range may refer to a range inside an embedded section

    Returns ProviderResult<(RefSyntaxNode<T> & ExpressionContext<T>)[]>

    A list of conditions with references to the original syntax nodes. These must include additional information about the context in which the condition is used.

    // Given the following code:
    if ((a && b) || c) {
    d();
    if (e) f();
    }

    // The following conditions should be returned:
    (a && b) || c
    e

    DocumentContext)