LuaLS / LuaLS/lua-language-server

Non-deterministic behavior when there are multiple parent folders with .luarc.json.

Open
#2,169 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### How are you using the lua-language-server?

NeoVim

### Which OS are you using?

Linux

### What is the issue affecting?

Diagnostics/Syntax Checking

### Expected Behaviour

When the language server processes a Lua file, it should use the .luarc.json file that is closest (in the chain of parent folders) to the file being opened. So in this case:
```
dir1
|- .luarc.json
\_ dir2
|- .luarc.json
\_ code.lua
```
Opening code.lua should use dir2/.luarc.json.

### Actual Behaviour

Non-deterministic behavior: sometimes it uses dir1/.luarc.json and sometimes it uses dir2/.luarc.json. This is a big problem e.g. in cases where those two files specify different versions of Lua.

### Reproduction steps

Create the directory/file structure above, specifying different version of Lua in each one, then put some code in code.lua that is sensitive to the version, then run lua-language-server (I run it through Neovim) on code.lua, and observe sometimes it assumes one version of Lua and other times it uses the other.

Deleting dir1/.luarc.json then eliminates the non-deterministic behavior and it always uses dir2/.luarc.json.

### Additional Notes

_No response_

### Log File

_No response_

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 reproducing the directory structure with two .luarc.json files and opening code.lua through Neovim. Trace how lua-language-server discovers configuration files and compare repeated runs with different Lua versions configured. Done means the nearest parent configuration is selected consistently, with the reproduction no longer showing nondeterministic diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.