diff options
-rw-r--r-- | .vscode/launch.json | 2 | ||||
-rw-r--r-- | .vscode/settings.json | 4 | ||||
-rw-r--r-- | main-beta.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/init.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/table.lua | 9 | ||||
-rw-r--r-- | script-beta/vm/eachDef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachField.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachRef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/getInfer.lua | 46 |
9 files changed, 62 insertions, 15 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 438fe0d7..5431ca74 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -48,7 +48,7 @@ "type": "lua", "request": "attach", "stopOnEntry": true, - "address": "127.0.0.1:11419", + "address": "127.0.0.1:11420", "outputCapture": [ ] }, diff --git a/.vscode/settings.json b/.vscode/settings.json index 97694867..ecf65735 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,9 @@ // Just some comment { - "Lua.diagnostics.globals": [ // Just some comment - // Just some comment + "Lua.diagnostics.globals": [ "ERR", "OUT", "IN", - // Just some comment "log", "ac", "_G", diff --git a/main-beta.lua b/main-beta.lua index 0f52e962..8e2bdb29 100644 --- a/main-beta.lua +++ b/main-beta.lua @@ -18,4 +18,6 @@ xpcall(dofile, log.debug, rootPath .. '/debugger.lua') local service = require 'service' +-- TODO +ALL_DEEP = true service.start() diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index ab8bd566..5e7a4072 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -8,7 +8,7 @@ local findSource = require 'core.find-source' local lang = require 'language' local function getHoverAsFunction(source) - local values = vm.getInfers(source) + local values = vm.getInfers(source, 'deep') local desc = getDesc(source) local labels = {} local defs = 0 diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index d5761e17..b098ad35 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -172,20 +172,23 @@ end return function (source) local literals = {} local classes = {} + local clock = os.clock() for _, src in ipairs(vm.getFields(source, 'deep')) do local key = getKey(src) if not key then goto CONTINUE end - local class, literal = getField(src) if not classes[key] then classes[key] = {} end if not literals[key] then literals[key] = {} end - classes[key][#classes[key]+1] = class - literals[key][#literals[key]+1] = literal + if os.clock() - clock <= 1 then + local class, literal = getField(src) + classes[key][#classes[key]+1] = class + literals[key][#literals[key]+1] = literal + end ::CONTINUE:: end diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 5d1aa566..0cd3c6ca 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -26,12 +26,16 @@ local function eachDef(source, deep) end function vm.getDefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachDefOfGlobal')[name] or vm.getCache('eachDef')[source] or eachDef(source, 'deep') vm.getCache('eachDefOfGlobal')[name] = cache + vm.getCache('eachDef')[source] = cache return cache else local cache = vm.getCache('eachDef')[source] diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua index 90892f03..798566b4 100644 --- a/script-beta/vm/eachField.lua +++ b/script-beta/vm/eachField.lua @@ -47,12 +47,16 @@ local function eachField(source, deep) end function vm.getFields(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachFieldOfGlobal')[name] or vm.getCache('eachField')[source] or eachField(source, 'deep') vm.getCache('eachFieldOfGlobal')[name] = cache + vm.getCache('eachField')[source] = cache return cache else local cache = vm.getCache('eachField')[source] diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua index ea46c9ee..cd003443 100644 --- a/script-beta/vm/eachRef.lua +++ b/script-beta/vm/eachRef.lua @@ -25,12 +25,16 @@ local function getRefs(source, deep) end function vm.getRefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachRefOfGlobal')[name] or vm.getCache('eachRef')[source] or getRefs(source, 'deep') vm.getCache('eachRefOfGlobal')[name] = cache + vm.getCache('eachRef')[source] = cache return cache else local cache = vm.getCache('eachRef')[source] diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua index c0f2d118..c7c422f4 100644 --- a/script-beta/vm/getInfer.lua +++ b/script-beta/vm/getInfer.lua @@ -1,6 +1,7 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local util = require 'utility' +local await = require 'await' NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end }) @@ -52,16 +53,47 @@ function vm.getInferLiteral(source, deep) return table.concat(literals, '|') end +local function getInfers(source, deep) + local results = {} + local lock = vm.lock('getInfers', source) + if not lock then + return results + end + + await.delay() + + local clock = os.clock() + local myResults, count = guide.requestInfer(source, vm.interface, deep) + if DEVELOP and os.clock() - clock > 0.1 then + log.warn('requestInfer', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })) + end + vm.mergeResults(results, myResults) + + lock() + + return results +end + --- 获取对象的值 --- 会尝试穿透函数调用 function vm.getInfers(source, deep) - if not source then - return + if ALL_DEEP then + deep = 'deep' end - local clock = os.clock() - local infers = guide.requestInfer(source, vm.interface, deep) - if os.clock() - clock > 0.1 then - log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))) + if guide.isGlobal(source) then + local name = guide.getKeyName(source) + local cache = vm.getCache('getInfersOfGlobal')[name] + or vm.getCache('getInfers')[source] + or getInfers(source, 'deep') + vm.getCache('getInfersOfGlobal')[name] = cache + vm.getCache('getInfers')[source] = cache + return cache + else + local cache = vm.getCache('getInfers')[source] + or getInfers(source, deep) + if deep then + vm.getCache('getInfers')[source] = cache + end + return cache end - return infers end |