LuaLS / LuaLS/lua-language-server
Add `upvalue` semantic token modifier
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Issue không nêu tên tệp hoặc test nào. Hãy bắt đầu bằng việc tìm phần tạo semantic token của LuaLS và cơ chế phân giải phạm vi từ vựng được sử dụng cho các tham chiếu biến; theo dõi cách modifier global hiện có được gán. Công việc được xem là hoàn tất khi các tham chiếu được phân giải đến các biến trong phạm vi bao quanh nhận được modifier upvalue, các khai báo và biến cục bộ thông thường không thay đổi, và các closure lồng nhau được bao phủ bởi test.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- devtools
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100