diff options
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/eachDef.lua | 10 | ||||
-rw-r--r-- | script/vm/getDef.lua | 29 | ||||
-rw-r--r-- | script/vm/getRef.lua (renamed from script/vm/eachRef.lua) | 0 | ||||
-rw-r--r-- | script/vm/init.lua | 4 |
4 files changed, 31 insertions, 12 deletions
diff --git a/script/vm/eachDef.lua b/script/vm/eachDef.lua deleted file mode 100644 index 3f7e1db9..00000000 --- a/script/vm/eachDef.lua +++ /dev/null @@ -1,10 +0,0 @@ ----@class vm -local vm = require 'vm.vm' - -function vm.getDefs(source, field) - return searcher.requestDefinition(source, field) -end - -function vm.getAllDefs(source, field) - return searcher.requestAllDefinition(source, field) -end diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua new file mode 100644 index 00000000..11a64421 --- /dev/null +++ b/script/vm/getDef.lua @@ -0,0 +1,29 @@ +local util = require 'utility' + +---@class vm +local vm = require 'vm.vm' + +local simpleMap = util.switch() + : case 'local' + : call(function (source, results) + results[#results+1] = source + end) + : case 'getlocal' + : case 'setlocal' + : call(function (source, results) + results[#results+1] = source.node + end) + : getMap() + +function vm.getDefs(source, field) + local results = {} + local simple = simpleMap[source.type] + if simple then + simple(source, results) + end + return results +end + +function vm.getAllDefs(source, field) + return vm.getDefs(source, field) +end diff --git a/script/vm/eachRef.lua b/script/vm/getRef.lua index ded95b61..ded95b61 100644 --- a/script/vm/eachRef.lua +++ b/script/vm/getRef.lua diff --git a/script/vm/init.lua b/script/vm/init.lua index c3ccabc1..3a42fb9c 100644 --- a/script/vm/init.lua +++ b/script/vm/init.lua @@ -3,7 +3,7 @@ require 'vm.compiler' require 'vm.getGlobals' require 'vm.getDocs' require 'vm.getLibrary' -require 'vm.eachDef' -require 'vm.eachRef' +require 'vm.getDef' +require 'vm.getRef' require 'vm.getLinks' return vm |