summaryrefslogtreecommitdiff
path: root/script-beta/vm/vm.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
commit6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch)
treefdc22d78150fd1c5edc46732c8b151ccfefb519f /script-beta/vm/vm.lua
parentd0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff)
downloadlua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip
正路目录
Diffstat (limited to 'script-beta/vm/vm.lua')
-rw-r--r--script-beta/vm/vm.lua81
1 files changed, 81 insertions, 0 deletions
diff --git a/script-beta/vm/vm.lua b/script-beta/vm/vm.lua
new file mode 100644
index 00000000..23a691df
--- /dev/null
+++ b/script-beta/vm/vm.lua
@@ -0,0 +1,81 @@
+local guide = require 'parser.guide'
+local util = require 'utility'
+
+local setmetatable = setmetatable
+local assert = assert
+local require = require
+local type = type
+
+_ENV = nil
+
+local specials = {
+ ['_G'] = true,
+ ['rawset'] = true,
+ ['rawget'] = true,
+ ['setmetatable'] = true,
+ ['require'] = true,
+ ['dofile'] = true,
+ ['loadfile'] = true,
+}
+
+---@class vm
+local m = {}
+
+function m.lock(tp, source)
+ if m.locked[tp][source] then
+ return nil
+ end
+ m.locked[tp][source] = true
+ return function ()
+ m.locked[tp][source] = nil
+ end
+end
+
+--- 获取link的uri
+function m.getLinkUris(call)
+ local workspace = require 'workspace'
+ local func = call.node
+ local name = func.special
+ if name == 'require' then
+ local args = call.args
+ if not args[1] then
+ return nil
+ end
+ local literal = guide.getLiteral(args[1])
+ if type(literal) ~= 'string' then
+ return nil
+ end
+ return workspace.findUrisByRequirePath(literal, true)
+ end
+end
+
+m.cacheTracker = setmetatable({}, { __mode = 'kv' })
+
+--- 刷新缓存
+function m.refreshCache()
+ if m.cache then
+ m.cache.dead = true
+ end
+ m.cache = {
+ eachRef = {},
+ eachField = {},
+ getGlobals = {},
+ getLinks = {},
+ getGlobal = {},
+ specialName = {},
+ getLibrary = {},
+ getValue = {},
+ specials = nil,
+ }
+ m.locked = {
+ eachRef = {},
+ eachField = {},
+ getGlobals = {},
+ getLinks = {},
+ getLibrary = {},
+ getValue = {},
+ }
+ m.cacheTracker[m.cache] = true
+end
+
+return m