LuaLS / LuaLS/lua-language-server
[Feature Request] Setting for case-insensitive require resolution?
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
**Priority**
Low
**Description**
On Windows and Mac, file systems are case-insensitive by default. Lua's filepath resolution is based on the OS, so I feel like while only the exact spelling for a file should be autocompleted, when actually resolving the type of a module, lua-language-server should have an option to be case-insensitive.
**Example**
```
root/
├── myscript.lua
└── mymod.lua
```
```lua
-- myscript.lua --
local myMod = require "myMod"
```
Currently you can write a plugin similar to the one below using `ResolveRequire`
```lua
local libRoot = fs.current_path() / "library"
local function resolveCaseInsensitive(root, moduleName)
for file in fs.pairs(root) do
if fs.is_regular_file(file) then
local fileName = file:filename():string()
if fileName:lower() == (moduleName .. ".lua"):lower() then
return file:string()
end
end
end
end
---@param uri string # The URI of file
---@param name string # Argument of require()
---@return string[]?
function ResolveRequire(uri, name)
local libModuleFile = resolveCaseInsensitive(libRoot, name)
local localModuleFile = resolveCaseInsensitive(fs.path(furi.decode(uri)), name)
local result = {}
if libModuleFile then
result[#result+1] = furi.encode(libModuleFile)
end
if localModuleFile then
result[#result+1] = furi.encode(localModuleFile)
end
if #result ~= 0 then
return result
end
end
```
Alternatively, I propose that a spellchecking diagnostic could be introduced for resolving module names. If a name matches the name of a known module in all except its case, a blue or yellow squiggly would underline the string, and the message could be something like "did you mean 'otherName'". This could be an opt-in diagnostic if it is considered a breaking change.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从现有的 ResolveRequire 插件钩子开始,跟踪 require() 的模块解析路径。确定项目应实现不区分大小写的设置,还是选择加入的诊断功能,然后找到相关测试。当所选行为能够处理 Windows 和 macOS 上模块名称大小写不匹配的情况,并且有测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100