@@ -30,6 +30,23 @@ local Token = require("nattlua.lexer.token")
3030local META = class .CreateTemplate (" editor_helper" )
3131META :GetSet (" WorkingDirectory" , " ./" )
3232
33+ local format_emitter_defaults = {
34+ pretty_print = true ,
35+ string_quote = " \" " ,
36+ no_semicolon = true ,
37+ comment_type_annotations = true ,
38+ type_annotations = " explicit" ,
39+ force_parenthesis = true ,
40+ omit_parentheses_for_single_table_call = true ,
41+ trailing_newline = true ,
42+ }
43+
44+ local function apply_format_emitter_defaults (emitter_config )
45+ for k , v in pairs (format_emitter_defaults ) do
46+ if emitter_config [k ] == nil then emitter_config [k ] = v end
47+ end
48+ end
49+
3350function META :SetWorkingDirectory (dir )
3451 self .WorkingDirectory = dir
3552end
@@ -522,6 +539,9 @@ function META:Recompile(path, lol, diagnostics, on_save_path)
522539 cfg_copy [k ] = v
523540 end
524541
542+
543+ if cfg_copy .trailing_newline == nil then cfg_copy .trailing_newline = true end
544+
525545 cfg_copy .remove_unused = true
526546 cfg_copy .skip_import = true
527547 cfg_copy .no_pipeline = true
653673function META :Format (code , path , extra_emitter_config )
654674 path = path_util .Normalize (path )
655675 local config = self :GetCompilerConfig (path )
656- local emitter_cfg = {
657- pretty_print = true ,
658- string_quote = " \" " ,
659- no_semicolon = true ,
660- comment_type_annotations = true ,
661- type_annotations = " explicit" ,
662- force_parenthesis = true ,
663- omit_parentheses_for_single_table_call = true ,
664- }
665-
666- for k , v in pairs (emitter_cfg ) do
667- if config .emitter [k ] == nil then config .emitter [k ] = v end
668- end
676+ apply_format_emitter_defaults (config .emitter )
669677
670678 config .parser = {skip_import = true }
671679 config .emitter .comment_type_annotations = path :sub (-# " .lua" ) == " .lua"
0 commit comments