LuaLS / LuaLS/lua-language-server

The `set` pattern for `single range char` is not working in glob

未关闭
#2,754 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I am testing the glob like pattern used in Lua.doc.<scope>Name, and the set pattern seems not working for single character.

  • .luarc.jsonc
{
    "doc.privateName": [
        "_[aeiouA-Z]"   // underscore followed by any upper letter, or lower letters a|e|i|o|u
    ]
}
  • test.lua
---@class A
local A = {}
A._A = 1
A._Z = 1
A._a = 1
A._e = 1
A._z = 1
A._AA = 1
A._aa = 1

---@type A
local t = {}
print(t._A)     -- warning
print(t._Z)     -- warning
print(t._a)     -- warning
print(t._e)     -- warning
print(t._z)     -- ok
print(t._AA)    -- ok
print(t._aa)    -- ok
Actual Behaviour
---@type A
local t = {}
print(t._A)     -- warning
print(t._Z)     -- warning
print(t._a)     -- ok (false negative)
print(t._e)     -- ok (false negative)
print(t._z)     -- ok
print(t._AA)    -- ok
print(t._aa)    -- ok
  • the single range word aeiou is not working as expected
Reproduction steps

Use the provided snippet

Additional Notes

I know that the glob pattern syntax in defined using LPeg: https://github.com/LuaLS/lua-language-server/blob/ddc96bd1ec0be95a985ab82531763578bf7eb793/script/glob/glob.lua#L19-L46
I am not familiar with LPeg, but by adding a print(#range, range[1], range[2]) inside mt:range() here, those single range word seems don't even get parsed. 😕 https://github.com/LuaLS/lua-language-server/blob/ddc96bd1ec0be95a985ab82531763578bf7eb793/script/glob/matcher.lua#L99-L100

With a bit of testing, the RangeUnit definition seems should be changed from:

    ['RangeUnit']   = m.Ct(m.C(m.V'RangeWord') * m.P'-' * m.C(m.V'RangeWord'))
                    + m.V'RangeWord',

to =>

    ['RangeUnit']   = m.Ct(m.C(m.V'RangeWord') * m.P'-' * m.C(m.V'RangeWord'))
                    + m.Ct(m.C(m.V'RangeWord')),

Then the set logic for single range character starts to work 🎉
But I don't know why it works this way 🙈


Can anyone comment on my above suggested change?
If this is correct, I am going to open a PR. 🙂

Log File

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 script/glob/glob.lua 和 script/glob/matcher.lua 开始,尤其关注 RangeUnit grammar 和 mt:range()。使用提供的 .luarc.jsonc 和 test.lua 代码片段复现该行为,然后验证单字符范围是否匹配预期的大写字母和元音情形,同时不改变多字符行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。