resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Add keep-sorted macro for maintaining sorted lists

Open Copilot opened this issue 3 months ago • 0 comments

Adds a keep-sorted macro that marks collections for Resyntax to keep sorted. When elements are out of order, Resyntax suggests reordering them alphabetically by identifier name.

Changes

  • keep-sorted.rkt - Macro that adds a 'keep-sorted syntax property to mark collections
  • default-recommendations/keep-sorted-suggestions.rkt - Refactoring rule that detects unsorted marked lists and suggests sorting
  • default-recommendations/keep-sorted-suggestions-test.rkt - Test coverage
  • default-recommendations.rkt - Added to default recommendations suite

Usage

#lang racket
(require resyntax/keep-sorted)

; Resyntax will suggest reordering to (list apple banana orange)
(keep-sorted (list apple orange banana))

The macro is transparent at runtime—it enables other macros like define-refactoring-suite to expand to keep-sorted and enforce sorted rule lists.

Original prompt

This section details on the original issue you should resolve

<issue_title>Keeping marked lists sorted</issue_title> <issue_description>It should be possible to tell Resyntax to keep specific collections in sorted order. This could be done with a keep-sorted macro by making a Resyntax rule that looks for a syntax property added by the macro. The first form in the list should be ignored so that this works with any collection, like (list ...), (set ...), or (vector ...). The comparator used could also be customizable by the keep-sorted macro, but it has to be something that operates on the syntax objects contained, not their values.

#lang resyntax/test

test: "unsorted marked list should be resorted"
--------------------
#lang racket
(keep-sorted (list apple orange banana))
--------------------
--------------------
#lang racket
(keep-sorted (list apple banana orange))
--------------------

It should be a macro so that other macros can expand to it. I want this so that define-refactoring-suite can specify that the list of refactoring rules should always be written in sorted order.</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes jackfirth/resyntax#499

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Dec 01 '25 17:12 Copilot