@@ -74,8 +74,34 @@ handle_request({document_ontypeformatting, Params}) ->
74
74
% % Internal functions
75
75
% %==============================================================================
76
76
-spec format_document (binary (), string (), formatting_options ()) ->
77
- {[text_edit ()]}.
77
+ {response , [text_edit ()]}.
78
78
format_document (Path , RelativePath , Options ) ->
79
+ Config = els_config :get (formatting ),
80
+ case {get_formatter_files (Config ), get_formatter_exclude_files (Config )} of
81
+ {all , ExcludeFiles } ->
82
+ case lists :member (Path , ExcludeFiles ) of
83
+ true ->
84
+ {response , []};
85
+ false ->
86
+ do_format_document (Path , RelativePath , Options )
87
+ end ;
88
+ {Files , ExcludeFiles } ->
89
+ case lists :member (Path , Files ) of
90
+ true ->
91
+ case lists :member (Path , ExcludeFiles ) of
92
+ true ->
93
+ {response , []};
94
+ false ->
95
+ do_format_document (Path , RelativePath , Options )
96
+ end ;
97
+ false ->
98
+ {response , []}
99
+ end
100
+ end .
101
+
102
+ -spec do_format_document (binary (), string (), formatting_options ()) ->
103
+ {response , [text_edit ()]}.
104
+ do_format_document (Path , RelativePath , Options ) ->
79
105
Fun = fun (Dir ) ->
80
106
format_document_local (Dir , RelativePath , Options ),
81
107
Outfile = filename :join (Dir , RelativePath ),
@@ -122,6 +148,27 @@ rangeformat_document(_Uri, _Document, _Range, _Options) ->
122
148
ontypeformat_document (_Uri , _Document , _Line , _Col , _Char , _Options ) ->
123
149
{ok , []}.
124
150
151
+ -spec get_formatter_files (map ()) -> [binary ()] | all .
152
+ get_formatter_files (Config ) ->
153
+ RootPath = els_uri :path (els_config :get (root_uri )),
154
+ case maps :get (" files" , Config , all ) of
155
+ all ->
156
+ all ;
157
+ Globs ->
158
+ lists :flatten ([expand_glob (RootPath , Glob ) || Glob <- Globs ])
159
+ end .
160
+
161
+ -spec get_formatter_exclude_files (map ()) -> [binary ()].
162
+ get_formatter_exclude_files (Config ) ->
163
+ RootPath = els_uri :path (els_config :get (root_uri )),
164
+ Globs = maps :get (" exclude_files" , Config , []),
165
+ lists :flatten ([expand_glob (RootPath , Glob ) || Glob <- Globs ]).
166
+
167
+ -spec expand_glob (binary (), binary ()) -> [binary ()].
168
+ expand_glob (RootPath , Glob ) ->
169
+ Wildcard = unicode :characters_to_list (filename :join (RootPath , Glob ), utf8 ),
170
+ [unicode :characters_to_binary (Path ) || Path <- filelib :wildcard (Wildcard )].
171
+
125
172
-spec get_formatter_name (map () | undefined ) ->
126
173
sr_formatter | erlfmt_formatter | otp_formatter | default_formatter .
127
174
get_formatter_name (undefined ) ->
0 commit comments