@@ -48,6 +48,11 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
4848 }
4949 p.check (.key_enum)
5050 end_pos := p.tok.pos ()
51+ mut comments_before_key_enum := if p.is_vls {
52+ p.cur_comments.clone ()
53+ } else {
54+ []
55+ }
5156 if p.disallow_declarations_in_script_mode () {
5257 return ast.EnumDecl{}
5358 }
@@ -253,20 +258,39 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
253258
254259 if ! already_exists {
255260 p.table.register_enum_decl (enum_decl)
256- if p.pref. is_vls {
261+ if p.is_vls {
257262 key := 'enum_${name }'
258- val := ast.VLSInfo{
259- pos: typ_pos
260- comments: enum_decl_comments
263+ mut has_decl_end_comment := false
264+ if enum_decl.comments.len > 0
265+ && enum_decl.comments[0 ].pos.line_nr == enum_decl.pos.line_nr {
266+ // enum MyEnum { // MyEnum end_comment1
267+ comments_before_key_enum << enum_decl.comments[0 ]
268+ has_decl_end_comment = true
269+ }
270+ val := ast.VlsInfo{
271+ pos: typ_pos
272+ doc: p.keyword_comments_to_string (enum_name, comments_before_key_enum)
261273 }
262274 p.table.register_vls_info (key, val)
263- for f in fields {
275+ for i, f in fields {
264276 f_key := 'enum_${name }.${f .name }'
265- f_val := ast.VLSInfo{
266- pos: f.pos
267- pre_comments: f.pre_comments
268- comments: f.comments
269- end_comments: f.next_comments
277+ f_val := if i == 0 {
278+ first_field_pre_comment := if has_decl_end_comment {
279+ enum_decl.comments[1 ..].clone ()
280+ } else {
281+ enum_decl.comments
282+ }
283+ ast.VlsInfo{
284+ pos: f.pos
285+ doc: p.comments_to_string (first_field_pre_comment) +
286+ p.comments_to_string (f.comments)
287+ }
288+ } else {
289+ ast.VlsInfo{
290+ pos: f.pos
291+ doc: p.comments_to_string (fields[i - 1 ].next_comments) +
292+ p.comments_to_string (f.comments)
293+ }
270294 }
271295 p.table.register_vls_info (f_key, f_val)
272296 }
0 commit comments