fmt: fix file with just imports (fix #14267) (#14513)

master
yuyi 2022-05-25 01:14:08 +08:00 committed by GitHub
parent f431020764
commit 0eb3f8854d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -7,7 +7,6 @@ import strings
import v.ast
import v.util
import v.pref
import v.mathutil
const (
bs = '\\'
@ -72,8 +71,16 @@ pub fn fmt(file ast.File, table &ast.Table, pref &pref.Preferences, is_debug boo
if res.len == 1 {
return f.out_imports.str().trim_space() + '\n'
}
bounded_import_pos := mathutil.min(res.len, f.import_pos)
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..]
if res.len <= f.import_pos {
imp_str := f.out_imports.str().trim_space()
if imp_str.len > 0 {
return res + '\n' + imp_str + '\n'
} else {
return res
}
} else {
return res[..f.import_pos] + f.out_imports.str() + res[f.import_pos..]
}
}
pub fn (mut f Fmt) process_file_imports(file &ast.File) {

View File

@ -1,3 +1,3 @@
module proto
import emily33901.vproto
import emily33901.vproto