Class GrammarFileRenameSupport

java.lang.Object
org.eclipse.lemminx.extensions.index.GrammarFileRenameSupport

public class GrammarFileRenameSupport extends Object
Computes a WorkspaceEdit that updates all grammar file references across the workspace when a grammar file is renamed.

Use case (UC14–UC18): The user renames schema.xsd to types.xsd in the IDE. All XML files that reference schema.xsd via <?xml-model href="schema.xsd"?>, xsi:schemaLocation, xsi:noNamespaceSchemaLocation, <!DOCTYPE ... SYSTEM "...">, or xs:include schemaLocation must be updated automatically.

Integration point: Called from the workspace/willRenameFiles handler. The LSP client sends the old and new URIs before the actual rename; this class computes the edits, the client applies them, then renames the file.

Flow:

   workspace/willRenameFiles("schema.xsd" → "types.xsd")
     │
     ├─ 1. WorkspaceIndex.getReferencesTo("schema.xsd")
     │     → Returns only confirmed referencing files from the in-memory index
     │     → Zero file I/O — GrammarReference line/column positions
     │        were computed once at indexing time and cached in FileBloomEntry
     │
     ├─ 2. For each confirmed file:
     │     → If the file is OPEN in the editor (live DOM may differ from disk):
     │        re-scan from the in-memory content to get accurate positions
     │     → If the file is CLOSED: use the cached line/column positions directly
     │
     └─ 3. Build WorkspaceEdit with TextEdits replacing old path with new path
           → preserves relative paths (e.g. "../schemas/schema.xsd" → "../schemas/types.xsd")
 
See Also:
  • Constructor Details

    • GrammarFileRenameSupport

      public GrammarFileRenameSupport()
  • Method Details

    • computeRenameEdits

      public static org.eclipse.lsp4j.WorkspaceEdit computeRenameEdits(WorkspaceIndex index, Path oldPath, Path newPath)
      Convenience overload — no open-document re-scan (uses cached positions for all files).
    • computeRenameEdits

      public static org.eclipse.lsp4j.WorkspaceEdit computeRenameEdits(WorkspaceIndex index, Path oldPath, Path newPath, Function<String,String> openDocumentContent)