Browse Source

Remove range format markers when using --lines and --diff together (#154)

fe/comments v1.4.5
Fredrik Ekre 4 months ago committed by GitHub
parent
commit
c415326215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      CHANGELOG.md
  2. 2
      Project.toml
  3. 21
      src/main.jl
  4. 10
      test/maintests.jl

5
CHANGELOG.md

@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.4.5] - 2025-07-24
### Fixed
- Fix `--diff` output in combination with `--lines`. Previously the internal makers used to
mark the lines to be formatted would show up in the diff output. ([#154]).
## [v1.4.4] - 2025-07-24
### Fixed
- Fix another edgecase where adding a trailing comma after the last item in a list results

2
Project.toml

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
name = "Runic"
uuid = "62bfec6d-59d7-401d-8490-b29ee721c001"
version = "1.4.4"
version = "1.4.5"
[deps]
JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4"

21
src/main.jl

@ -468,15 +468,32 @@ function main(argv) @@ -468,15 +468,32 @@ function main(argv)
file = basename(inputfile)
A = joinpath(a, file)
B = joinpath(b, file)
src_str = ctx.src_str
# If we have ranges we need to remove the comment markers
# TODO: It isn't great that the source string has been modified to begin
# with, and to support --lines in the API functions this filtering
# needs to be moved to the `format_tree` function.
if !isempty(line_ranges)
io = IOBuffer(; sizehint = sizeof(src_str))
for line in eachline(IOBuffer(src_str); keep = true)
if !(
occursin(RANGE_FORMATTING_BEGIN, line) ||
occursin(RANGE_FORMATTING_END, line)
)
write(io, line)
end
end
src_str = String(take!(io))
end
# juliac: `open(...) do` uses dynamic dispatch otherwise the following
# blocks could be written as
# ```
# write(A, ctx.src_str)
# write(A, src_str)
# write(B, seekstart(ctx.fmt_io))
# ```
let io = open(A, "w")
try
write(io, ctx.src_str)
write(io, src_str)
finally
close(io)
end

10
test/maintests.jl

@ -543,6 +543,16 @@ function maintests(f::R) where {R} @@ -543,6 +543,16 @@ function maintests(f::R) where {R}
rc, fd1, fd2 = runic(["--lines=3:4", "."])
@test rc == 1 && isempty(fd1)
@test occursin("option `--lines` can not be used together with multiple input files", fd2)
# --diff and --lines: no comment markers in diff output
if Sys.which("git") !== nothing
rc, fd1, fd2 = runic(["--lines=1:1", "--diff"], src)
@test rc == 0
@test fd1 == "function f(a, b)\n return a+b\n end\n"
@test occursin("-function f(a,b)", fd2)
@test occursin("+function f(a, b)", fd2)
@test !occursin(Runic.RANGE_FORMATTING_BEGIN, fd2)
@test !occursin(Runic.RANGE_FORMATTING_END, fd2)
end
end
return

Loading…
Cancel
Save