Class WorkspaceIndexCodeLensSupport

java.lang.Object
org.eclipse.lemminx.extensions.index.WorkspaceIndexCodeLensSupport

public class WorkspaceIndexCodeLensSupport extends Object
Shared utility that builds the "N references" workspace code lens for grammar files (XSD, DTD, RNG, RNC).

This class is called by both WorkspaceIndexCodeLensParticipant (for grammar files opened via the XML language service) and directly by the RNC code lens provider (which runs through a separate text document service and therefore cannot go through the XML extension registry).

Use case: The user opens order.rnc or types.xsd. The code lens provider for that file type calls buildWorkspaceReferenceLens(org.eclipse.lemminx.extensions.index.WorkspaceIndex, java.lang.String, org.eclipse.lsp4j.Range, boolean, org.eclipse.lsp4j.jsonrpc.CancelChecker) to create a "N references" lens at the position of the first significant token. Clicking the lens triggers textDocument/references → WorkspaceIndexReferenceParticipant.

Range: Each caller supplies the lens Range because the grammar AST differs per file type:

  • XSD/RNG/DTD: range of the root DOM element's start tag
  • RNC: position (0,0) (no DOM available)

No file I/O: Reference counts come directly from the GrammarReference list cached in each FileBloomEntry during indexing. Files are never re-read during code lens computation.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.eclipse.lsp4j.CodeLens
    buildCatalogWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String catalogUri, String catalogIdentifier, org.eclipse.lsp4j.Range range, boolean supportedByClient, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Builds a "N references" code lens for a catalog entry pointing to the grammar at uri.
    static org.eclipse.lsp4j.CodeLens
    buildWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String uri, org.eclipse.lsp4j.Range range, boolean supportedByClient, boolean excludeGrammarFiles, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Builds a "N references" code lens for the grammar file identified by uri, optionally excluding grammar-to-grammar references from the count.
    static org.eclipse.lsp4j.CodeLens
    buildWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String uri, org.eclipse.lsp4j.Range range, boolean supportedByClient, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Builds a "N references" code lens for the grammar file identified by uri.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WorkspaceIndexCodeLensSupport

      public WorkspaceIndexCodeLensSupport()
  • Method Details

    • buildWorkspaceReferenceLens

      public static org.eclipse.lsp4j.CodeLens buildWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String uri, org.eclipse.lsp4j.Range range, boolean supportedByClient, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Builds a "N references" code lens for the grammar file identified by uri.

      Use case: types.xsd is referenced by three XML files in the workspace. The lens shows "3 references" at the position supplied by the caller. Clicking it opens the references panel.

      Returns null when no workspace files reference this grammar, so the caller can omit it from the list without adding an empty lens.

      Parameters:
      workspaceIndex - the populated Bloom index.
      uri - URI of the grammar file being viewed.
      range - position where the lens should appear (caller-supplied, differs per grammar file type).
      supportedByClient - true if the client supports the editor.action.showReferences command.
      cancelChecker - unused — kept for API compatibility.
      Returns:
      a CodeLens with a ReferenceCommand, or null if no references are found.
    • buildWorkspaceReferenceLens

      public static org.eclipse.lsp4j.CodeLens buildWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String uri, org.eclipse.lsp4j.Range range, boolean supportedByClient, boolean excludeGrammarFiles, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Builds a "N references" code lens for the grammar file identified by uri, optionally excluding grammar-to-grammar references from the count.

      Use case — excludeGrammarFiles = true: A catalog entry <uri name="http://foo" uri="schema.xsd"/> should only count XML instance documents, not other XSD files that import schema.xsd. Passing true filters out XSD/DTD/RNG/RNC/XSL/XSLT candidates.

      Parameters:
      excludeGrammarFiles - when true, grammar files are excluded from the reference count — used by catalog code lenses.
    • buildCatalogWorkspaceReferenceLens

      public static org.eclipse.lsp4j.CodeLens buildCatalogWorkspaceReferenceLens(WorkspaceIndex workspaceIndex, String catalogUri, String catalogIdentifier, org.eclipse.lsp4j.Range range, boolean supportedByClient, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Builds a "N references" code lens for a catalog entry pointing to the grammar at uri.

      Only XML instance files that reference the grammar via the catalog identifier are counted. Direct references to the grammar file by filename (e.g. xsi:noNamespaceSchemaLocation="data2.xsd") are intentionally excluded because they bypass the catalog mapping and do not use the catalog entry.

      Parameters:
      workspaceIndex - the populated Bloom index.
      catalogUri - URI of the catalog file containing the entry. Used as the target for the ReferenceCommand so that clicking the lens triggers textDocument/references on the catalog file.
      catalogIdentifier - the catalog key attribute (systemId / publicId / URI name).
      range - position where the lens should appear.
      supportedByClient - true if the client supports the references command.
      cancelChecker - unused — kept for API compatibility.
      Returns:
      a CodeLens with a ReferenceCommand, or null if no references are found.