diff options
-rw-r--r-- | script-beta/core/semantic-tokens.lua | 2 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 8 | ||||
-rw-r--r-- | script-beta/vm/getGlobals.lua | 22 | ||||
-rw-r--r-- | test-beta.lua | 2 | ||||
-rw-r--r-- | test-beta/diagnostics/init.lua | 9 |
5 files changed, 32 insertions, 11 deletions
diff --git a/script-beta/core/semantic-tokens.lua b/script-beta/core/semantic-tokens.lua index af1409c1..8947bd88 100644 --- a/script-beta/core/semantic-tokens.lua +++ b/script-beta/core/semantic-tokens.lua @@ -64,7 +64,7 @@ Care['getlocal'] = function (source, results) end -- 3. 不是函数的局部变量 local hasFunc - for _, def in ipairs(vm.getDefs(loc)) do + for _, def in ipairs(vm.getDefs(loc, 'simple')) do if def.type == 'function' or (def.type == 'library' and def.value.type == 'function') then hasFunc = true diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 0b1f1a85..31e2b9d8 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1766,14 +1766,6 @@ function m.searchSameFields(status, simple, mode) if first.tag == '_ENV' then -- 检查全局变量的分支情况,需要业务层传入 interface.global m.checkSameSimpleInGlobal(status, simple[1], 1, queue) - if first.ref then - for _, ref in ipairs(first.ref) do - queue[#queue+1] = { - obj = ref, - start = 1, - } - end - end else simple.global = nil tableInsert(simple, 1, 'l|_ENV') diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index c5d6dc21..f5b22ff9 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -4,14 +4,34 @@ local files = require 'files' local library = require 'library' local util = require 'utility' +local function searchG(ref, results) + +end + +local function searchEnvRef(ref, results) + if ref.type == 'setglobal' + or ref.type == 'getglobal' then + results[#results+1] = ref + searchG(ref, results) + elseif ref.type == 'getlocal' then + results[#results+1] = ref.next + searchG(ref.next, results) + end +end + local function getGlobalsOfFile(uri) local globals = {} local ast = files.getAst(uri) if not ast then return globals end + local results = {} local env = guide.getENV(ast.ast) - local results = guide.requestFields(env) + if env.ref then + for _, ref in ipairs(env.ref) do + searchEnvRef(ref, results) + end + end for _, res in ipairs(results) do local name = guide.getSimpleName(res) if name then diff --git a/test-beta.lua b/test-beta.lua index d975832b..4148bb2d 100644 --- a/test-beta.lua +++ b/test-beta.lua @@ -6,7 +6,7 @@ package.path = package.path .. ';' .. rootPath .. '\\test-beta\\?\\init.lua' local fs = require 'bee.filesystem' ROOT = fs.path(rootPath) -LANG = 'en-US' +LANG = 'zh-CN' collectgarbage 'generational' diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua index c33d4f0a..8f1bb2c6 100644 --- a/test-beta/diagnostics/init.lua +++ b/test-beta/diagnostics/init.lua @@ -560,6 +560,15 @@ local <!t!> = {} <!t!>[1] = 1 ]] +TEST [[ +T1 = 1 +_ENV.T2 = 2 +_G.T3 = 2 +print(T1) +print(T2) +print(T3) +]] + --TEST [[ -----@class <!Class!> -----@class <!Class!> |