Skip to content

Better global recognizing for loadfile #143

Open
@Bilal2453

Description

@Bilal2453

In some cases you might need to make the plugin recognize a specific local variable as global, without declaring that variable as an actual global, one of these cases are using load and loadfile were you can pass an env variable that represents the chunk environment.

*mainFile.lua

local env = setmetatable(
  {foo = function(a, b) return a == b end},
  {__index = _G}
)

loadfile('./secondFile.lua', 't', env)

*secondFile.lua

foo(1, 2) -- Undefined global `foo` . Lua Diagnostics.(undefined-global)

So i would suggest better recognizing for load/loadfile/loadstring environment or/and a custom emmylua annotations --- @global that marks the local var as a global one.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions