Skip to content

Commit

Permalink
Elixir 1.13 support (#620)
Browse files Browse the repository at this point in the history
* bump elixir_sense

* fix deprecated api usage

* migrate to Config

* add compatibility with elixir 1.13 mix

* fix test

* fix test

* fix test

* call old version on elixir < 1.13

* add support for bin_heredoc token

* fix compile on 1.12

* remove newlines in document outline

* add support for list_heredoc token

* Update apps/language_server/lib/language_server/mix_shell.ex

Co-authored-by: Jason Axelson <[email protected]>
  • Loading branch information
lukaszsamson and axelson authored Nov 21, 2021
1 parent 4a6145d commit 90f6591
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 17 deletions.
3 changes: 1 addition & 2 deletions apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ defmodule ElixirLS.LanguageServer.Build do
# The project may override our logger config, so we reset it after loading their config
logger_config = Application.get_all_env(:logger)
Mix.Task.run("loadconfig")
# NOTE: soft-deprecated in v1.10
Mix.Config.persist(logger: logger_config)
Application.put_all_env([logger: logger_config], persistent: true)
end

{status, diagnostics}
Expand Down
9 changes: 7 additions & 2 deletions apps/language_server/lib/language_server/mix_shell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule ElixirLS.LanguageServer.MixShell do
end

@impl Mix.Shell
def yes?(message) do
def yes?(message, options \\ []) do
if WireProtocol.io_intercepted?() do
response =
JsonRpc.show_message_request(:info, message, [
Expand All @@ -55,7 +55,12 @@ defmodule ElixirLS.LanguageServer.MixShell do
true
end
else
Mix.Shell.IO.yes?(message)
# TODO convert to to normal call when we require elixir 1.13
if Version.match?(System.version(), "< 1.13.0-rc.0") do
apply(Mix.Shell.IO, :yes?, [message])
else
apply(Mix.Shell.IO, :yes?, [message, options])
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
[{:when, _, [{:"::", _, [{_, _, _} = type_head, _]}, _]}] ->
Macro.to_string(type_head)
end
|> String.replace("\n", "")

type = if type_kind in [:type, :typep, :opaque], do: :class, else: :event

Expand Down Expand Up @@ -192,7 +193,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
{defname, _, [{:when, _, [{_, location, _} = fn_head, _]} | _]}
)
when defname in @defs do
name = Macro.to_string(fn_head)
name = Macro.to_string(fn_head) |> String.replace("\n", "")

%Info{
type: :function,
Expand All @@ -205,7 +206,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
# Function, macro, delegate
defp extract_symbol(_current_module, {defname, _, [{_, location, _} = fn_head | _]})
when defname in @defs do
name = Macro.to_string(fn_head)
name = Macro.to_string(fn_head) |> String.replace("\n", "")

%Info{
type: :function,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ElixirLS.LanguageServer.Providers.FoldingRange.Token do
"""

alias ElixirSense.Core.Normalized.Tokenizer
require Logger

@type t :: {atom(), {non_neg_integer(), non_neg_integer(), any()}, any()}

Expand Down Expand Up @@ -36,8 +37,15 @@ defmodule ElixirLS.LanguageServer.Providers.FoldingRange.Token do
{:sigil, {b1, b2, b3}, _, _, _, delimiter} ->
{:sigil, {b1 - 1, b2 - 1, b3}, delimiter}

{:bin_heredoc, {b1, b2, b3}, _, _} ->
{:bin_heredoc, {b1 - 1, b2 - 1, b3}, nil}

{:list_heredoc, {b1, b2, b3}, _, _} ->
{:list_heredoc, {b1 - 1, b2 - 1, b3}, nil}

# raise here?
_ ->
error ->
Logger.warn("Unmatched token: #{inspect(error)}")
:error
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator

test "map with fields" do
contract = '(any()) -> \#{integer()=>any(), 1:=atom(), abc:=4}'

assert "foo(any) :: %{optional(integer) => any, 1 => atom, :abc => 4}" ==

expected = if Version.match?(System.version(), "< 1.13.0-rc.0") do
"foo(any) :: %{optional(integer) => any, 1 => atom, :abc => 4}"
else
"foo(any) :: %{optional(integer) => any, 1 => atom, abc: 4}"
end

assert expected ==
ContractTranslator.translate_contract(:foo, contract, false, Atom)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacroTest do
}
})

if Version.match?(System.version(), "< 1.13.0-rc.0") do
assert res == %{
"expand" => """
require(ElixirLS.Test.MacroA)
Expand Down Expand Up @@ -96,5 +97,39 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacroTest do
)
"""
}
else
assert res == %{
"expand" => """
require ElixirLS.Test.MacroA
ElixirLS.Test.MacroA.__using__([])
""",
"expandAll" => """
require ElixirLS.Test.MacroA
(
import ElixirLS.Test.MacroA
def macro_a_func do
:ok
end
)
""",
"expandOnce" => """
require ElixirLS.Test.MacroA
ElixirLS.Test.MacroA.__using__([])
""",
"expandPartial" => """
require ElixirLS.Test.MacroA
(
import ElixirLS.Test.MacroA
def macro_a_func do
:ok
end
)
"""
}
end
end
end
8 changes: 3 additions & 5 deletions apps/language_server/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,8 @@ defmodule ElixirLS.LanguageServer.ServerTest do
Inspects and writes the given `item` to the device.
```
@spec inspect(item, keyword) :: item
when item: var
```
"""
@spec inspect\
""" <> _
},
"label" => "inspect(item, opts \\\\ [])",
"parameters" => [%{"label" => "item"}, %{"label" => "opts \\\\ []"}]
Expand All @@ -999,7 +997,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
]
}
]
}) == resp
}) = resp
end

@tag :fixture
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# and its dependencies with the aid of the Config module.
import Config

# By default, the umbrella project as well as each child
# application will require this configuration file, ensuring
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"docsh": {:hex, :docsh, "0.7.2", "f893d5317a0e14269dd7fe79cf95fb6b9ba23513da0480ec6e77c73221cae4f2", [:rebar3], [{:providers, "1.8.1", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm", "4e7db461bb07540d2bc3d366b8513f0197712d0495bb85744f367d3815076134"},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "4a857f2c262b9f8ac2d72e31f4806cecc740192a", []},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "3aff3709d78f79c641fc0df47b0976aa7217b45e", []},
"erl2ex": {:git, "https://github.com/dazuma/erl2ex.git", "244c2d9ed5805ef4855a491d8616b8842fef7ca4", []},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"getopt": {:hex, :getopt, "1.0.1", "c73a9fa687b217f2ff79f68a3b637711bb1936e712b521d8ce466b29cbf7808a", [:rebar3], [], "hexpm", "53e1ab83b9ceb65c9672d3e7a35b8092e9bdc9b3ee80721471a161c10c59959c"},
Expand Down

0 comments on commit 90f6591

Please sign in to comment.