summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-28 16:59:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-28 16:59:58 +0800
commit697aa9822b989d670c38bab8b4a0c25352a1b316 (patch)
tree26ee36e3575a4bd4eaf84e4a17fe8d4cdfd8f3b0 /script-beta
parenteec3341dcba8b4076a038827aad3869a1439058b (diff)
downloadlua-language-server-697aa9822b989d670c38bab8b4a0c25352a1b316.zip
允许在索引过程中访问库
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/definition.lua2
-rw-r--r--script-beta/core/hover/description.lua2
-rw-r--r--script-beta/parser/guide.lua124
-rw-r--r--script-beta/vm/eachDef.lua13
-rw-r--r--script-beta/vm/eachField.lua4
-rw-r--r--script-beta/vm/getClass.lua5
-rw-r--r--script-beta/vm/getGlobals.lua14
-rw-r--r--script-beta/vm/getLibrary.lua18
-rw-r--r--script-beta/vm/guideInterface.lua15
9 files changed, 36 insertions, 161 deletions
diff --git a/script-beta/core/definition.lua b/script-beta/core/definition.lua
index 62643861..bb770b4e 100644
--- a/script-beta/core/definition.lua
+++ b/script-beta/core/definition.lua
@@ -59,7 +59,7 @@ local function checkRequire(source, offset)
local call = callargs.parent
local func = call.node
local literal = guide.getLiteral(source)
- local lib = vm.getLibrary(func)
+ local lib = func.special
if not lib then
return nil
end
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua
index 261f8569..768e5f50 100644
--- a/script-beta/core/hover/description.lua
+++ b/script-beta/core/hover/description.lua
@@ -14,7 +14,7 @@ local function asString(source)
local result
local call = parent.parent
local node = call.node
- local lib = vm.getLibrary(node)
+ local lib = node.special
if not lib then
return
end
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 9bdfd716..be082527 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1391,7 +1391,7 @@ end
function m.checkSameSimpleAsTableField(status, ref, start, queue)
local parent = ref.parent
- if parent.type ~= 'tablefield' then
+ if not parent or parent.type ~= 'tablefield' then
return
end
if m.checkValueMark(status, parent, ref) then
@@ -1420,7 +1420,7 @@ function m.checkSearchLevel(status)
end
function m.checkSameSimpleAsReturn(status, ref, start, queue)
- if ref.parent.type ~= 'return' then
+ if not ref.parent or ref.parent.type ~= 'return' then
return
end
if ref.parent.parent.type ~= 'main' then
@@ -1447,6 +1447,9 @@ function m.checkSameSimpleAsSetValue(status, ref, start, queue)
return
end
local parent = ref.parent
+ if not parent then
+ return
+ end
if m.getObjectValue(parent) ~= ref then
return
end
@@ -1501,8 +1504,10 @@ function m.pushResult(status, mode, ref, simple)
end
elseif ref.type == 'table' then
results[#results+1] = ref
+ elseif ref.library then
+ results[#results+1] = ref
end
- if ref.parent.type == 'return' then
+ if ref.parent and ref.parent.type == 'return' then
if m.getParentFunction(ref) ~= m.getParentFunction(simple.first) then
results[#results+1] = ref
end
@@ -1534,6 +1539,8 @@ function m.pushResult(status, mode, ref, simple)
or ref.node.special == 'rawget' then
results[#results+1] = ref
end
+ elseif ref.library then
+ results[#results+1] = ref
end
if ref.parent.type == 'return' then
results[#results+1] = ref
@@ -1563,6 +1570,8 @@ function m.pushResult(status, mode, ref, simple)
or ref.node.special == 'rawget' then
results[#results+1] = ref
end
+ elseif ref.library then
+ results[#results+1] = ref
end
end
end
@@ -2420,111 +2429,6 @@ function m.inferCheckBinary(status, source)
end
end
-function m.inferCheckLibraryTypes(status, source)
- if type(source.type) ~= 'table' then
- return false
- end
- for i = 1, #source.type do
- status.results[#status.results+1] = {
- type = source.type[i],
- source = source,
- }
- end
- return true
-end
-
-function m.inferCheckLibrary(status, source)
- local lib = status.interface.library and status.interface.library(source)
- if not lib then
- return false
- end
- status.results = m.allocInfer {
- type = lib.type,
- value = lib.value,
- source = lib,
- }
- return true
-end
-
-function m.inferCheckLibraryReturn(status, source)
- if source.type ~= 'select' then
- return nil
- end
- local index = source.index
- local call = source.vararg
- if call.type ~= 'call' then
- return nil
- end
- local func = call.node
- local lib = status.interface.library and status.interface.library(func)
- if not lib then
- return nil
- end
- if lib.type ~= 'function' then
- return nil
- end
- if not lib.returns then
- return nil
- end
- local rtn = lib.returns[index]
- if not rtn then
- return nil
- end
- if not rtn.type then
- return nil
- end
- if rtn.type == '...' or rtn.type == 'any' then
- return
- end
- status.results = m.allocInfer {
- type = rtn.type,
- value = rtn.value,
- source = rtn,
- }
- return true
-end
-
-function m.inferByLibraryArg(status, source)
- local args = source.parent
- if not args then
- return
- end
- if args.type ~= 'callargs' then
- return
- end
- local call = args.parent
- if not call then
- return
- end
- local func = call.node
- local index
- for i = 1, #args do
- if args[i] == source then
- index = i
- break
- end
- end
- if not index then
- return
- end
- local lib = status.interface.library and status.interface.library(func)
- local arg = lib and lib.args and lib.args[index]
- if not arg then
- return
- end
- if not arg.type then
- return
- end
- if arg.type == '...' or arg.type == 'any' then
- return
- end
- status.results[#status.results+1] = {
- type = arg.type,
- value = arg.value,
- source = arg,
- }
-end
-
function m.inferByDef(status, obj)
if status.index > 1 then
return
@@ -2789,9 +2693,6 @@ function m.searchInfer(status, obj)
local checked = m.inferCheckLiteral(status, obj)
or m.inferCheckUnary(status, obj)
or m.inferCheckBinary(status, obj)
- or m.inferCheckLibraryTypes(status, obj)
- or m.inferCheckLibrary(status, obj)
- or m.inferCheckLibraryReturn(status, obj)
if checked then
m.cleanInfers(status.results)
if makeCache then
@@ -2800,7 +2701,6 @@ function m.searchInfer(status, obj)
return
end
- m.inferByLibraryArg(status, obj)
m.inferByDef(status, obj)
m.inferBySet(status, obj)
m.inferByCall(status, obj)
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 030fccea..e251cda5 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -6,17 +6,6 @@ local await = require 'await'
local m = {}
-function m.searchLibrary(source, results)
- if not source then
- return
- end
- local lib = vm.getLibrary(source)
- if not lib then
- return
- end
- vm.mergeResults(results, { lib })
-end
-
function m.eachDef(source, results)
results = results or {}
local lock = vm.lock('eachDef', source)
@@ -32,8 +21,6 @@ function m.eachDef(source, results)
log.warn('requestDefinition', count, os.clock() - clock, guide.getRoot(source).uri, util.dump(source, { deep = 1 }))
end
vm.mergeResults(results, myResults)
- m.searchLibrary(source, results)
- m.searchLibrary(guide.getObjectValue(source), results)
lock()
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index ffc16228..74f9b591 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -25,10 +25,6 @@ local function eachField(source)
await.delay()
local results = guide.requestFields(source, vm.interface)
- local lib = vm.getLibrary(source)
- if lib then
- eachFieldInLibrary(source, lib, results)
- end
if source.special == '_G' then
eachFieldOfLibrary(results)
end
diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua
index a3394e41..b573c6be 100644
--- a/script-beta/vm/getClass.lua
+++ b/script-beta/vm/getClass.lua
@@ -5,11 +5,6 @@ local function getClass(source, classes, deep)
if deep > 3 then
return
end
- local lib = vm.getLibrary(source)
- if lib and lib.type == 'table' then
- classes[#classes+1] = lib.name
- return
- end
local value = guide.getObjectValue(source) or source
vm.eachField(value, function (src)
local key = vm.getKeyName(src)
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua
index 53fff173..69e6dbb7 100644
--- a/script-beta/vm/getGlobals.lua
+++ b/script-beta/vm/getGlobals.lua
@@ -1,6 +1,7 @@
-local guide = require 'parser.guide'
-local vm = require 'vm.vm'
-local files = require 'files'
+local guide = require 'parser.guide'
+local vm = require 'vm.vm'
+local files = require 'files'
+local library = require 'library'
local function getGlobalsOfFile(uri)
local globals = {}
@@ -22,6 +23,12 @@ local function getGlobalsOfFile(uri)
return globals
end
+local function insertLibrary(results, name)
+ if name:sub(1, 2) == 's|' then
+ results[#results+1] = library.global[name:sub(3)]
+ end
+end
+
local function getGlobals(name)
local results = {}
for uri in files:eachFile() do
@@ -33,6 +40,7 @@ local function getGlobals(name)
end
end
end
+ insertLibrary(results, name)
return results
end
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index f9f94bca..a7f0e03a 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -1,20 +1,14 @@
local vm = require 'vm.vm'
-local library = require 'library'
local guide = require 'parser.guide'
-local interface = {
- global = function (name)
- if name:sub(1, 2) == 's|' then
- return library.global[name:sub(3)]
- end
- end,
-}
-
local function getLibrary(source)
- local results = guide.requestDefinition(source, interface)
- for _, def in ipairs(results) do
-
+ local defs = vm.getDefs(source)
+ for _, def in ipairs(defs) do
+ if def.library then
+ return def
+ end
end
+ return nil
end
function vm.getLibrary(source)
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
index d7bb89e0..3ddb86ea 100644
--- a/script-beta/vm/guideInterface.lua
+++ b/script-beta/vm/guideInterface.lua
@@ -1,8 +1,8 @@
-local vm = require 'vm.vm'
-local files = require 'files'
-local ws = require 'workspace'
-local guide = require 'parser.guide'
-local await = require 'await'
+local vm = require 'vm.vm'
+local files = require 'files'
+local ws = require 'workspace'
+local guide = require 'parser.guide'
+local await = require 'await'
local m = {}
@@ -103,11 +103,6 @@ function vm.interface.cache(source, mode)
end
end
-function vm.interface.library(source)
- await.delay()
- return vm.getLibrary(source)
-end
-
function vm.setSearchLevel(n)
-- 只有在搜索等级由低变高时,才需要清空缓存
if n > vm.interface.searchLevel then