Class RNCLanguageService

java.lang.Object
org.eclipse.lemminx.extensions.relaxng.grammar.rnc.RNCLanguageService

public class RNCLanguageService extends Object
Facade for all RNC (RELAX NG Compact Syntax) language features, analogous to XMLLanguageService for XML documents.

This service provides the core language intelligence for .rnc files, including completion, hover, go-to-definition, document highlighting, folding, code lens, code actions, semantic tokens, and formatting. Each feature is implemented by a dedicated delegate class in its own sub-package.

Use case: RNCTextDocumentService creates an instance of this service and delegates all LSP requests (completion, hover, formatting, etc.) to it.

Example usage:

 RNCLanguageService service = new RNCLanguageService(documentProvider);
 CompletionList list = service.doComplete(document, position, true, cancelChecker);
 Hover hover = service.doHover(document, position, cancelChecker);
 List<? extends TextEdit> edits = service.format(document, sharedSettings);
 

Static helper methods for identifier resolution and range creation are in RNCPositionUtils.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new RNC language service, initializing all feature delegates.
  • Method Summary

    Modifier and Type
    Method
    Description
    List<org.eclipse.lsp4j.CodeAction>
    doCodeActions(RNCDocument rncDocument, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.CodeActionContext context, boolean snippetSupported, boolean resolveSupported, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes code actions (quick fixes) for diagnostics in the given range.
    org.eclipse.lsp4j.CompletionList
    doComplete(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes completion items for the given position in an RNC document.
    org.eclipse.lsp4j.Hover
    doHover(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes hover information for the word at the given position.
    org.eclipse.lsp4j.WorkspaceEdit
    doRename(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, String newName, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Renames the symbol at the given position across all its occurrences.
    List<? extends org.eclipse.lsp4j.LocationLink>
    findDefinition(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Finds the definition location for the symbol at the given position.
    List<org.eclipse.lsp4j.DocumentHighlight>
    findDocumentHighlights(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Finds all occurrences of the symbol at the given position for highlighting.
    List<org.eclipse.lsp4j.DocumentLink>
    findDocumentLinks(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Finds document links (clickable URIs) in an RNC document.
    List<org.eclipse.lsp4j.DocumentSymbol>
    findDocumentSymbols(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes hierarchical document symbols for the Outline view.
    List<? extends org.eclipse.lsp4j.Location>
    findReferences(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.ReferenceContext context, WorkspaceIndex workspaceIndex, Function<String,String> openDocContent, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Finds all references to the symbol at the given position.
    List<org.eclipse.lsp4j.SymbolInformation>
    findSymbolInformations(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes flat symbol information for workspace-wide symbol search.
    List<? extends org.eclipse.lsp4j.TextEdit>
    format(TextDocument textDocument, SharedSettings sharedSettings, RNCFormattingSettings rncFormattingSettings)
    Formats an RNC document by adjusting whitespace (indentation, spacing around operators, blank lines between definitions).
    List<org.eclipse.lsp4j.CodeLens>
    getCodeLens(RNCDocument rncDocument, boolean supportedByClient, WorkspaceIndex workspaceIndex, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes code lenses for an RNC document.
    List<org.eclipse.lsp4j.FoldingRange>
    getFoldingRanges(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Computes folding ranges for an RNC document.
    List<org.eclipse.lsp4j.InlayHint>
    getInlayHints(RNCDocument rncDocument, org.eclipse.lsp4j.Range range)
    Computes inlay hints for an RNC document.
    List<org.eclipse.lsp4j.SelectionRange>
    getSelectionRanges(RNCDocument rncDocument, List<org.eclipse.lsp4j.Position> positions, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
     
    org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.Range,org.eclipse.lsp4j.PrepareRenameResult>
    prepareRename(RNCDocument rncDocument, org.eclipse.lsp4j.Position position)
    Validates whether rename is possible at the given position and returns the range of the symbol to rename.
    org.eclipse.lsp4j.CodeAction
    resolveCodeAction(RNCDocument rncDocument, org.eclipse.lsp4j.CodeAction unresolved, boolean snippetSupported)
    Resolves a code action by computing its workspace edit lazily.
    org.eclipse.lsp4j.CompletionItem
    resolveCompletionItem(org.eclipse.lsp4j.CompletionItem item, RNCDocument rncDocument, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    Resolves a completion item by adding documentation (hover content).

    Methods inherited from class java.lang.Object

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

    • RNCLanguageService

      public RNCLanguageService(IRNCDocumentProvider documentProvider)
      Creates a new RNC language service, initializing all feature delegates.
      Parameters:
      documentProvider - provides access to open RNC documents (checks in-memory documents first, falls back to disk).
  • Method Details

    • doComplete

      public org.eclipse.lsp4j.CompletionList doComplete(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes completion items for the given position in an RNC document.

      Use case: triggered when the user presses Ctrl+Space or types a trigger character, offering keyword, define, datatype, and snippet completions based on cursor context.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      sharedSettings - the shared settings (snippet support, trigger-suggest, etc.).
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of completion items.
    • resolveCompletionItem

      public org.eclipse.lsp4j.CompletionItem resolveCompletionItem(org.eclipse.lsp4j.CompletionItem item, RNCDocument rncDocument, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Resolves a completion item by adding documentation (hover content).

      Use case: the client requests lazy resolution for a selected completion item to fetch its full documentation on demand.

      Parameters:
      item - the unresolved completion item.
      rncDocument - the parsed RNC document (AST).
      sharedSettings - settings for markup kind support.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the resolved completion item with documentation filled in.
    • doHover

      public org.eclipse.lsp4j.Hover doHover(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, SharedSettings sharedSettings, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes hover information for the word at the given position.

      Use case: the user hovers over a define reference, keyword, or datatype to see its documentation or definition text.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      sharedSettings - settings for markup kind support.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the hover content, or null if nothing to show.
    • findDocumentHighlights

      public List<org.eclipse.lsp4j.DocumentHighlight> findDocumentHighlights(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds all occurrences of the symbol at the given position for highlighting.

      Use case: when the cursor is on a define name or reference, all usages in the document are highlighted (definition = Write, references = Read).

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of document highlights.
    • findDefinition

      public List<? extends org.eclipse.lsp4j.LocationLink> findDefinition(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds the definition location for the symbol at the given position.

      Use case: "Go to Definition" on a define reference navigates to the define declaration; on an include URI navigates to the file.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of definition location links.
    • findReferences

      public List<? extends org.eclipse.lsp4j.Location> findReferences(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, org.eclipse.lsp4j.ReferenceContext context, WorkspaceIndex workspaceIndex, Function<String,String> openDocContent, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds all references to the symbol at the given position.

      Use case: "Find All References" on a define name shows everywhere it is used in the document (and optionally includes the declaration). When the cursor is not on a define name and workspaceIndex is non-null, falls back to cross-file workspace references (e.g. code lens click at position (0,0)).

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      context - whether to include the declaration itself.
      workspaceIndex - the workspace Bloom index for cross-file lookup, or null if the workspace index feature is disabled.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of reference locations.
    • prepareRename

      public org.eclipse.lsp4j.jsonrpc.messages.Either<org.eclipse.lsp4j.Range,org.eclipse.lsp4j.PrepareRenameResult> prepareRename(RNCDocument rncDocument, org.eclipse.lsp4j.Position position)
      Validates whether rename is possible at the given position and returns the range of the symbol to rename.

      Use case: the client calls this before showing the rename input box to verify the cursor is on a renameable symbol (define name or reference).

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position.
      Returns:
      the renameable range, or null if rename is not applicable.
    • doRename

      public org.eclipse.lsp4j.WorkspaceEdit doRename(RNCDocument rncDocument, org.eclipse.lsp4j.Position position, String newName, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Renames the symbol at the given position across all its occurrences.

      Use case: the user renames a define — all references and the declaration are updated to the new name.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      position - the cursor position on the symbol to rename.
      newName - the new name.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the workspace edit with all text changes.
    • getFoldingRanges

      public List<org.eclipse.lsp4j.FoldingRange> getFoldingRanges(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes folding ranges for an RNC document.

      Use case: provides fold regions for multi-line defines, includes, divs, consecutive declarations, and consecutive comment lines.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      cancelChecker - used to check if the operation has been cancelled.
      Returns:
      a list of FoldingRange for the document.
    • getCodeLens

      public List<org.eclipse.lsp4j.CodeLens> getCodeLens(RNCDocument rncDocument, boolean supportedByClient, WorkspaceIndex workspaceIndex, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes code lenses for an RNC document.

      Use case — workspace lens: When workspaceIndex is non-null, a "N references" lens is added at position (0,0) showing how many workspace XML files reference this RNC file. This is the same lens that WorkspaceIndexCodeLensParticipant produces for XSD/DTD/RNG files, but RNC files go through a separate text document service and therefore call WorkspaceIndexCodeLensSupport directly.

      Use case — per-define lens: Each define gets a lens showing its reference count within the file (and included files).

      Parameters:
      rncDocument - the parsed RNC document (AST).
      supportedByClient - whether the client supports code lens.
      workspaceIndex - the populated workspace Bloom index, or null if the workspace index feature is disabled.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of code lenses.
    • findDocumentLinks

      public List<org.eclipse.lsp4j.DocumentLink> findDocumentLinks(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Finds document links (clickable URIs) in an RNC document.

      Use case: the quoted URI in include "types.rnc" becomes a clickable link that opens the referenced file.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of document links.
    • findDocumentSymbols

      public List<org.eclipse.lsp4j.DocumentSymbol> findDocumentSymbols(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes hierarchical document symbols for the Outline view.

      Use case: populates the editor's Outline panel with a tree of namespace declarations, start, defines, includes, and nested element/attribute patterns.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of hierarchical document symbols.
    • findSymbolInformations

      public List<org.eclipse.lsp4j.SymbolInformation> findSymbolInformations(RNCDocument rncDocument, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes flat symbol information for workspace-wide symbol search.

      Use case: allows "Go to Symbol in Workspace" (Ctrl+T) to find RNC defines and declarations across all open files.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      a flat list of symbol information entries.
    • format

      public List<? extends org.eclipse.lsp4j.TextEdit> format(TextDocument textDocument, SharedSettings sharedSettings, RNCFormattingSettings rncFormattingSettings)
      Formats an RNC document by adjusting whitespace (indentation, spacing around operators, blank lines between definitions).

      Use case: when the user triggers "Format Document" on a .rnc file. For example, start=element root\{text\} is formatted to:

       start = element root {
         text
       }
       

      Respects SharedSettings for tab size, insert spaces vs tabs, trim trailing whitespace, insert final newline, and trim final newlines.

      Parameters:
      textDocument - the RNC text document.
      sharedSettings - the formatting settings (tab size, insert spaces, etc.).
      Returns:
      a list of TextEdit that transform the document to the formatted form.
    • getSelectionRanges

      public List<org.eclipse.lsp4j.SelectionRange> getSelectionRanges(RNCDocument rncDocument, List<org.eclipse.lsp4j.Position> positions, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
    • getInlayHints

      public List<org.eclipse.lsp4j.InlayHint> getInlayHints(RNCDocument rncDocument, org.eclipse.lsp4j.Range range)
      Computes inlay hints for an RNC document.

      Inherited start hint: When the document has an include but no own start declaration, an inlay hint shows the inherited start pattern from the included file at the end of the include URI.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      range - the range for which hints are requested.
      Returns:
      the list of inlay hints.
    • doCodeActions

      public List<org.eclipse.lsp4j.CodeAction> doCodeActions(RNCDocument rncDocument, org.eclipse.lsp4j.Range range, org.eclipse.lsp4j.CodeActionContext context, boolean snippetSupported, boolean resolveSupported, org.eclipse.lsp4j.jsonrpc.CancelChecker cancelChecker)
      Computes code actions (quick fixes) for diagnostics in the given range.

      Use case: when the user clicks the light bulb on an error, code actions offer fixes like "Create define", "Did you mean", "Add start", "Add closing brace", etc.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      range - the range for which code actions are requested.
      context - the code action context containing diagnostics.
      snippetSupported - whether the client supports snippet text edits.
      resolveSupported - whether the client supports lazy resolution.
      cancelChecker - used to abort if the request is cancelled.
      Returns:
      the list of code actions.
    • resolveCodeAction

      public org.eclipse.lsp4j.CodeAction resolveCodeAction(RNCDocument rncDocument, org.eclipse.lsp4j.CodeAction unresolved, boolean snippetSupported)
      Resolves a code action by computing its workspace edit lazily.

      Use case: for code actions like "Extract define" that require computing edits on demand rather than up front.

      Parameters:
      rncDocument - the parsed RNC document (AST).
      unresolved - the code action to resolve.
      snippetSupported - whether the client supports snippet text edits.
      Returns:
      the resolved code action with its edit populated.