Interface IIndexFileScannerContributor

All Known Implementing Classes:
RNCIndexFileScannerContributor

public interface IIndexFileScannerContributor
Extension point that allows XML plugins to contribute a custom file scanner for non-XML grammar formats to the workspace index.

The default index scanner understands XML-based formats (XSD, RNG, DTD, WSDL…). Implement this interface to handle grammar files whose syntax is not XML — for example, RELAX NG Compact Syntax (RNC) — so that their include and external directives are captured by the workspace Bloom index.

Register your implementation in IXMLExtension.start(org.eclipse.lsp4j.InitializeParams, org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry) via XMLExtensionsRegistry.registerIndexFileScannerContributor(org.eclipse.lemminx.services.extensions.IIndexFileScannerContributor).

When the workspace index needs to scan a file, it asks each registered contributor in order whether it canScan(java.nio.file.Path) the file. The first contributor that accepts it performs the scan; the XML scanner is used as the fallback for all other files.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canScan(Path path)
    Returns true if this contributor can scan the given file.
    default String
    Returns the in-memory text content of the given URI if the file is currently open in the editor and tracked by this contributor, or null if the file is not open or this contributor does not track open documents.
    default void
    scan(String content, Path path, List<GrammarReference> refs, Set<String> names)
    Scans the given in-memory content and populates refs and names.
    boolean
    scan(Path path, int maxChars, List<GrammarReference> refs, Set<String> names)
    Scans the file and populates refs and names.
  • Method Details

    • canScan

      boolean canScan(Path path)
      Returns true if this contributor can scan the given file.

      Implementations typically check the file extension. The check must be cheap (no I/O).

      Parameters:
      path - the absolute path of the file to be indexed.
      Returns:
      true to claim the file; false to pass.
    • scan

      boolean scan(Path path, int maxChars, List<GrammarReference> refs, Set<String> names) throws IOException
      Scans the file and populates refs and names.

      The scan must be streaming: never load the whole file into memory. Stop reading after maxChars characters and return true to signal that the file is only partially indexed.

      Parameters:
      path - the absolute path of the file to scan.
      maxChars - maximum characters to consume; Integer.MAX_VALUE means no limit.
      refs - output — located grammar references with line/column positions.
      names - output — token names for the Bloom filter.
      Returns:
      true if scanning stopped early due to maxChars.
      Throws:
      IOException - if the file cannot be opened or read.
    • scan

      default void scan(String content, Path path, List<GrammarReference> refs, Set<String> names) throws IOException
      Scans the given in-memory content and populates refs and names.

      Called when the file is open in the editor with unsaved changes, so that reference positions stay accurate even before the file is saved and the workspace index is re-indexed. The default implementation falls back to scan(Path, int, List, Set), ignoring the in-memory content.

      Parameters:
      content - in-memory file content (may differ from disk).
      path - absolute path of the file (used for resolving relative references).
      refs - output — located grammar references with line/column positions.
      names - output — token names for the Bloom filter.
      Throws:
      IOException - if the fallback disk scan fails.
    • getOpenDocumentContent

      default String getOpenDocumentContent(String uri)
      Returns the in-memory text content of the given URI if the file is currently open in the editor and tracked by this contributor, or null if the file is not open or this contributor does not track open documents.

      The default implementation returns null. Override to supply live content from the contributor's own text-document service so that reference positions remain accurate for files with unsaved edits.

      Parameters:
      uri - the document URI to look up.
      Returns:
      live content, or null if unavailable.