Skip to content

Commit c0982d4

Browse files
committed
Support fancy in Gradient
1 parent 22f0ef8 commit c0982d4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/gradient/elixir_fmt.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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"}

lib/mix/tasks/gradient.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule Mix.Tasks.Gradient do
1616
* `--stop_on_first_error` - stop type checking at the first error
1717
* `--infer` - infer type information from literals and other language
1818
constructs,
19-
* `--verbose` - show what Gradient is doing
19+
* `--verbose` - show what Gradualizer is doing
2020
* `--no-fancy` - do not use fancy error messages
2121
* `--fmt-location none` - do not display location for easier comparison
2222
* `--fmt-location brief` - display location for machine processing

0 commit comments

Comments
 (0)