LuaLS / LuaLS/lua-language-server

Lazy load workspace libraries

Open
#1,745 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

I'm using sumneko_lua with Neovim and I wanted to have completions from the Lua plugins I have installed, so I inserted all the paths to the plugins that I have into `Lua.workspace.library`

But the problem is that it that sumneko_lua loads *all* the files inside those libraries right on startup, causing a massive increase to my RAM usage. Normally sumneko_lua only takes up 100-200 MB, but after adding 40+ library paths, sumneko now takes up to 600-700 MB.

Is it possible to load the libraries into the workspace, _only_ when it is needed?
For example, I don't believe the library needs to be loaded when you're only completing a require statement:
```lua
local foobar = require("foob|
```
sumneko_lua only needs to scan the directories listed in `Lua.workspace.library` to find the correct files.

Once the require statement is completed, and its return value is interacted with:
```lua
local foobar = require("foobar")
foobar.call_functi|
```
sumneko_lua can now then load the library in order to produce the completions.

Is it possible for something like this to be implemented?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Lua.workspace.library paths are loaded and how require-statement completion finds matching files. Then examine when the required library becomes available for member completions. Done means library paths are searched without loading every file at startup, while completions such as require("foobar") and foobar.call_function still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
devtools, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.