@@ -32,60 +32,65 @@ public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activa
3232 });
3333
3434 plugins. hook_document. connect ((d) = > {
35- // Ensure use global settings by default
36- format_bar. tab_style_set_by_editor_config = false ;
37- format_bar. tab_width_set_by_editor_config = false ;
38- format_bar. set_document (d);
35+ update_config. begin (d);
36+ });
3937
40- Scratch . Widgets . SourceView view = d. source_view;
41- File file = d. file;
38+ }
4239
43- if (file == null || ! file. query_exists ()) {
44- return ;
45- }
40+ private async void update_config (Scratch .Services .Document d ) {
41+ // Ensure use global settings by default
42+ format_bar. tab_style_set_by_editor_config = false ;
43+ format_bar. tab_width_set_by_editor_config = false ;
44+ format_bar. set_document (d);
4645
47- var handle = new EditorConfig .Handle ();
48- handle. set_conf_file_name (" .editorconfig" );
49- if (handle. parse (file. get_path ()) != 0 ) {
50- return ;
51- }
46+ Scratch . Widgets . SourceView view = d. source_view;
47+ File file = d. file;
5248
53- for (int i = 0 ; i < handle. get_name_value_count (); i++ ) {
54- string name, val;
55- handle. get_name_value (i, out name, out val);
56- /* These are all properties (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties) */
57- switch (name) {
58- case " indent_style" :
59- format_bar. tab_style_set_by_editor_config = true ;
60- var use_spaces = (val != " tab" );
61- format_bar. set_insert_spaces_instead_of_tabs (use_spaces);
62- break ;
63- case " indent_size" :
64- case " tab_width" :
65- format_bar. tab_width_set_by_editor_config = true ;
66- var indent_width = (int . parse (val)). clamp (2 , 16 );
67- format_bar. set_tab_width (indent_width);
68- break ;
69- case " end_of_line" :
70- break ;
71- case " charset" :
72- break ;
73- case " trim_trailing_whitespace" :
74- break ;
75- case " insert_final_newline" :
76- break ;
77- case " max_line_length" :
78- view. right_margin_position = int . parse (val);
79- break ;
80- default:
81- warning (" unrecognised name/value %s /%s " , name, val);
82- break ;
83- }
49+ if (file == null || ! file. query_exists ()) {
50+ return ;
51+ }
52+
53+ var handle = new EditorConfig .Handle ();
54+ handle. set_conf_file_name (" .editorconfig" );
55+ if (handle. parse (file. get_path ()) != 0 ) {
56+ return ;
57+ }
58+
59+ for (int i = 0 ; i < handle. get_name_value_count (); i++ ) {
60+ string name, val;
61+ handle. get_name_value (i, out name, out val);
62+ /* These are all properties (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties) */
63+ switch (name) {
64+ case " indent_style" :
65+ format_bar. tab_style_set_by_editor_config = true ;
66+ var use_spaces = (val != " tab" );
67+ format_bar. set_insert_spaces_instead_of_tabs (use_spaces);
68+ break ;
69+ case " indent_size" :
70+ case " tab_width" :
71+ format_bar. tab_width_set_by_editor_config = true ;
72+ var indent_width = (int . parse (val)). clamp (2 , 16 );
73+ format_bar. set_tab_width (indent_width);
74+ break ;
75+ case " end_of_line" :
76+ break ;
77+ case " charset" :
78+ break ;
79+ case " trim_trailing_whitespace" :
80+ break ;
81+ case " insert_final_newline" :
82+ break ;
83+ case " max_line_length" :
84+ view. right_margin_position = int . parse (val);
85+ break ;
86+ default:
87+ warning (" unrecognised name/value %s /%s " , name, val);
88+ break ;
8489 }
85- });
90+ }
8691 }
8792
88- public void deactivate () { }
93+ public void deactivate () { debug ( " Editor config deactivate " ); }
8994}
9095
9196[ModuleInit ]
0 commit comments