Class WorkspaceIndexCodeLensParticipant

java.lang.Object
org.eclipse.lemminx.extensions.index.WorkspaceIndexCodeLensParticipant
All Implemented Interfaces:
ICodeLensParticipant

public class WorkspaceIndexCodeLensParticipant extends Object implements ICodeLensParticipant
Shows a "N references" code lens at the root element of grammar files opened via the XML language service (XSD, DTD, RNG).

RNC files go through a separate text document service and therefore cannot reach this participant. Their "N references" lens is added by the RNC code lens provider, which calls the shared WorkspaceIndexCodeLensSupport.buildWorkspaceReferenceLens(org.eclipse.lemminx.extensions.index.WorkspaceIndex, java.lang.String, org.eclipse.lsp4j.Range, boolean, org.eclipse.lsp4j.jsonrpc.CancelChecker) directly.

Use case (UC19 — Browse backlinks from a grammar file): The user opens order-schema.xsd. The root element shows:

   3 references
   <xs:schema ...>
 
Clicking the lens opens the references panel listing all three XML files and the exact attribute values that point to this grammar.

Prerequisite: Code lens must be enabled (xml.codeLens.enabled: true in VS Code settings). The workspace scan must have populated WorkspaceIndex. If the scan is still running when the lens is first requested, a workspace/codeLens/refresh is sent once it completes so the count updates.

Two-pass approach (delegated to WorkspaceIndexCodeLensSupport):

  1. WorkspaceIndex.findReferencingFiles(java.lang.String) — Bloom filter O(n) pre-filter
  2. GrammarReferenceLocator.locateReferencesTo(java.lang.CharSequence, java.lang.String) — exact count per candidate
See Also:
  • Constructor Details

    • WorkspaceIndexCodeLensParticipant

      public WorkspaceIndexCodeLensParticipant(WorkspaceIndex workspaceIndex)
  • Method Details

    • doCodeLens

      public void doCodeLens(ICodeLensRequest request, List<org.eclipse.lsp4j.CodeLens> lenses, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Emits a "N references" lens on the root element of grammar files.

      Use case: opening types.xsd when two XML files reference it via xsi:noNamespaceSchemaLocation="types.xsd" → shows "2 references". Clicking triggers textDocument/references at the root element position, which WorkspaceIndexReferenceParticipant resolves to all referencing locations across the workspace.

      The lens range is the start tag of the DOM root element (or (0,0) as fallback). RNC uses (0,0) always since no DOM is available there.

      Specified by:
      doCodeLens in interface ICodeLensParticipant