LuaLS/lua-language-server

Better global

Open

#283 ouverte le 5 déc. 2020

Voir sur GitHub
 (3 commentaires) (4 réactions) (0 assignés)Lua (427 forks)batch import
help wanted

Métriques du dépôt

Stars
 (4 251 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

I'm going to do some work for global variable distinguishing environments. At present, my idea is as follows:

---@global global -- the table will be merged into current globals. the second `global` can be omitted
local t = {
    X = 1,
    Y = 2,
    Z = 3,
}

print(X) -- `X` is `t.X`
---@global module1, module2 -- the table will be merged into environment `module1` and `module2`
local t = {
    X = 1,
    Y = 2,
    Z = 3,
}

print(X) -- `x` is undefined

---@environment module1, global -- set the current environment can visit `module1` and `global`
print(X) -- `X` is `t.X`

---@environment module1
print(X) -- `X` is `t.X` and `print` is undefined

EDIT:

---@partial class _G -- the table will be merged into class `_G`. the default environment is class `_G`
local t = {
    X = 1,
    Y = 2,
    Z = 3,
}

print(X) -- `X` is `t.X`
---@class module1
local t = {
    X = 1,
    Y = 2,
    Z = 3,
}

print(X) -- `x` is undefined

---@environment module1, _G -- set the current environment can visit class `module1` and `_G`
print(X) -- `X` is `t.X`

---@environment module1
print(X) -- `X` is `t.X` and `print` is undefined

Guide contributeur