summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/definition.lua11
-rw-r--r--script/core/infer.lua1
-rw-r--r--script/vm/eachDef.lua10
-rw-r--r--script/vm/getDef.lua29
-rw-r--r--script/vm/getRef.lua (renamed from script/vm/eachRef.lua)0
-rw-r--r--script/vm/init.lua4
6 files changed, 31 insertions, 24 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 6c6b3df3..11223187 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -1,4 +1,3 @@
-local searcher = require 'core.searcher'
local workspace = require 'workspace'
local files = require 'files'
local vm = require 'vm'
@@ -132,21 +131,11 @@ return function (uri, offset)
end
local defs = vm.getAllDefs(source)
- local values = {}
- for _, src in ipairs(defs) do
- local value = searcher.getObjectValue(src)
- if value and value ~= src and guide.isLiteral(value) then
- values[value] = true
- end
- end
for _, src in ipairs(defs) do
if src.dummy then
goto CONTINUE
end
- if values[src] then
- goto CONTINUE
- end
local root = guide.getRoot(src)
if not root then
goto CONTINUE
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 691424a2..ab5e2180 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -1,4 +1,3 @@
-local searcher = require 'core.searcher'
local config = require 'config'
local util = require 'utility'
local vm = require "vm.vm"
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