Skip to content

Commit

Permalink
Change to flag for on-type formatting case
Browse files Browse the repository at this point in the history
  • Loading branch information
jryans authored and jeapostrophe committed Apr 5, 2023
1 parent aacc842 commit b77ed7e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions text-document.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@
(define end-pos (send doc-text last-position))
(define start (abs-pos->Pos doc-text 0))
(define end (abs-pos->Pos doc-text end-pos))
(success-response id (format! uri start end 'document))]
(success-response id (format! uri start end))]
[_
(error-response id INVALID-PARAMS "textDocument/formatting failed")]))

Expand All @@ -518,7 +518,7 @@
;; XXX We're ignoring 'options' for now
[(hash-table ['textDocument (DocIdentifier #:uri uri)]
['range (Range #:start start #:end end)])
(success-response id (format! uri start end 'range))]
(success-response id (format! uri start end))]
[_
(error-response id INVALID-PARAMS "textDocument/rangeFormatting failed")]))

Expand All @@ -543,13 +543,12 @@
(abs-pos->Pos doc-text (or (find-containing-paren pos (send doc-text get-text))
0))
(abs-pos->Pos doc-text pos))]))
(success-response id (format! uri start end 'on-type))]
(success-response id (format! uri start end #:on-type? #t))]
[_
(error-response id INVALID-PARAMS "textDocument/onTypeFormatting failed")]))

;; Shared path for all formatting requests
;; `kind` allows diverging in a few places while sharing the core operation
(define (format! uri start end kind)
(define (format! uri start end #:on-type? [on-type? #f])
(unless (uri-is-path? uri)
(error 'format! "uri is not a path"))
(match-define (doc doc-text doc-trace)
Expand Down Expand Up @@ -581,7 +580,7 @@
identity
; NOTE: The order is important somehow
(list (remove-trailing-space! mut-doc-text skip-this-line? line)
(indent-line! mut-doc-text indenter line kind)))
(indent-line! mut-doc-text indenter line #:on-type? on-type?)))
(loop (add1 line)))))))

;; Returns a TextEdit, or #f if the line is a part of multiple-line string
Expand All @@ -600,7 +599,7 @@
[else #f]))

;; Returns a TextEdit, or #f if the line is already correct.
(define (indent-line! doc-text indenter line kind)
(define (indent-line! doc-text indenter line #:on-type? [on-type? #f])
(define line-start (send doc-text paragraph-start-position line))
(define line-end (send doc-text paragraph-end-position line))
(define line-text (send doc-text get-text line-start line-end))
Expand All @@ -618,7 +617,7 @@
(cond
[(not (number? desired-spaces)) #f]
[(= current-spaces desired-spaces) #f]
[(and (not (eq? kind 'on-type)) (= line-length 0)) #f]
[(and (not on-type?) (= line-length 0)) #f]
[(< current-spaces desired-spaces)
;; Insert spaces
(define insert-count (- desired-spaces current-spaces))
Expand Down

0 comments on commit b77ed7e

Please sign in to comment.