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:
---@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