You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: Per-firectory or per-file environments #3185
Is there a way I could set files under a specific directory to use a @meta file as an environment? If not, how would I accomplish this? In my project, a certain folder as a number of modular scripts that have an environment separate to the rest of the project.
i have recently found that doing local _ENV = _ENV --[[@as SomeClassToUseAsEnv]] at the top of a file kinda-sorta works to change the environment - the autocomplete is still only using the regular global environment, but the type checking applies the new class as env to tell you what globals are actually valid! (and i've been considering a small plugin hack to rewrite some special comment into this, but it doesn't quite work well enough for me to go down that road...)
(Notably though, doing ---@cast _ENV SomeClassToUseAsEnv instead seems to do nothing at all!)
Activity
tomlau10 commentedon May 19, 2025
There are already a few similar feature requests and discussions:
The closest thing for supporting separate environment currently is using the multi-root workspace feature: https://luals.github.io/wiki/developing/#multiple-workspace-support
And vscode is one of the editors that support this feature.
justarandomgeek commentedon Jul 25, 2025
i have recently found that doing
local _ENV = _ENV --[[@as SomeClassToUseAsEnv]]at the top of a file kinda-sorta works to change the environment - the autocomplete is still only using the regular global environment, but the type checking applies the new class as env to tell you what globals are actually valid! (and i've been considering a small plugin hack to rewrite some special comment into this, but it doesn't quite work well enough for me to go down that road...)(Notably though, doing
---@cast _ENV SomeClassToUseAsEnvinstead seems to do nothing at all!)ChrisKader commentedon Mar 8, 2026
This is a start. https://github.com/ChrisKader/lua-language-server
"Per File" env.
Svarshick commentedon Jun 6, 2026
@ChrisKader, have you considered opening a PR for the ---@env feature?