elixir-lsp / elixir-ls

A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol"
https://elixir-lsp.github.io/elixir-ls/
Apache License 2.0
1.43k stars 190 forks source link

typespecs do not work for implemented behaviour functions #1102

Closed pauldemarco closed 1 day ago

pauldemarco commented 1 month ago

Environment

Current behavior

There is no autocomplete for function arguments that are keywords. This applies to Modules that implement a behaviour function and have their own typespec.

Reproduction steps:

This is our goal -- notice how autocomplete works with GenServer's start_link options: image

Let's try to recreate this awesomeness with our own Module:

  1. Now, define a behaviour that has a @callback method with an options (keyword) argument.
  2. Use the behaviour in a Module with @behaviour MyBehaviour.
  3. Implement the function and add the typespec for the options.
  4. Now in a calling function, try to use the method, and notice there is no autocomplete as it bypasses the Module's typespec and gives you the Behaviours definition.
lukaszsamson commented 1 week ago

The reason for what you observe is there are 2 separate mechanisms generating completions. One is used for remote functions and the other for local buffer completions. The remote one relies on compiled beams - it extracts info from EEP48 doc chunks and typespec chunks. The local one relies on AST analysis. Keyword argument completions are only implemented for remote typespec (as returned by Code.Typespec.fetch_specs internal elixir API). We would need something similar that extracts keyword lists from typespec AST in current buffer. Side note: typespecs are going to be deprecated in elixir and replaced with typesystem. There is a plan for typesystem to handle keyword lists but it most likely will not land soon

pauldemarco commented 1 week ago

Thanks for the clarification. Looking forward to the typesystem!

lukaszsamson commented 1 day ago

Keyword list completions from the current buffer are already tracked in https://github.com/elixir-lsp/elixir-ls/issues/1070