Class WorkspaceIndexReferenceParticipant
- All Implemented Interfaces:
IReferenceParticipant
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 Summary
ConstructorsConstructorDescriptionWorkspaceIndexReferenceParticipant(WorkspaceIndex workspaceIndex) Convenience constructor for tests that don't need open-document re-scan.WorkspaceIndexReferenceParticipant(WorkspaceIndex workspaceIndex, Supplier<IXMLDocumentProvider> docProviderSupplier) Constructor used in production. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 referencetargetPathand returns their exactLocations.static List<org.eclipse.lsp4j.Location> collectCrossFileReferences(WorkspaceIndex index, Path targetPath, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker) Convenience overload without open-document re-scan.voidfindReference(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.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) Find references for a document that is not currently open/managed, identified only by its URI.static booleanisGrammarFile(String uri) Returnstrueifuripoints to a grammar file that can be the target of cross-file references (XSD, DTD, RNG, RNC).
-
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
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.xmland positions the cursor inside the"schema.xsd"value ofxsi: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.xsdand 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 referenceschema.xsd.- Specified by:
findReferencein interfaceIReferenceParticipant
-
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:IReferenceParticipantFind 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:
findReferenceByUriin interfaceIReferenceParticipant
-
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 referencetargetPathand returns their exactLocations. Positions are always resolved from the freshest available content viaGrammarFileRenameSupport.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.xmlis open in the editor and the user added 2 lines before<?xml-model href="schema.xsd"?>. Live content is used → accurate line-3Locationis returned.Use case — recently saved file:
order.xmlwas just saved and thedidChangeWatchedFilesre-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 returningnullif closed. Passnullto 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
Returnstrueifuripoints to a grammar file that can be the target of cross-file references (XSD, DTD, RNG, RNC).Use case: Both
WorkspaceIndexCodeLensParticipantand the Case-2 path offindReference(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. Openingorder.xml→false(no lens, no Case-2 search). Openingtypes.xsd→true.
-