summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-10 16:10:56 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-10 16:10:56 +0800
commite81e3400f29bf310e05afb9305a2cfa1c3271873 (patch)
tree263fd3cc9c000e04045b293db2256ab7213a57c1
parentf335c413a409c1f03e379d7d5e1d5b377d378a0f (diff)
downloadlua-language-server-e81e3400f29bf310e05afb9305a2cfa1c3271873.zip
update
-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
-rw-r--r--test.lua2
7 files changed, 32 insertions, 25 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
diff --git a/test.lua b/test.lua
index 42b0d129..8a343f70 100644
--- a/test.lua
+++ b/test.lua
@@ -51,8 +51,8 @@ end
local function testAll()
test 'basic'
- test 'references'
test 'definition'
+ test 'references'
test 'type_inference'
test 'hover'
test 'completion'