fmt: fix comment line number in file with crlf line separator (fix #23524) (#25163)

This commit is contained in:
Krchi 2025-08-24 15:49:10 +08:00 committed by GitHub
parent be31491834
commit 000b4169d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 3 deletions

2
vlib/v/fmt/tests/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*_crlf_* binary
*_lf_* binary

View File

@ -0,0 +1,12 @@
module main
fn main() {
// vfmt off
a := [
1, 2, 3,
4, 5, 6,
]
// vfmt on
println('Hello World!')
}

View File

@ -0,0 +1,12 @@
module main
fn main() {
// vfmt off
a := [
1, 2, 3,
4, 5, 6,
]
// vfmt on
println('Hello World!')
}

View File

@ -1068,11 +1068,11 @@ pub fn (mut s Scanner) text_scan() token.Token {
mut comment_line_end := s.pos
if s.text[s.pos - 1] == b_cr {
comment_line_end--
} else {
// fix line_nr, \n was read; the comment is marked on the next line
s.pos--
s.line_nr--
}
// fix line_nr, \n was read; the comment is marked on the next line
s.pos--
s.line_nr--
if s.should_parse_comment() {
s.line_comment = s.text[start + 1..comment_line_end]
mut comment := s.line_comment