From 64f3cd1ebd2d329c9730318a012a4caee72fc3d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 17:06:09 +0000 Subject: [PATCH 1/3] Initial plan From 7c8a39968836862e979771b4d318f308b07e473e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 17:16:35 +0000 Subject: [PATCH 2/3] Add source-syntax-paths function to filter syntax paths by line ranges Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- private/source.rkt | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/private/source.rkt b/private/source.rkt index a16631e..efbacb8 100644 --- a/private/source.rkt +++ b/private/source.rkt @@ -19,6 +19,7 @@ [source-can-expand? (-> source? boolean?)] [source-text-of (-> source? syntax? immutable-string?)] [source-comment-locations (-> source? immutable-range-set?)] + [source-syntax-paths (->* (source?) (range-set?) sorted-set?)] [file-source? (-> any/c boolean?)] [file-source (-> path-string? file-source?)] [file-source-path (-> file-source? path?)] @@ -37,11 +38,14 @@ racket/path racket/port rebellion/base/immutable-string + resyntax/private/linemap resyntax/private/syntax-neighbors + resyntax/private/syntax-path syntax/modread rebellion/base/comparator rebellion/base/range rebellion/collection/range-set + rebellion/collection/sorted-set rebellion/collection/vector/builder rebellion/streaming/transducer syntax-color/lexer-contract @@ -149,7 +153,32 @@ (define valid-mod (modified-source orig "#lang racket/base\n(define foo 43)")) (define invalid-mod (modified-source orig "#lang racket/base\n(if)")) (check-true (source-can-expand? valid-mod)) - (check-false (source-can-expand? invalid-mod)))) + (check-false (source-can-expand? invalid-mod))) + + (test-case "source-syntax-paths" + ;; Test with all lines (unbounded range) + (define test-source (string-source "#lang racket/base\n(define x 42)\n(define y 99)")) + (define all-paths (source-syntax-paths test-source)) + (check-true (sorted-set? all-paths)) + ;; Should have multiple paths since there are multiple forms + (check-true (> (sorted-set-size all-paths) 0)) + + ;; Test with specific line range - just line 2 which has (define x 42) + (define line2-range (range-set (closed-range 2 2 #:comparator natural<=>))) + (define line2-paths (source-syntax-paths test-source line2-range)) + (check-true (sorted-set? line2-paths)) + ;; Should have fewer paths than all-paths + (check-true (< (sorted-set-size line2-paths) (sorted-set-size all-paths))) + + ;; Test with a line range that includes multiple forms + (define lines23-range (range-set (closed-range 2 3 #:comparator natural<=>))) + (define lines23-paths (source-syntax-paths test-source lines23-range)) + (check-true (>= (sorted-set-size lines23-paths) (sorted-set-size line2-paths))) + + ;; Test with no overlapping lines (e.g., line 100) + (define no-overlap-range (range-set (closed-range 100 100 #:comparator natural<=>))) + (define no-overlap-paths (source-syntax-paths test-source no-overlap-range)) + (check-equal? (sorted-set-size no-overlap-paths) 0))) (define (source-expand code) @@ -195,6 +224,22 @@ #:into (into-range-set natural<=>))) +(define (source-syntax-paths src [lines (range-set (unbounded-range #:comparator natural<=>))]) + (define program-stx (source-read-syntax src)) + (define linemap (string-linemap (source->string src))) + (sorted-set->immutable-sorted-set + (transduce (in-syntax-paths program-stx) + (filtering + (λ (path) + (define stx (syntax-ref program-stx path)) + ;; Only include paths with source location information + (and (syntax-position stx) + (syntax-span stx) + (let ([stx-lines (syntax-line-range stx #:linemap linemap)]) + (range-set-overlaps? lines stx-lines))))) + #:into (into-sorted-set syntax-path<=>)))) + + (struct lexical-token (text start end type delimiter-kind attributes) #:transparent) From 599b9ef8c57e13de4e553e6208eda4dbe3f391ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 17:19:17 +0000 Subject: [PATCH 3/3] Update source-analyze to accept syntax paths instead of line ranges Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- main.rkt | 3 ++- private/analysis.rkt | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/main.rkt b/main.rkt index a9db4eb..cc5fe01 100644 --- a/main.rkt +++ b/main.rkt @@ -209,8 +209,9 @@ (define results (with-handlers ([exn:fail? skip]) + (define paths (source-syntax-paths source lines)) (define analysis (source-analyze source - #:lines lines + #:paths paths #:analyzers (refactoring-suite-analyzers effective-suite) #:timeout-ms timeout-ms)) (refactor-visited-forms diff --git a/private/analysis.rkt b/private/analysis.rkt index 52ac154..1b8707f 100644 --- a/private/analysis.rkt +++ b/private/analysis.rkt @@ -7,7 +7,7 @@ (provide (contract-out [source-analyze (->* (source? #:analyzers (sequence/c expansion-analyzer?) #:timeout-ms exact-nonnegative-integer?) - (#:lines range-set?) + (#:paths sorted-set?) source-code-analysis?)] [source-code-analysis? (-> any/c boolean?)] [source-code-analysis-code (-> source-code-analysis? source?)] @@ -117,7 +117,7 @@ (define (source-analyze code - #:lines [lines (range-set (unbounded-range #:comparator natural<=>))] + #:paths [paths (sorted-set #:comparator syntax-path<=>)] #:analyzers analyzers #:timeout-ms timeout-ms) (define ns (make-base-namespace)) @@ -141,18 +141,22 @@ (define/guard (resyntax-should-analyze-syntax? stx #:as-visit? [as-visit? #true]) (guard (syntax-original-and-from-source? stx program-source-name) #:else #false) (guard as-visit? #:else #true) - (define stx-lines (syntax-line-range stx #:linemap code-linemap)) - (define overlaps? (range-set-overlaps? lines stx-lines)) - (unless overlaps? + ;; If no paths were specified (empty set), analyze everything + (guard (not (sorted-set-empty? paths)) #:else #true) + (define stx-path (syntax-original-path stx)) + (define should-analyze? + (and stx-path + (sorted-set-contains? paths stx-path))) + (unless should-analyze? (log-resyntax-debug - (string-append "ignoring visited syntax object because it's outside analyzed lines\n" - " analyzed lines: ~a\n" - " syntax lines: ~a\n" + (string-append "ignoring visited syntax object because it's not in analyzed paths\n" + " analyzed paths: ~a\n" + " syntax path: ~a\n" " syntax: ~a") - lines - stx-lines + paths + stx-path stx)) - overlaps?) + should-analyze?) (define/match (observe-event! sig val) [('visit (? syntax? visited))