LuaLS / LuaLS/lua-language-server

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

Đang mở
#2,845 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ả

**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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với plugin hook ResolveRequire hiện có và lần theo đường dẫn phân giải module của require(). Xác định xem dự án nên triển khai một thiết lập không phân biệt chữ hoa chữ thường hay một chẩn đoán opt-in, sau đó tìm các kiểm thử liên quan. Được xem là hoàn tất khi hành vi được chọn xử lý việc không khớp chữ hoa chữ thường trong tên module trên Windows và macOS, và được các kiểm thử bao phủ.

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ó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.