@@ -7,28 +7,29 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
7
7
def format ( % SourceFile { } = source_file , uri = "file:" <> _ , project_dir )
8
8
when is_binary ( project_dir ) do
9
9
file_path = SourceFile.Path . absolute_from_uri ( uri )
10
+
10
11
if SourceFile.Path . path_in_dir? ( file_path , project_dir ) do
12
+ # file in project_dir we find formatter and options for file
11
13
case SourceFile . formatter_for ( uri , project_dir ) do
12
14
{ :ok , { formatter , opts , formatter_exs_dir } } ->
13
15
if should_format? ( uri , formatter_exs_dir , opts [ :inputs ] ) do
14
16
do_format ( source_file , formatter , opts )
15
17
else
16
- JsonRpc . show_message ( :info , "formatter.exs not found for #{ file_path } " )
18
+ JsonRpc . show_message ( :info , "File #{ file_path } not included in #{ Path . join ( formatter_exs_dir , ".formatter.exs" ) } " )
17
19
{ :ok , [ ] }
18
20
end
19
21
20
22
{ :error , message } ->
21
- JsonRpc . show_message ( :error , "Unable to fetch formatter options for #{ file_path } " )
23
+ JsonRpc . show_message ( :error , "Unable to find formatter for #{ file_path } " )
22
24
{ :error , :internal_error , message , true }
23
25
end
24
26
else
25
- JsonRpc . show_message ( :warning , "Cannot format file #{ file_path } outside of project dir #{ project_dir } " )
26
-
27
- { :ok , [ ] }
27
+ # if file is outside project_dir we format with default options
28
+ do_format ( source_file , nil , [ ] )
28
29
end
29
30
end
30
31
31
- # if project_dir is not set or schema is not file: we format with default options
32
+ # if project_dir is not set or schema is not file we format with default options
32
33
def format ( % SourceFile { } = source_file , _uri , _project_dir ) do
33
34
do_format ( source_file , nil , [ ] )
34
35
end
@@ -43,8 +44,9 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
43
44
44
45
{ :ok , response }
45
46
rescue
46
- _e in [ TokenMissingError , SyntaxError ] ->
47
- { :error , :internal_error , "Unable to format due to syntax error" , false }
47
+ e ->
48
+ JsonRpc . show_message ( :error , "Unable to format:\n #{ Exception . message ( e ) } " )
49
+ { :ok , [ ] }
48
50
end
49
51
50
52
defp get_formatted ( text , formatter , _ ) when is_function ( formatter ) do
0 commit comments