LuaLS / LuaLS/lua-language-server
Difference in behavior between table literal, dictionary, and class in terms of completion
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Maybe more of a feature request than a bug, but I noticed some interesting differences between classes, dictionaries, and table literals in terms of completions.
Using this code as a base:
```lua
---@class TestClass
---@field test_group TestGroup
---@class TestGroup
---@field test_field string
---@alias TestTableDictionary {["test_group"]: {["test_field"]: string}}
---@alias TestTableLiteral {test_group: {test_field: string}}
---@type TestClass
local test_class
local test_group = "test_group"
local test1 = test_class["test_group"].test_field
---@type TestTableDictionary
local test_table_dictionary
local test_group = "test_group"
local test2 = test_table_dictionary[test_group].test_field
---@type TestTableLiteral
local test_table_literal
local test_group = "test_group"
local test3 = test_table_literal[test_group].test_field
```
I would expect the completion for test1, test2, and test3 to be equivalent. However there are some interesting differences.
For test 1 if we do this `local test1 = test_class[test_group].test_field` the type of test1 is unknown and there is no completion suggestions for `test_class[test_group].` Both `test_class["test_group"].test_field` and `test_class.test_group.test_field` work correctly.
For test 2 `test_table_dictionary[test_group].test_field` works correctly. `test_table_dictionary.test_group.test_field` gives the right value but does not show any completion suggestions like the classes do.
For test 3 the table literal is the best of all worlds. You can do ` test_table_literal[test_group].test_field` as well as get completions on test_table_literal.test_group.test_field.
As I am using classes in a lot of places and they are useful as they can be spread across multiple lines and the fields can have longer descriptions it would be awesome to see the ability to do something like `test_class[test_group].test_field` for classes
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
該 issue 未指出任何原始檔案或測試;請先使用三個 Lua 範例,追蹤 language server 對類別欄位、字典別名和表格字面值的 completion 處理。等價的索引表達式和點號表達式能夠提供預期型別和 completion 建議,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- developer-experience
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100