Skip to content

Commit 8f9d4b2

Browse files
committed
delete isGlobalLibraryName
1 parent ae42fbc commit 8f9d4b2

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

script/core/diagnostics/lowercase-global.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
local files = require 'files'
2-
local guide = require 'parser.guide'
3-
local lang = require 'language'
4-
local config = require 'config'
5-
local vm = require 'vm'
1+
local files = require 'files'
2+
local guide = require 'parser.guide'
3+
local lang = require 'language'
4+
local config = require 'config'
5+
local vm = require 'vm'
6+
local globalMgr = require 'vm.global-manager'
67

78
local function isDocClass(source)
89
if not source.bindDocs then
@@ -44,8 +45,17 @@ return function (uri, callback)
4445
if isDocClass(source) then
4546
return
4647
end
47-
if vm.isGlobalLibraryName(name) then
48-
return
48+
if definedGlobal[name] == nil then
49+
definedGlobal[name] = false
50+
local global = globalMgr.getGlobal('variable', name)
51+
if global then
52+
for _, set in ipairs(global:getSets(uri)) do
53+
if vm.isMetaFile(guide.getUri(set)) then
54+
definedGlobal[name] = true
55+
return
56+
end
57+
end
58+
end
4959
end
5060
callback {
5161
start = source.start,

script/core/semantic-tokens.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local converter = require 'proto.converter'
88
local infer = require 'vm.infer'
99
local config = require 'config'
1010
local linkedTable = require 'linked-table'
11+
local globalMgr = require 'vm.global-manager'
1112

1213
local Care = util.switch()
1314
: case 'getglobal'
@@ -16,7 +17,23 @@ local Care = util.switch()
1617
if not options.variable then
1718
return
1819
end
19-
local isLib = vm.isGlobalLibraryName(source[1])
20+
21+
local name = source[1]
22+
local isLib = options.libGlobals[name]
23+
if isLib == nil then
24+
isLib = false
25+
local global = globalMgr.getGlobal('variable', name)
26+
if global then
27+
local uri = guide.getUri(source)
28+
for _, set in ipairs(global:getSets(uri)) do
29+
if vm.isMetaFile(guide.getUri(set)) then
30+
isLib = true
31+
break
32+
end
33+
end
34+
end
35+
options.libGlobals[name] = isLib
36+
end
2037
local isFunc = infer.getInfer(source):hasFunction()
2138

2239
local type = isFunc and define.TokenTypes['function'] or define.TokenTypes.variable
@@ -789,6 +806,7 @@ return function (uri, start, finish)
789806
uri = uri,
790807
state = state,
791808
text = files.getText(uri),
809+
libGlobals = {},
792810
variable = config.get(uri, 'Lua.semantic.variable'),
793811
annotation = config.get(uri, 'Lua.semantic.annotation'),
794812
keyword = config.get(uri, 'Lua.semantic.keyword'),

script/vm/library.lua

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,3 @@ function vm.getLibraryName(source)
1313
end
1414
return nil
1515
end
16-
17-
local globalLibraryNames = {
18-
'arg', 'assert', 'error', 'collectgarbage', 'dofile', '_G', 'getfenv',
19-
'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring',
20-
'module', 'next', 'pairs', 'pcall', 'print', 'rawequal',
21-
'rawget', 'rawlen', 'rawset', 'select', 'setfenv',
22-
'setmetatable', 'tonumber', 'tostring', 'type', '_VERSION',
23-
'warn', 'xpcall', 'require', 'unpack', 'bit32', 'coroutine',
24-
'debug', 'io', 'math', 'os', 'package', 'string', 'table',
25-
'utf8', 'newproxy',
26-
}
27-
local globalLibraryNamesMap
28-
function vm.isGlobalLibraryName(name)
29-
if not globalLibraryNamesMap then
30-
globalLibraryNamesMap = {}
31-
for _, v in ipairs(globalLibraryNames) do
32-
globalLibraryNamesMap[v] = true
33-
end
34-
end
35-
return globalLibraryNamesMap[name] or false
36-
end

0 commit comments

Comments
 (0)