@@ -13,6 +13,8 @@ defmodule Gradient.ElixirFmt do
1313
1414 - `ex_fmt_type_fun`: function to pretty print an type AST in Elixir `(abstract_type() -> iodata())`.
1515
16+ - `{fancy, boolean()}`: do not use fancy error messages, default: true
17+
1618 - Gradualizer options, but some of them are overwritten by Gradient.
1719 """
1820 @ behaviour Gradient.Fmt
@@ -244,16 +246,23 @@ defmodule Gradient.ElixirFmt do
244246 @ spec try_highlight_in_context ( Types . abstract_expr ( ) , options ( ) ) ::
245247 { :ok , iodata ( ) } | { :error , term ( ) }
246248 def try_highlight_in_context ( expression , opts ) do
247- forms = Keyword . get ( opts , :forms )
248-
249- with :ok <- has_location? ( expression ) ,
250- { :ok , path } <- get_ex_file_path ( forms ) ,
249+ with :ok <- print_fancy? ( opts ) ,
250+ :ok <- has_location? ( expression ) ,
251+ { :ok , path } <- get_ex_file_path ( opts [ :forms ] ) ,
251252 { :ok , code } <- File . read ( path ) do
252253 code_lines = String . split ( code , ~r/ \R / )
253254 { :ok , highlight_in_context ( expression , code_lines , opts ) }
254255 end
255256 end
256257
258+ def print_fancy? ( opts ) do
259+ if Keyword . get ( opts , :fancy , true ) do
260+ :ok
261+ else
262+ { :error , "The fancy mode is turn off" }
263+ end
264+ end
265+
257266 def has_location? ( expression ) do
258267 if elem ( expression , 1 ) == 0 do
259268 { :error , "The location is missing in the expression" }
0 commit comments