Skip to content

Conversation

@iamgio
Copy link
Owner

@iamgio iamgio commented Sep 20, 2025

This PR makes DocumentInfo immutable, along with its data properties (PageFormatInfo, ParagraphStyleInfo, DocumentNumbering, CaptionPositionInfo, FontInfo, TexInfo).

This is powered by the amber library, made ad-hoc for this specific use case.

The entry point to mutate the document info and metadata is now by overwriting MutableContext#documentInfo.

@iamgio iamgio added the refactor Internal structure was changed label Sep 20, 2025
@iamgio iamgio requested a review from Copilot September 20, 2025 18:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR transforms the DocumentInfo class and its sub-properties into immutable data structures using the amber library. The changes replace the previous automerge system with a new immutable approach where document information is updated by creating new instances rather than mutating existing ones.

Key changes include:

  • Converting mutable document properties to immutable ones with the amber library
  • Updating all document modification functions to use copy semantics
  • Changing function signatures to require MutableContext instead of Context for modification operations

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
quarkdown-core/build.gradle.kts Updates dependency from automerge to amber library
quarkdown-core/src/main/kotlin/com/quarkdown/core/document/DocumentInfo.kt Makes DocumentInfo immutable with @NestedData annotation
quarkdown-core/src/main/kotlin/com/quarkdown/core/document/tex/TexInfo.kt Converts TexInfo to immutable with Map instead of MutableMap
quarkdown-core/src/main/kotlin/com/quarkdown/core/document/layout/*/Info.kt Adds @mergeable annotations and converts var to val properties
quarkdown-core/src/main/kotlin/com/quarkdown/core/context/MutableContext.kt Adds mutable documentInfo property to support immutable updates
quarkdown-stdlib/src/main/kotlin/com/quarkdown/stdlib/Document.kt Updates all document functions to use copy semantics for immutability
Test files Updates test code to use new immutable patterns for DocumentInfo creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +3 to 4
import com.quarkdown.amber.annotations.Mergeable
import com.quarkdown.core.ast.Node
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement shows a change from automerge to amber, but this appears to be a simple library replacement. Ensure that the Mergeable annotation from the amber library provides the same functionality as the previous automerge implementation.

Suggested change
import com.quarkdown.amber.annotations.Mergeable
import com.quarkdown.core.ast.Node
// NOTE: The Mergeable annotation was previously imported from automerge.

Copilot uses AI. Check for mistakes.
Comment on lines +255 to +263
val authors =
this.authors +
it.map { (name, info) ->
DocumentAuthor(
name = name,
info = info.unwrappedValue.mapValues { (_, value) -> value.unwrappedValue },
)
}
copy(authors = authors)
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The temporary authors variable assignment could be simplified by inlining the computation directly in the copy call, reducing unnecessary intermediate variables and improving readability.

Copilot uses AI. Check for mistakes.
@iamgio iamgio merged commit c20fe33 into main Sep 23, 2025
3 checks passed
@iamgio iamgio deleted the document-info-immutability branch September 23, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Internal structure was changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants