LuaLS / LuaLS/lua-language-server

[Feature Request] Setting for case-insensitive require resolution?

未關閉
#2,845 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從現有的 ResolveRequire 外掛 hook 開始,追蹤 require() 的模組解析路徑。判斷專案應實作不區分大小寫的設定,還是選擇加入的診斷功能,然後找出相關測試。當所選行為能處理 Windows 和 macOS 上模組名稱大小寫不一致的情況,並且有測試涵蓋時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。