Skip to content

Commit b1415ce

Browse files
lukaszsamsonaxelson
authored andcommitted
Remove elixir 1.6 code as 1.7 is required (elixir-editors#93)
* remove elixir 1.6 code as 1.7 is required replace deprecated Code.load_file/1 with Code.require_file/1 * remove not used param * fix dialyzer error: The test binary() == nil can never evaluate to 'true'
1 parent 41756b8 commit b1415ce

File tree

7 files changed

+21
-66
lines changed

7 files changed

+21
-66
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ In order to debug modules in `.exs` files (such as tests), they must be specifie
7373

7474
Builds are performed automatically when files are saved. If you want this to happen automatically when you type, you can turn on "autosave" in your IDE.
7575

76-
Starting in Elixir 1.6, Mix compilers adhere to the [Mix.Task.Compiler](https://hexdocs.pm/mix/master/Mix.Task.Compiler.html) behaviour and return their error and warning diagnostics in a standardized way. If you're using Elixir >= 1.6, errors and warnings will be shown inline in your code as well as in the "Problems" pane in the IDE. If you're using an earlier version of Elixir, you'll need to look at the text log from the extension to see the errors and warnings.
76+
Starting in Elixir 1.6, Mix compilers adhere to the [Mix.Task.Compiler](https://hexdocs.pm/mix/master/Mix.Task.Compiler.html) behaviour and return their error and warning diagnostics in a standardized way. Errors and warnings will be shown inline in your code as well as in the "Problems" pane in the IDE. If you're using an earlier version of Elixir, you'll need to look at the text log from the extension to see the errors and warnings.
7777

7878
## Dialyzer integration
7979

apps/debugger/lib/debugger/server.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ defmodule ElixirLS.Debugger.Server do
435435
mixfile = Path.absname(System.get_env("MIX_EXS") || "mix.exs")
436436

437437
unless match?(%{file: ^mixfile}, Mix.ProjectStack.peek()) do
438-
Code.load_file(System.get_env("MIX_EXS") || "mix.exs")
438+
Code.require_file(System.get_env("MIX_EXS") || "mix.exs")
439439
end
440440

441441
task = task || Mix.Project.config()[:default_task]
@@ -546,7 +546,7 @@ defmodule ElixirLS.Debugger.Server do
546546
%{name: name, file: file} = project
547547
:code.purge(name)
548548
:code.delete(name)
549-
Code.load_file(file)
549+
Code.require_file(file)
550550
end
551551
end
552552

apps/elixir_ls_utils/test/support/mix_test.case.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ defmodule ElixirLS.Utils.MixTest.Case do
126126
for %{name: module, file: file} <- stack do
127127
:code.purge(module)
128128
:code.delete(module)
129-
Code.load_file(file)
129+
Code.require_file(file)
130130
end
131131
end
132132
end

apps/language_server/lib/language_server/build.ex

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ defmodule ElixirLS.LanguageServer.Build do
7979
msg =
8080
case error do
8181
{:shutdown, 1} ->
82-
msg = "Build failed for unknown reason. See output log."
83-
84-
if Version.match?(System.version(), ">= 1.6.0-dev") do
85-
msg
86-
else
87-
msg <> " Upgrade to Elixir 1.6 to see build errors and warnings."
88-
end
82+
"Build failed for unknown reason. See output log."
8983

9084
_ ->
9185
Exception.format_exit(error)
@@ -124,23 +118,18 @@ defmodule ElixirLS.LanguageServer.Build do
124118
# Override build directory to avoid interfering with other dev tools
125119
Mix.ProjectStack.post_config(build_path: ".elixir_ls/build")
126120

127-
# If using Elixir 1.6 or higher, we can get diagnostics if Mixfile fails to load
121+
# We can get diagnostics if Mixfile fails to load
128122
{status, diagnostics} =
129-
if Version.match?(System.version(), ">= 1.6.0-dev") do
130-
case Kernel.ParallelCompiler.compile([mixfile]) do
131-
{:ok, _, warnings} ->
132-
{:ok, Enum.map(warnings, &mixfile_diagnostic(&1, :warning))}
133-
134-
{:error, errors, warnings} ->
135-
{
136-
:error,
137-
Enum.map(warnings, &mixfile_diagnostic(&1, :warning)) ++
138-
Enum.map(errors, &mixfile_diagnostic(&1, :error))
139-
}
140-
end
141-
else
142-
Code.load_file(mixfile)
143-
{:ok, []}
123+
case Kernel.ParallelCompiler.compile([mixfile]) do
124+
{:ok, _, warnings} ->
125+
{:ok, Enum.map(warnings, &mixfile_diagnostic(&1, :warning))}
126+
127+
{:error, errors, warnings} ->
128+
{
129+
:error,
130+
Enum.map(warnings, &mixfile_diagnostic(&1, :warning)) ++
131+
Enum.map(errors, &mixfile_diagnostic(&1, :error))
132+
}
144133
end
145134

146135
if status == :ok do

apps/language_server/lib/language_server/dialyzer/utils.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Utils do
2828
expand_references(rest, exclude, result)
2929
end
3030

31-
# Mix.Utils.last_modified/1 returns a :calendar.universal_time() in Elixir < 1.7,
32-
# otherwise posix time, so we normalize to a :calendar.universal_time()
31+
# Mix.Utils.last_modified/1 returns a posix time, so we normalize to a :calendar.universal_time()
3332
def normalize_timestamp(timestamp) when is_integer(timestamp),
3433
do: :calendar.gregorian_seconds_to_datetime(timestamp + @epoch_gregorian_seconds)
3534

36-
def normalize_timestamp(timestamp), do: timestamp
37-
3835
defp module_references(mod) do
3936
try do
4037
forms = :forms.read(mod)

apps/language_server/lib/language_server/providers/formatting.ex

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
99
def format(source_file, uri, project_dir) do
1010
if can_format?(uri, project_dir) do
1111
file = SourceFile.path_from_uri(uri) |> Path.relative_to(project_dir)
12-
opts = formatter_opts(file, project_dir)
12+
opts = formatter_opts(file)
1313
formatted = IO.iodata_to_binary([Code.format_string!(source_file.text, opts), ?\n])
1414

1515
response =
@@ -34,38 +34,12 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
3434
file_path = file_uri |> SourceFile.path_from_uri() |> String.downcase()
3535
cwd = File.cwd!() |> String.downcase()
3636

37-
is_nil(project_dir) or not String.starts_with?(file_path, project_dir) or
37+
not String.starts_with?(file_path, project_dir) or
3838
String.starts_with?(Path.absname(file_path), cwd)
3939
end
4040

41-
defp formatter_opts(for_file, project_dir) do
42-
# Elixir 1.6.5+ has a function that returns formatter options, so we use that if available
43-
if Code.ensure_loaded?(Mix.Tasks.Format) and
44-
function_exported?(Mix.Tasks.Format, :formatter_opts_for_file, 1) do
45-
Mix.Tasks.Format.formatter_opts_for_file(for_file)
46-
else
47-
read_formatter_exs(project_dir)
48-
end
49-
end
50-
51-
# TODO: Deprecate once Elixir 1.7 released
52-
defp read_formatter_exs(project_dir) do
53-
dot_formatter = Path.join(project_dir, ".formatter.exs")
54-
55-
if File.regular?(dot_formatter) do
56-
{formatter_opts, _} = Code.eval_file(dot_formatter)
57-
58-
unless Keyword.keyword?(formatter_opts) do
59-
Mix.raise(
60-
"Expected #{inspect(dot_formatter)} to return a keyword list, " <>
61-
"got: #{inspect(formatter_opts)}"
62-
)
63-
end
64-
65-
formatter_opts
66-
else
67-
[]
68-
end
41+
defp formatter_opts(for_file) do
42+
Mix.Tasks.Format.formatter_opts_for_file(for_file)
6943
end
7044

7145
defp myers_diff_to_text_edits(myers_diff, starting_pos \\ {0, 0}) do

apps/language_server/lib/language_server/server.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ defmodule ElixirLS.LanguageServer.Server do
110110
{:noreply, handle_build_result(status, diagnostics, state)}
111111
end
112112

113-
# Pre Elixir 1.6, we can't get diagnostics from builds
114-
def handle_cast({:build_finished, _}, state) do
115-
{:noreply, handle_build_result(:ok, [], state)}
116-
end
117-
118113
def handle_cast({:dialyzer_finished, diagnostics, build_ref}, state) do
119114
{:noreply, handle_dialyzer_result(diagnostics, build_ref, state)}
120115
end

0 commit comments

Comments
 (0)