elixir-lsp / vscode-elixir-ls

Elixir language support and debugger for VS Code, powered by ElixirLS.
https://marketplace.visualstudio.com/items?itemName=JakeBecker.elixir-ls
MIT License
545 stars 105 forks source link

@spec annotation suggestion missing parentheses #338

Closed my4ng closed 1 year ago

my4ng commented 1 year ago

Environment

Troubleshooting

Details

As described in the title, the @spec annotation suggestion is missing parentheses after each built-in type, and hence they are not properly syntax highlighted, unlike custom defined types which do include the parentheses. I am new to elixir, so I am not sure if there's any rule regarding the consistency.

Example:

Custom type
@type t :: %T{
  ...
}

@spec f :: [t(), ...]
def f do
  [ %T{...}]
end
Builtin type
@spec add(number, number) :: number
def add(m, n), do: m + n
lukaszsamson commented 1 year ago

Elixir formatter does not care if no parens or parens version is used. While https://hexdocs.pm/elixir/typespecs.html seems to prefer parens form, the source code of elixir itself prefers no parens. We treat it as a stylistic choice to prefer no parens for builtin types.

Regarding the syntax highlighting, there are no specific rules for typespecs (https://github.com/elixir-lsp/vscode-elixir-ls/issues/311). Parens form gets highlighted as function call (entity.name.function-call.elixir source.elixir), no parens as variable (source.elixir).