lua-language-server
lua-language-server copied to clipboard
[Features Request] Import folder modules in auto require by folder name instead or beside of init
Given such a folder structure:
.
└── module
├── init.lua
└── submodule
└── init.lua
Now in module/init.lua i would like to import submodule. Currently it only works if I try to import it via init:

However it would be nice to import them as submodule as the foldername would suggest:

P.S. Side notice, in my demonstration test I noticed, returning a string in module/submodule/init.lua won't show up in autocompletion suggestions when typing init.
Are there any plans to address this issue?
I'm a bit annoyed that I can't autorequire many of my modules, which are setup in this way (myModule/init.lua).
That's why I tried debbugging the server and I think I found a temporary (theoretical) solution:
script/core/completion/completion.lua:364
local path = furi.decode(uri)
local initDirname = path:match("([^/\\]+)[/\\]init.lua$") -- TODO: consider current package.path configuration
local fileName = path:match '[^/\\]*$'
local stemName = fileName:gsub('%..+', '')
if not locals[stemName]
and not vm.hasGlobalSets(state.uri, 'variable', stemName)
and not config.get(state.uri, 'Lua.diagnostics.globals')[stemName]
and (
stemName:match '^[%a_][%w_]*$'
and matchKey(word, stemName)
or
initDirname
and initDirname:match "^[%a_][%w_]*$"
and matchKey(word, initDirname)
) then
This change would allow for folder modules being detected, if they have an init.lua file. I couldn't check if it's working, because I don't know how to tell vscode to launch the projects lua-language-server instead of my installed one. Now I tried to delete the extension server and replace these files with bin/*, but it did not (after restarting) show the additional modules with */init.lua.
And this shouldn't be a final solution (if it works at all), because somehow package.path should be considered. (e.g. someone decides to use ?/setup.lua or removes ?/init.lua)
Thanks in advance!
Close as completed via #1711.