Class RNCTextDocumentService

java.lang.Object
org.eclipse.lemminx.AbstractTextDocumentService<RNCDocument>
org.eclipse.lemminx.extensions.relaxng.grammar.rnc.RNCTextDocumentService
All Implemented Interfaces:
org.eclipse.lsp4j.services.TextDocumentService

public class RNCTextDocumentService extends AbstractTextDocumentService<RNCDocument>
LSP text document service for RNC (RELAX NG Compact Syntax) .rnc files.

This service is registered with the CompositeTextDocumentService and handles all LSP requests for files matching the .rnc extension. It routes each request (completion, hover, formatting, etc.) to the RNCLanguageService facade, analogous to how XMLTextDocumentService routes requests to XMLLanguageService.

Use case: when a user opens, edits, or closes a .rnc file in the editor, this service is selected by canHandle(String) and manages the full lifecycle: parsing, validation with delay, and responding to LSP feature requests.

Validation flow:

  • onDidOpen → validates immediately (async, no delay)
  • onDidChange → validates with delay via ModelValidatorDelayer to debounce rapid keystrokes
  • onDidClose → cancels any pending validation for the closed URI

Validation itself uses RNCValidator (Jing's CompactParseable) and is version-aware: if the document changes while validation is running, the result is discarded via CancellationException.

  • Constructor Details

    • RNCTextDocumentService

      public RNCTextDocumentService(XMLLanguageServer server)
      Creates a new RNC text document service.
      Parameters:
      server - the XML language server that hosts this service.
  • Method Details

    • updateSettings

      public void updateSettings(Object initSettings)
      Description copied from class: AbstractTextDocumentService
      Called when the client sends updated settings. Subclasses may override to extract settings specific to their file type.
      Overrides:
      updateSettings in class AbstractTextDocumentService<RNCDocument>
      Parameters:
      initSettings - the settings object (content under xml).
    • getScopedFields

      protected List<ConfigurationField> getScopedFields()
      Description copied from class: AbstractTextDocumentService
      Returns the list of configuration fields that can be scoped per folder via workspace/configuration. Subclasses should override to return the appropriate scoped fields for their file type.
      Overrides:
      getScopedFields in class AbstractTextDocumentService<RNCDocument>
      Returns:
      the scoped fields, or null if scoped settings are not supported by this service.
    • canHandle

      public boolean canHandle(String uri)
      Determines whether this service handles the given document URI.

      Returns true for URIs ending with .rnc (RELAX NG Compact Syntax files).

      Specified by:
      canHandle in class AbstractTextDocumentService<RNCDocument>
      Parameters:
      uri - the document URI to check.
      Returns:
      true if the URI points to a .rnc file.
    • onDidOpen

      protected void onDidOpen(ModelTextDocument<RNCDocument,SharedSettings> document)
      Called when an RNC document is opened. Triggers immediate validation (no delay) so the user sees diagnostics right away.
      Overrides:
      onDidOpen in class AbstractTextDocumentService<RNCDocument>
    • onDidChange

      protected void onDidChange(ModelTextDocument<RNCDocument,SharedSettings> document)
      Called when an RNC document is changed. Triggers delayed validation to debounce rapid keystrokes and avoid unnecessary re-validation.
      Overrides:
      onDidChange in class AbstractTextDocumentService<RNCDocument>
    • onDidClose

      protected void onDidClose(String uri)
      Called when an RNC document is closed. Cancels any pending validation to avoid publishing stale diagnostics for a closed file.
      Overrides:
      onDidClose in class AbstractTextDocumentService<RNCDocument>
    • onIndexScanCompleted

      protected void onIndexScanCompleted()
      Re-validates all open RNC files when the workspace index scan completes. Needed because some diagnostics (e.g. "missing start" suppression) depend on cross-file workspace information that is only available after the full scan.
      Overrides:
      onIndexScanCompleted in class AbstractTextDocumentService<RNCDocument>
    • completion

      public CompletableFuture<org.eclipse.lsp4j.jsonrpc.messages.Either<List<org.eclipse.lsp4j.CompletionItem>,org.eclipse.lsp4j.CompletionList>> completion(org.eclipse.lsp4j.CompletionParams params)
      Handles textDocument/completion for RNC files.

      Use case: provides keyword, snippet, and define-reference completions based on the cursor context (top-level, after assign, inside pattern, etc.).

      Specified by:
      completion in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      completion in class AbstractTextDocumentService<RNCDocument>
    • resolveCompletionItem

      public CompletableFuture<org.eclipse.lsp4j.CompletionItem> resolveCompletionItem(org.eclipse.lsp4j.CompletionItem unresolved)
      Specified by:
      resolveCompletionItem in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      resolveCompletionItem in class AbstractTextDocumentService<RNCDocument>
    • hover

      public CompletableFuture<org.eclipse.lsp4j.Hover> hover(org.eclipse.lsp4j.HoverParams params)
      Handles textDocument/hover for RNC files.

      Use case: shows define declarations or keyword documentation on hover.

      Specified by:
      hover in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      hover in class AbstractTextDocumentService<RNCDocument>
    • documentHighlight

      public CompletableFuture<List<? extends org.eclipse.lsp4j.DocumentHighlight>> documentHighlight(org.eclipse.lsp4j.DocumentHighlightParams params)
      Handles textDocument/documentHighlight for RNC files.

      Use case: highlights the definition (Write) and all references (Read) of a define name when the cursor is placed on it.

      Specified by:
      documentHighlight in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      documentHighlight in class AbstractTextDocumentService<RNCDocument>
    • documentSymbol

      public CompletableFuture<List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.SymbolInformation,org.eclipse.lsp4j.DocumentSymbol>>> documentSymbol(org.eclipse.lsp4j.DocumentSymbolParams params)
      Specified by:
      documentSymbol in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      documentSymbol in class AbstractTextDocumentService<RNCDocument>
    • definition

      public CompletableFuture<org.eclipse.lsp4j.jsonrpc.messages.Either<List<? extends org.eclipse.lsp4j.Location>,List<? extends org.eclipse.lsp4j.LocationLink>>> definition(org.eclipse.lsp4j.DefinitionParams params)
      Handles textDocument/definition for RNC files.

      Use case: navigates from a define reference (e.g. root in start = root) to its declaration (root = element root \{ ... \}).

      Specified by:
      definition in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      definition in class AbstractTextDocumentService<RNCDocument>
    • references

      public CompletableFuture<List<? extends org.eclipse.lsp4j.Location>> references(org.eclipse.lsp4j.ReferenceParams params)
      Specified by:
      references in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      references in class AbstractTextDocumentService<RNCDocument>
    • prepareRename

      public CompletableFuture<org.eclipse.lsp4j.jsonrpc.messages.Either3<org.eclipse.lsp4j.Range,org.eclipse.lsp4j.PrepareRenameResult,org.eclipse.lsp4j.PrepareRenameDefaultBehavior>> prepareRename(org.eclipse.lsp4j.PrepareRenameParams params)
      Specified by:
      prepareRename in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      prepareRename in class AbstractTextDocumentService<RNCDocument>
    • rename

      public CompletableFuture<org.eclipse.lsp4j.WorkspaceEdit> rename(org.eclipse.lsp4j.RenameParams params)
      Specified by:
      rename in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      rename in class AbstractTextDocumentService<RNCDocument>
    • foldingRange

      public CompletableFuture<List<org.eclipse.lsp4j.FoldingRange>> foldingRange(org.eclipse.lsp4j.FoldingRangeRequestParams params)
      Handles textDocument/foldingRange for RNC files.

      Use case: provides fold regions for brace blocks and consecutive comment groups.

      Specified by:
      foldingRange in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      foldingRange in class AbstractTextDocumentService<RNCDocument>
    • documentLink

      public CompletableFuture<List<org.eclipse.lsp4j.DocumentLink>> documentLink(org.eclipse.lsp4j.DocumentLinkParams params)
      Specified by:
      documentLink in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      documentLink in class AbstractTextDocumentService<RNCDocument>
    • codeLens

      public CompletableFuture<List<? extends org.eclipse.lsp4j.CodeLens>> codeLens(org.eclipse.lsp4j.CodeLensParams params)
      Handles textDocument/codeLens for RNC files.

      Use case: shows "N references" above each define declaration.

      Specified by:
      codeLens in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      codeLens in class AbstractTextDocumentService<RNCDocument>
    • codeAction

      public CompletableFuture<List<org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.Command,org.eclipse.lsp4j.CodeAction>>> codeAction(org.eclipse.lsp4j.CodeActionParams params)
      Handles textDocument/codeAction for RNC files.

      Use case: provides quick-fix code actions for parser errors (e.g. insert missing \}, add missing =, insert URI placeholder).

      Specified by:
      codeAction in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      codeAction in class AbstractTextDocumentService<RNCDocument>
    • resolveCodeAction

      public CompletableFuture<org.eclipse.lsp4j.CodeAction> resolveCodeAction(org.eclipse.lsp4j.CodeAction unresolved)
      Specified by:
      resolveCodeAction in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      resolveCodeAction in class AbstractTextDocumentService<RNCDocument>
    • inlayHint

      public CompletableFuture<List<org.eclipse.lsp4j.InlayHint>> inlayHint(org.eclipse.lsp4j.InlayHintParams params)
      Specified by:
      inlayHint in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      inlayHint in class AbstractTextDocumentService<RNCDocument>
    • selectionRange

      public CompletableFuture<List<org.eclipse.lsp4j.SelectionRange>> selectionRange(org.eclipse.lsp4j.SelectionRangeParams params)
      Specified by:
      selectionRange in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      selectionRange in class AbstractTextDocumentService<RNCDocument>
    • formatting

      public CompletableFuture<List<? extends org.eclipse.lsp4j.TextEdit>> formatting(org.eclipse.lsp4j.DocumentFormattingParams params)
      Handles textDocument/formatting for RNC files.

      Use case: formats the entire RNC document, adjusting indentation, spacing around operators, and blank lines between top-level definitions.

      Specified by:
      formatting in interface org.eclipse.lsp4j.services.TextDocumentService
      Overrides:
      formatting in class AbstractTextDocumentService<RNCDocument>