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.5k stars 196 forks source link

Stale data lookups in completions #269

Open Nitrodist opened 4 years ago

Nitrodist commented 4 years ago

Hello, I am a vim+coc.nvim user and I use this project (elixir-ls) to provide code-completion etc.

I want to discuss the idea of using the stale analysis data during the various compilation steps so that code completion continues to work instead of returning nothing.

In my large project, it takes 12 seconds for code-completion to work again. I'm editing a test written in a .exs file in this example - maybe I'm doing something wrong (I am new!), but during those 12 seconds I know that I haven't made a functional change to anything, so I'd be fine with old lookups were to still be returned after I happen to use :w to save my work in progress. Even if it's 5 seconds, I'd rather have those 5 seconds of my life back, you know!

Let's say that I write to the file and it has compilation errors. This may be common because I'll return to my work after I've saved my work to disk before having lunch. I've now returned to fix my code and I don't have access to the basic information and advantages provided by code-completion with elixir-ls.

Stale data lookups fix these issues and it would improve the utility of elixir-ls considerably.

Environment

elixir --version
Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.10.3 (compiled with Erlang/OTP 21)

Logs

Compiling with Mix env test
[Info  - 11:41:05 a.m.] Compile took 402 milliseconds
[Info  - 11:41:05 a.m.] [ElixirLS Dialyzer] Checking for stale beam files
[Info  - 11:41:05 a.m.] [ElixirLS Dialyzer] Found 0 changed files in 76 milliseconds
[Info  - 11:41:08 a.m.] [ElixirLS Dialyzer] Analyzing 2 modules: [:metrics_exometer, :metrics_folsom]
[Info  - 11:41:08 a.m.] [ElixirLS Dialyzer] Analysis finished in 2775 milliseconds
[Info  - 11:41:10 a.m.] [ElixirLS Dialyzer] Writing manifest...
[Info  - 11:41:11 a.m.] [ElixirLS Dialyzer] Done writing manifest in 2304 milliseconds.
[Info  - 11:41:14 a.m.] Dialyzer analysis is up to date
[Info  - 11:41:21 a.m.] [ElixirLS WorkspaceSymbols] Indexing...
[Info  - 11:41:26 a.m.] [ElixirLS WorkspaceSymbols] Module discovery complete
[Info  - 11:41:26 a.m.] [ElixirLS WorkspaceSymbols] 480 callbacks added to index
[Info  - 11:41:30 a.m.] [ElixirLS WorkspaceSymbols] 2591 modules added to index
[Info  - 11:41:30 a.m.] [ElixirLS WorkspaceSymbols] 1712 types added to index
[Info  - 11:41:49 a.m.] [ElixirLS WorkspaceSymbols] 34255 functions added to index

Compiling with Mix env test
[Info  - 12:19:02 p.m.] Compile took 388 milliseconds
[Info  - 12:19:02 p.m.] [ElixirLS Dialyzer] Checking for stale beam files
[Info  - 12:19:03 p.m.] [ElixirLS Dialyzer] Found 0 changed files in 136 milliseconds
[Info  - 12:19:06 p.m.] [ElixirLS Dialyzer] Analyzing 2 modules: [:metrics_exometer, :metrics_folsom]
[Info  - 12:19:06 p.m.] [ElixirLS Dialyzer] Analysis finished in 3152 milliseconds
[Info  - 12:19:08 p.m.] [ElixirLS Dialyzer] Writing manifest...
[Info  - 12:19:09 p.m.] [ElixirLS Dialyzer] Done writing manifest in 2069 milliseconds.
[Info  - 12:19:14 p.m.] Dialyzer analysis is up to date
[Info  - 12:19:14 p.m.] [ElixirLS WorkspaceSymbols] Updating index...
[Info  - 12:19:19 p.m.] [ElixirLS WorkspaceSymbols] 0 modules need reindexing
[Info  - 12:19:19 p.m.] [ElixirLS WorkspaceSymbols] 0 modules added to index
[Info  - 12:19:19 p.m.] [ElixirLS WorkspaceSymbols] 0 types added to index
[Info  - 12:19:19 p.m.] [ElixirLS WorkspaceSymbols] 0 functions added to index
[Info  - 12:19:19 p.m.] [ElixirLS WorkspaceSymbols] 0 callbacks added to index
lukaszsamson commented 4 years ago

It shouldn't be very difficult to implement. elixir_sense library does most of the work and it should rather work fine (I'd expect some occasional crashes as it analyses modules on the fly). A PR would definitely be welcome

lukaszsamson commented 10 months ago

It's not a full solution but https://github.com/elixir-lsp/elixir_sense/commit/6b378da5b7b1d43a0af1c8761b1a035e3929efdd is a step in the direction of building cache of completion symbols