LuaLS / LuaLS/lua-language-server
The fallback scope pollutes the workpace environment with extraneous definitions.
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### How are you using the lua-language-server?
NeoVim
### Which OS are you using?
Linux
### What is the issue affecting?
Completion, Diagnostics/Syntax Checking, Hover
### Expected Behaviour
When the workspace configuation contains settings that affect which parts of Lua are available (i.e. the `runtime.version` and `runtime.builtin` settings); the workspace configuration should entirely take precedence over what's loaded with the fallback scope, here are some examples of behaviour I would expect from the server:
The setup is: `runtime.version` set to `Lua 5.2` in the workspace config and left as default, `Lua 5.4` in the server config.
1. Hover:
```lua
string.byte
--[[Should have this hyperlink in the description:
[View documents](http://www.lua.org/manual/5.2/manual.html#pdf-string.byte)
]]
```
2. Completions:
```lua
debug.info(1,
--[[Should show the following completion options:
"n", "S", "l", "t", "u", "f", "L"
]]
```
3. Hover and diagnostics:
```lua
utf8 = {}
smuggledChar = utf8.char
smuggledChar --Hover shouldn't show any description
utf8.char() --Diagnostics should stay quiet on this line, as the utf8 library was added in Lua 5.3 and thus it shouldn't know anything about this function as is.
```
Similar general case, but with the `debug` library disabled via `runtime.builtin` in the workspace settings, but left as is in the server config.
4. Hover, completion and diagnostics:
```lua
debug = {}
smuggledGetinfo = debug.getinfo
smuggledGetinfo --Shouldn't show any description.
debug.getinfo() --Diagnostics should stay quiet on this line.
debug.getinfo(1, --No completion options should be displayed.
```
### Actual Behaviour
For each of the cases above here's what happens instead:
Same setup as described above, `runtime.version` set to `Lua 5.2` in the workspace config and left as default, `Lua 5.4` in the server config:
1. Hover:
```lua
local test = string.byte
--[[Gives this hyperlink:
[View documents](http://www.lua.org/manual/5.4/manual.html#pdf-string.byte)
5.4 is the wrong version of the manual for this workspace environment
]]
```
2. Completions:
```lua
debug.info(1,
--[[Shows the following completion options:
"n", "S", "l", "t", "u", "f", "r", "L", "n", "S", "l", "t", "u", "f", "L"
The "r" option was added in Lua 5.4; what's probably worse is it gives both the Lua 5.4 options and Lua 5.2 options.
]]
```
3. Hover and diagnostics:
```lua
utf8 = {}
smuggledChar = utf8.char
smuggledChar --Hover shows the Lua 5.4 documentation description.
utf8.char() --Diagnostics say this function call is missing an argument and the return value cannot be discarded.
```
Same as in the expected behaviour section, the `debug` library is disabled via `runtime.builtin` in the workspace settings, left as is in the server config.
4. Hover, completion and diagnostics:
```lua
debug = {}
smuggledGetinfo = debug.getinfo
smuggledGetinfo --Shows debug.getinfo's description.
debug.getinfo() --Diagnostics say this function call is missing an argument and the return value cannot be discarded.
debug.getinfo(1,
--[[
Shows the following completion options:
"n", "S", "l", "t", "u", "f", "r", "L"
]]
```
### Reproduction steps
1. Configure `runtime.version` and `runtime.builtin` as described above;
2. Input the code snippets above to reproduce.
That's pretty much it
### Additional Notes
Additionally I tested the above cases on VS Code via VSCodium and was able to reproduce the same behaviour, but for cases 3 and 4 I didn't even have to smuggle the functions into local variables to get it to show the description, in VS Code the hover system was all too happy to show me definitions for functions that shouldn't exist in my environment. This behaviour might seem generally inconsequential for the language server's uses, but this creates some annoying restrictions for customized Lua environments where one might want to overwrite existing definitions for libraries; for example MoonSharp (an embeddable C# Lua interpreter, most commonly used in Unity projects) is only able to provide partial support for some libraries (like `os` and `debug`) on some platforms (again, Unity) and also gives the option to override the libraries; anyone who wishes to provide proper documentation for any changes to the standard libraries has to also get the user to change their server's settings in order to turn a library off entirely so the new definitions can be properly applied without any pollution for the specific workspace.
### Log File
_No response_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、runtime.version と runtime.builtin について、サーバーとワークスペースの値が競合する、提供された hover、completion、diagnostic のスニペットを再現します。fallback scope がどのように読み込まれ、ワークスペース設定と比較されるかを追跡します。完了の条件は、ワークスペース設定によって互換性のない fallback の定義、ドキュメント、診断、completion オプションが完全に抑制されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- developer-experience, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100