lua-language-server
lua-language-server copied to clipboard
[Feature Request] Setting for case-insensitive require resolution?
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
-- myscript.lua --
local myMod = require "myMod"
Currently you can write a plugin similar to the one below using ResolveRequire
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.