Add `upvalue` semantic token modifier
还没有人认领这个 Issue。
评估
调研方向
Issue 没有指出任何文件或测试。首先定位 LuaLS 的语义 token 生成,以及用于变量引用的词法作用域解析;跟踪现有 global modifier 的分配方式。完成的标准是:解析到外层作用域变量的引用会获得 upvalue modifier,声明和普通局部变量保持不变,并且嵌套 closure 有测试覆盖。
由索引模型根据 Issue 内容生成。
描述
LuaLS should expose whether a variable reference is an upvalue through a new upvalue semantic token modifier.
Currently, local variables and upvalues are both reported as:
semantic token type: variable
modifiers: -
while globals are already distinguished using:
semantic token type: variable
modifiers: global
This makes it impossible for editors such as VS Code to visually distinguish local variables from upvalues.
Example
local function outer()
local value = 123
return function()
print(value) -- upvalue
end
end
Currently the value reference inside the inner function is:
variable
It would be useful for LuaLS to report it as:
variable + upvalue
while the declaration remains:
variable
Proposed semantic token model
variable -> local variable
variable + upvalue -> upvalue
variable + global -> global variable
parameter -> function parameter
For example:
local foo = 1
local function outer(bar)
local baz = 2
return function(qux)
print(foo) -- upvalue
print(bar) -- upvalue
print(baz) -- upvalue
print(qux) -- parameter
print(print) -- global
end
end
would produce approximately:
foo -> variable + upvalue
bar -> variable + upvalue
baz -> variable + upvalue
qux -> parameter
print -> variable + global
Ordinary locals would remain simply:
variable
Why a modifier?
A modifier seems preferable to introducing a new semantic token type because upvalue describes a property of a variable reference rather than a fundamentally different kind of symbol.
It also fits the existing LuaLS representation of globals:
variable + global
This gives editor themes a simple way to distinguish all four cases:
variable
variable + upvalue
variable + global
parameter
Scope
The upvalue modifier should be applied to references resolved to a variable declared in an enclosing lexical scope.
For example:
local x = 1
local function f()
print(x)
end
would be:
x declaration -> variable
x reference -> variable + upvalue
Nested closures should work recursively.
Motivation
This would allow VS Code themes to use different colors for locals, parameters, upvalues, and globals, making lexical scope much easier to understand in closure-heavy Lua/LuaJIT code.
LuaLS already performs the necessary lexical-scope resolution; this proposal would expose that information through semantic tokens.
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- 平均合并
- 8 天 9 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
LuaLS/lua-language-server 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 62/100
LuaLS/lua-language-server#1776 ·
-
难度 3/5 1-2 天 新手友好度 65/100
LuaLS/lua-language-server#3463 · 5 条评论 ·
-
难度 4/5 3-5 天 新手友好度 55/100
LuaLS/lua-language-server#3461 ·
-
难度 3/5 1-2 天 新手友好度 68/100
LuaLS/lua-language-server#3460 · 1 条评论 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 68/100
LuaLS/lua-language-server#3459 · 1 个 reaction ·
查看 LuaLS/lua-language-server 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
openSUSE/python-rpm-macros#219 ·
-
bug mini.bracketed
难度 2/5 1-3 小时 新手友好度 75/100
-
accessibility bug typst
难度 2/5 1-3 小时 新手友好度 75/100
quarto-dev/quarto-cli#14947 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
HenrikBengtsson/CBI-software#134 ·
-
Nmap
难度 1/5 1 小时以内 新手友好度 85/100