Langium - v4.0.0
    Preparing search index...

    Class AbstractFormatterAbstract

    Language specific service for handling formatting related LSP requests.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    collector: FormattingCollector = ...

    Accessors

    • get formatOnTypeOptions(): undefined | DocumentOnTypeFormattingOptions

      Options that determine when the formatDocumentOnType method should be invoked by the language client. When undefined is returned, document format on type will be disabled.

      Returns undefined | DocumentOnTypeFormattingOptions

    Methods

    • Creates a formatter scoped to the supplied AST node. Allows to define fine-grained formatting rules for elements.

      Example usage:

      export class CustomFormatter extends AbstractFormatter {
      protected override format(node: AstNode): void {
      if (isPerson(node)) {
      const formatter = this.getNodeFormatter(node);
      formatter.property('name').prepend(Formatting.oneSpace());
      }
      }
      }

      Type Parameters

      Parameters

      • node: T

        The specific node the formatter should be scoped to. Every call to properties or keywords will only select those which belong to the supplied AST node.

      Returns NodeFormatter<T>

    • Returns whether a range for a given document is error free, i.e. safe to format

      Parameters

      • document: LangiumDocument

        Document to inspect for lexer & parser errors that may produce an unsafe range

      • range: Range

        Formatting range to check for safety

      Returns boolean

      Whether the given formatting range does not overlap with or follow any regions with an error