Auto-completion of spec types, struct fields, struct names, Erlang module functions; Auto-completion variables based on type; Erlang module Quick Documentation;
Greetings,
Firstly, thanks for this amazing plugin.
I have not opened a bug as I do not know if the 12 cases that I am going to illustrate show the expected behavior or not (9 of Elixir, 3 of Erlang). I have detailed them in the following code. When applicable, I symbolize the position of the cursor with ▮ when doing Ctrl-Space (and Ctrl-Q when trying the doc).
If there is any case that I have put as wrong but it should work, I hope you can point me in the direction to solve it.
defmodule Namespace.User do
@moduledoc """
Documentation of Namespace.User
"""
alias Namespace.User
@type t :: %__MODULE__{
first_name: String.t(),
last_name: String.t()
}
defstruct first_name: "",
last_name: ""
@user_attr ""
@type user_fields_raw :: %{String.t() => String.t()}
@doc "Documentation of cast"
@spec cast(user_fields_raw) :: nil | User.t()
def cast(user = %{}) do
e = case user do
%{
"first_name" => first_name,
"last_name" => last_name
} -> %user{
first_name: first_name,
last_name: last_name
}
_ -> nil
end
end
# ✘ Case 1: cannot autocomplete spec types
# User. => cannot suggest the type `t`
# user_f => cannot suggest the type `user_fields_raw`
@spec cannot_suggest_spec_types(user_f▮) :: nil | User.▮
def cannot_suggest_spec_types(user_map) do
user_map |> cast()
end
# ✘ Case 2: cannot autocomplete fields of structs
def cannot_suggest_fields() do
u = %User{}
u.▮ # I would expect: first_name (String.t()), last_name (String.t())
end
# ✘ Case 3: cannot autocomplete functions of non Elixir/Stdlib modules
def cannot_suggest_functions() do
User.▮ # would expect functions or functions with types: cast(user_fields_raw) :: nil | User.t()
end
# ✘ Case 4: cannot show types of variables that are obtained/inferred by the defined types
# How can I get the info/associated tag in the IDE that `name` (or `u.first_name`) are of type String.t()?
def cannot_suggest_types() do
u = %User{}
name = u.first_name # no type/typespec info provided
end
# ✘ Case 5: cannot suggest struct name
def cannot_suggest_struct() do
u = %Us▮ # I would expect: %User
end
# ✓ Case 6: can suggest module attributes
def can_suggest_module_attributes() do
@us▮ # => @user_attr
end
# ✓ Case 7: can suggest std modules and functions, and quick documentation (Ctrl-Q)
def can_suggest_std_modules_and_functions_and_docs() do
Ma▮ # => Map, Macro, MapSet, ...
Map.▮ # => -map/2-fun-0, -merge/3-fun-0, ...
Map.g▮ # => get, get, get_and_update, ...
end
# ✘ Case 8: cannot suggest type of std function args by expected type
def cannot_suggest_type_of_std_function_args_by_expected_type() do
r = 1..3
String.slice("elixir", ▮) # => I would expect: r since it is a Range.t() and matches:
# String.slice(t(), Range.t()) :: t()
end
# ✘ Case 9: cannot detect wrong types
# can be detected with the tool dialyzer/dialyxir (`has no local return`)
# but not directly by the IDE or while typing (typically an error on the left side)
def cannot_detect_wrong_types() do
cast(%{"one" => 3}) # should indicate conflict types with the typespec of cast:
# cast(user_fields_raw) being user_fields_raw:
# ✓ - %{String.t() => String.t()} <- expected type
# ✘ - %{String.t() => integer()} <- wrong type provided
end
# Erlang cases:
# ✓ Case 10: can suggest erlang modules
def can_suggest_erlang_modules() do
:ma▮ # => math, make, maps, ...
end
# ✘ Case 11: cannot show quick documentation of erlang modules
def cannot_suggest_documentation_of_erlang_modules() do
:ma▮ # => math, make, maps, ... (Ctrl-Q) # => no documentation found
end
# ✘ Case 12: cannot suggest erlang functions
def cannot_suggest_erlang_functions() do
:math.▮ # I would expect: acos, pow, ...
end
end
Thank you in advance.
Very thorough, thank you.
Thank you, @KronicDeth.
I assume this is expected behavior, having these 9 uses cases not working. In such scenario, although I am really busy, but I could try studying and implementing it eventually, Which case would be the easiest to support? Can you provide some path of resolution? It would be ideal if you help me saying something like W use case can be achieved probably by touching X functions, Y files and Z features of this repository; have a look at the repository T/branch U for inspiration and the documentation present in S.
I don't know Kotlin (although I worked with Java in the past) and I have never developed an Intellij plugin (good practices, environment, tests...), but I suppose I can have it as another side project to support some of these features during the next months, if no one is going to work on these.
Regards
I would have expected 3 and 12 to work. I think 11 doesn't work because I never had OTP built with docs installed, so there's no to test against when using asdf