Class WorkspaceIndexReferenceParticipant

java.lang.Object
org.eclipse.lemminx.extensions.index.WorkspaceIndexReferenceParticipant
All Implemented Interfaces:
IReferenceParticipant

public class WorkspaceIndexReferenceParticipant extends Object implements IReferenceParticipant
Provides cross-file "Find References" using the workspace Bloom index.

Two entry points:

  • Cursor on a grammar reference attribute value (href, noNamespaceSchemaLocation, schemaLocation) in any XML file → returns all workspace files that reference that grammar.
  • Cursor anywhere in a grammar file (XSD, DTD, RNG, RNC) → returns all workspace XML files that reference the current grammar file.

Always-fresh positions: Reference positions are resolved via GrammarFileRenameSupport.resolveCurrentRefs(java.lang.String, java.nio.file.Path, java.nio.file.Path, java.util.List<org.eclipse.lemminx.extensions.index.GrammarReference>, java.util.function.Function<java.lang.String, java.lang.String>, java.util.List<org.eclipse.lemminx.services.extensions.IGrammarReferenceContributor>) which prefers live in-memory content (open files), falls back to on-disk content (closed files), and only uses cached bloom-index positions as a last resort. This ensures accurate Locations even when lines are added before the grammar reference or when a didChangeWatchedFiles re-index has not yet completed.

See Also:
  • Constructor Details

    • WorkspaceIndexReferenceParticipant

      public WorkspaceIndexReferenceParticipant(WorkspaceIndex workspaceIndex, Supplier<IXMLDocumentProvider> docProviderSupplier)
      Constructor used in production. The document-provider supplier is resolved lazily so that the participant can be created before the registry is fully initialized.
    • WorkspaceIndexReferenceParticipant

      public WorkspaceIndexReferenceParticipant(WorkspaceIndex workspaceIndex)
      Convenience constructor for tests that don't need open-document re-scan.
  • Method Details

    • findReference

      public void findReference(DOMDocument document, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.ReferenceContext context, List<org.eclipse.lsp4j.Location> locations, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds cross-file references using the workspace Bloom index.

      Case 1 — cursor on a grammar reference value: The user is in order.xml and positions the cursor inside the "schema.xsd" value of xsi:noNamespaceSchemaLocation="schema.xsd". This method extracts "schema.xsd" as the target and returns all workspace files that also reference it.

      Case 2 — cursor anywhere in a grammar file: The user opens schema.xsd and invokes "Find All References". This method detects that the current document is a grammar file, uses its filename as the target, and returns all XML files in the workspace that reference schema.xsd.

      Specified by:
      findReference in interface IReferenceParticipant
    • findReferenceByUri

      public CompletableFuture<List<org.eclipse.lsp4j.Location>> findReferenceByUri(String uri, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.ReferenceContext context, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Description copied from interface: IReferenceParticipant
      Find references for a document that is not currently open/managed, identified only by its URI. The returned future may resolve asynchronously (e.g. after a workspace index scan completes). Participants that do not depend on the DOM should override this method; the default returns an empty list immediately.
      Specified by:
      findReferenceByUri in interface IReferenceParticipant
    • collectCrossFileReferences

      public static List<org.eclipse.lsp4j.Location> collectCrossFileReferences(WorkspaceIndex index, Path targetPath, Function<String,String> openDocContent, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds all workspace files that reference targetPath and returns their exact Locations. Positions are always resolved from the freshest available content via GrammarFileRenameSupport.resolveCurrentRefs(java.lang.String, java.nio.file.Path, java.nio.file.Path, java.util.List<org.eclipse.lemminx.extensions.index.GrammarReference>, java.util.function.Function<java.lang.String, java.lang.String>, java.util.List<org.eclipse.lemminx.services.extensions.IGrammarReferenceContributor>): live in-memory content for open files, on-disk content for closed files, and cached bloom-index positions only as a last resort.

      Use case — open modified file: order.xml is open in the editor and the user added 2 lines before <?xml-model href="schema.xsd"?>. Live content is used → accurate line-3 Location is returned.

      Use case — recently saved file: order.xml was just saved and the didChangeWatchedFiles re-index has not yet completed. On-disk content is read directly, bypassing the potentially stale bloom-index positions.

      Parameters:
      index - the workspace Bloom index.
      targetPath - absolute path of the grammar file being queried.
      openDocContent - function mapping a URI to its in-memory content if the file is currently open, or returning null if closed. Pass null to skip the live-content step.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      all locations across the workspace that reference targetPath.
    • collectCrossFileReferences

      public static List<org.eclipse.lsp4j.Location> collectCrossFileReferences(WorkspaceIndex index, Path targetPath, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Convenience overload without open-document re-scan. Used by RNC references and other callers that don't have access to a document provider.
    • isGrammarFile

      public static boolean isGrammarFile(String uri)
      Returns true if uri points to a grammar file that can be the target of cross-file references (XSD, DTD, RNG, RNC).

      Use case: Both WorkspaceIndexCodeLensParticipant and the Case-2 path of findReference(org.eclipse.lemminx.dom.DOMDocument, org.eclipse.lsp4j.Position, org.eclipse.lsp4j.ReferenceContext, java.util.List<org.eclipse.lsp4j.Location>, org.eclipse.lsp4j.jsonrpc.CancelChecker) call this to decide whether to activate on the current document. Opening order.xml → false (no lens, no Case-2 search). Opening types.xsd → true.