Skip to content

Commit

Permalink
fmt: fix autoimport with shebang and comments above other imports (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Mar 18, 2024
1 parent 833da30 commit a36c693
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/fmt/fmt.v
Expand Up @@ -98,7 +98,8 @@ pub fn fmt(file ast.File, mut table ast.Table, pref_ &pref.Preferences, is_debug
return res
}
mut import_start_pos := f.import_pos
if stmt := file.stmts[1] {
if f.import_pos == 0 && file.stmts.len > 1 {
stmt := file.stmts[1]
if stmt is ast.ExprStmt && stmt.expr is ast.Comment
&& (stmt.expr as ast.Comment).text.starts_with('#!') {
import_start_pos = stmt.pos.len
Expand Down
@@ -0,0 +1,7 @@
#!/usr/bin/env -S v

// Comment
import json
import os

os.join_path('', '')
@@ -0,0 +1,5 @@
#!/usr/bin/env -S v

// Comment
import json
os.join_path('', '')

0 comments on commit a36c693

Please sign in to comment.