Interface IIndexFileScannerContributor
- All Known Implementing Classes:
RNCIndexFileScannerContributor
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 TypeMethodDescriptionbooleanReturnstrueif this contributor can scan the given file.default StringReturns the in-memory text content of the given URI if the file is currently open in the editor and tracked by this contributor, ornullif the file is not open or this contributor does not track open documents.default voidScans the given in-memory content and populatesrefsandnames.booleanScans the file and populatesrefsandnames.
-
Method Details
-
canScan
Returnstrueif 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:
trueto claim the file;falseto pass.
-
scan
boolean scan(Path path, int maxChars, List<GrammarReference> refs, Set<String> names) throws IOException Scans the file and populatesrefsandnames.The scan must be streaming: never load the whole file into memory. Stop reading after
maxCharscharacters and returntrueto 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_VALUEmeans no limit.refs- output — located grammar references with line/column positions.names- output — token names for the Bloom filter.- Returns:
trueif scanning stopped early due tomaxChars.- 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 populatesrefsandnames.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
Returns the in-memory text content of the given URI if the file is currently open in the editor and tracked by this contributor, ornullif 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
nullif unavailable.
-