summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-25 14:59:37 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-25 14:59:37 +0800
commit8f9d4b2d402584f7b2439a4e211fb5ca45fd7125 (patch)
tree70ac28b0fe94de04c625e90c47696d139c5e17e4 /script
parentae42fbc3b3470b03aa2e86934883acf807a037c4 (diff)
downloadlua-language-server-8f9d4b2d402584f7b2439a4e211fb5ca45fd7125.zip
delete `isGlobalLibraryName`
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/lowercase-global.lua24
-rw-r--r--script/core/semantic-tokens.lua20
-rw-r--r--script/vm/library.lua21
3 files changed, 36 insertions, 29 deletions
diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua
index 500f84dd..7c5ac720 100644
--- a/script/core/diagnostics/lowercase-global.lua
+++ b/script/core/diagnostics/lowercase-global.lua
@@ -1,8 +1,9 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local config = require 'config'
-local vm = require 'vm'
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local config = require 'config'
+local vm = require 'vm'
+local globalMgr = require 'vm.global-manager'
local function isDocClass(source)
if not source.bindDocs then
@@ -44,8 +45,17 @@ return function (uri, callback)
if isDocClass(source) then
return
end
- if vm.isGlobalLibraryName(name) then
- return
+ if definedGlobal[name] == nil then
+ definedGlobal[name] = false
+ local global = globalMgr.getGlobal('variable', name)
+ if global then
+ for _, set in ipairs(global:getSets(uri)) do
+ if vm.isMetaFile(guide.getUri(set)) then
+ definedGlobal[name] = true
+ return
+ end
+ end
+ end
end
callback {
start = source.start,
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index e1c262ea..d42e5b04 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -8,6 +8,7 @@ local converter = require 'proto.converter'
local infer = require 'vm.infer'
local config = require 'config'
local linkedTable = require 'linked-table'
+local globalMgr = require 'vm.global-manager'
local Care = util.switch()
: case 'getglobal'
@@ -16,7 +17,23 @@ local Care = util.switch()
if not options.variable then
return
end
- local isLib = vm.isGlobalLibraryName(source[1])
+
+ local name = source[1]
+ local isLib = options.libGlobals[name]
+ if isLib == nil then
+ isLib = false
+ local global = globalMgr.getGlobal('variable', name)
+ if global then
+ local uri = guide.getUri(source)
+ for _, set in ipairs(global:getSets(uri)) do
+ if vm.isMetaFile(guide.getUri(set)) then
+ isLib = true
+ break
+ end
+ end
+ end
+ options.libGlobals[name] = isLib
+ end
local isFunc = infer.getInfer(source):hasFunction()
local type = isFunc and define.TokenTypes['function'] or define.TokenTypes.variable
@@ -789,6 +806,7 @@ return function (uri, start, finish)
uri = uri,
state = state,
text = files.getText(uri),
+ libGlobals = {},
variable = config.get(uri, 'Lua.semantic.variable'),
annotation = config.get(uri, 'Lua.semantic.annotation'),
keyword = config.get(uri, 'Lua.semantic.keyword'),
diff --git a/script/vm/library.lua b/script/vm/library.lua
index 49f7adb0..e7bf4f42 100644
--- a/script/vm/library.lua
+++ b/script/vm/library.lua
@@ -13,24 +13,3 @@ function vm.getLibraryName(source)
end
return nil
end
-
-local globalLibraryNames = {
- 'arg', 'assert', 'error', 'collectgarbage', 'dofile', '_G', 'getfenv',
- 'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring',
- 'module', 'next', 'pairs', 'pcall', 'print', 'rawequal',
- 'rawget', 'rawlen', 'rawset', 'select', 'setfenv',
- 'setmetatable', 'tonumber', 'tostring', 'type', '_VERSION',
- 'warn', 'xpcall', 'require', 'unpack', 'bit32', 'coroutine',
- 'debug', 'io', 'math', 'os', 'package', 'string', 'table',
- 'utf8', 'newproxy',
-}
-local globalLibraryNamesMap
-function vm.isGlobalLibraryName(name)
- if not globalLibraryNamesMap then
- globalLibraryNamesMap = {}
- for _, v in ipairs(globalLibraryNames) do
- globalLibraryNamesMap[v] = true
- end
- end
- return globalLibraryNamesMap[name] or false
-end