fmt: keep comments between and after imports (#8637)
parent
cb1f63f765
commit
8cb01ba8db
|
@ -287,6 +287,7 @@ pub:
|
||||||
pub mut:
|
pub mut:
|
||||||
syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}`
|
syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}`
|
||||||
comments []Comment
|
comments []Comment
|
||||||
|
next_comments []Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
// import symbol,for import {symbol} syntax
|
// import symbol,for import {symbol} syntax
|
||||||
|
|
|
@ -280,6 +280,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
|
||||||
already_imported[import_text] = true
|
already_imported[import_text] = true
|
||||||
f.out_imports.writeln(import_text)
|
f.out_imports.writeln(import_text)
|
||||||
f.import_comments(imp.comments, inline: true)
|
f.import_comments(imp.comments, inline: true)
|
||||||
|
f.import_comments(imp.next_comments, {})
|
||||||
num_imports++
|
num_imports++
|
||||||
}
|
}
|
||||||
if num_imports > 0 {
|
if num_imports > 0 {
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
// import time This should be commented out
|
// import time This should be commented out
|
||||||
import os
|
import os
|
||||||
|
// between
|
||||||
import rand
|
import rand
|
||||||
|
// first between
|
||||||
|
// second between
|
||||||
|
import semver
|
||||||
|
// after the last import
|
||||||
|
// also after the last import
|
||||||
|
|
||||||
// another comment after imports
|
// this comment does not belong to the imports anymore
|
||||||
|
|
|
@ -1918,6 +1918,7 @@ fn (mut p Parser) import_stmt() ast.Import {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
import_node.comments = p.eat_comments(same_line: true)
|
import_node.comments = p.eat_comments(same_line: true)
|
||||||
|
import_node.next_comments = p.eat_comments(follow_up: true)
|
||||||
p.imports[mod_alias] = mod_name
|
p.imports[mod_alias] = mod_name
|
||||||
// if mod_name !in p.table.imports {
|
// if mod_name !in p.table.imports {
|
||||||
p.table.imports << mod_name
|
p.table.imports << mod_name
|
||||||
|
|
Loading…
Reference in New Issue