Skip to content

Building a shared global environment #13445

@josevalim

Description

@josevalim

Hi @lukaszsamson, @mhanberg, @scohen, and @michalmuskala!

We have had several discussions in the past about improving Elixir for language servers. The discussions usually centered around two topics:

  • The global environment which contains all modules and functions, alongside their imports, aliases, requires, etc (note that not all modules are compiled with tracer events, such as the ones from Elixir or Erlang modules, so there is still need to fallback to runtime reflection APIs)

  • The buffer environment which is obtained by analyzing the currently open file and only makes sense within the current file (variable definition, module attributes)

In order to build the global environment, language servers need to add their own compilation tracers, and customize compilation. In turn, that requires a custom build directory and the need to compile all code at least twice. I would like to discuss the option of having Mix build this shared global environment instead.

In a nutshell, the idea is that Mix in dev mode will either add a separate .termdb file alongside each .beam file or augment the .beam files with an additional chunk. This way, language servers can rely on the regular code compilation to generate all artifacts they need and then use the file watching mechanism to observe when such files are added or removed. You can then load such files into another database of your preference. Another file will be made available with compilation diagnostics as well, so they can be shown in the UI.

Here are questions for you:

  1. How does this idea sound? Would it help your language server?
  2. I am assuming language servers can watch how .termdb files will be added to _build, is this true?

Assuming we are happy with this, we should discuss:

  1. How to store this information? .beam files? Separate files? Which format?
  2. What to store in those files. We can probably summarize the needs of all language servers.
  3. Anything else?

Thank you for your time.

PS: the language server can also just run mix compile to trigger a new compilation. However, we need to add locking to make sure we don't have concurrent compilations, @lukaszsamson plans to explore this feature too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions