fmt: only insert a space after // if the 3rd char is alphanumeric (#7330)
parent
8ab59c5f0f
commit
c922565525
|
@ -1204,16 +1204,19 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
||||||
if !node.text.contains('\n') {
|
if !node.text.contains('\n') {
|
||||||
is_separate_line := !options.inline || node.text.starts_with('\x01')
|
is_separate_line := !options.inline || node.text.starts_with('\x01')
|
||||||
mut s := if node.text.starts_with('\x01') { node.text[1..] } else { node.text }
|
mut s := if node.text.starts_with('\x01') { node.text[1..] } else { node.text }
|
||||||
if s == '' {
|
mut out_s := '//'
|
||||||
s = '//'
|
if s != '' {
|
||||||
} else {
|
match s[0] {
|
||||||
s = '// ' + s
|
`a`...`z`, `A`...`Z`, `0`...`9` { out_s += ' ' }
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
out_s += s
|
||||||
}
|
}
|
||||||
if !is_separate_line && f.indent > 0 {
|
if !is_separate_line && f.indent > 0 {
|
||||||
f.remove_new_line() // delete the generated \n
|
f.remove_new_line() // delete the generated \n
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
}
|
}
|
||||||
f.write(s)
|
f.write(out_s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lines := node.text.split_into_lines()
|
lines := node.text.split_into_lines()
|
||||||
|
|
|
@ -30,6 +30,9 @@ fn main() {
|
||||||
a := 123 // comment after assign
|
a := 123 // comment after assign
|
||||||
b := 'foo' // also comment after assign
|
b := 'foo' // also comment after assign
|
||||||
c := true
|
c := true
|
||||||
// between two assigns
|
// Between two assigns
|
||||||
d := false
|
d := false
|
||||||
|
//////
|
||||||
|
// /
|
||||||
|
// 123
|
||||||
}
|
}
|
||||||
|
|
|
@ -926,7 +926,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||||
}
|
}
|
||||||
if s.should_parse_comment() {
|
if s.should_parse_comment() {
|
||||||
s.line_comment = s.text[start + 1..comment_line_end]
|
s.line_comment = s.text[start + 1..comment_line_end]
|
||||||
mut comment := s.line_comment.trim_space()
|
mut comment := s.line_comment
|
||||||
// Find out if this comment is on its own line (for vfmt)
|
// Find out if this comment is on its own line (for vfmt)
|
||||||
mut is_separate_line_comment := true
|
mut is_separate_line_comment := true
|
||||||
for j := start - 2; j >= 0 && s.text[j] != `\n`; j-- {
|
for j := start - 2; j >= 0 && s.text[j] != `\n`; j-- {
|
||||||
|
|
Loading…
Reference in New Issue