summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-21 20:52:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-21 20:52:05 +0800
commitca322946af06afa7bfd93fa176812ceed854730e (patch)
treee32e54acea059359a27ecf35c9ab305d8a5e0f51 /script-beta
parent0bb3565ed9e8f3fb0d9501f7ac2b3c7aa0245a86 (diff)
downloadlua-language-server-ca322946af06afa7bfd93fa176812ceed854730e.zip
优化性能
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/await.lua3
-rw-r--r--script-beta/core/hover/table.lua12
-rw-r--r--script-beta/parser/guide.lua21
-rw-r--r--script-beta/provider/provider.lua5
-rw-r--r--script-beta/vm/eachDef.lua10
-rw-r--r--script-beta/vm/eachRef.lua10
-rw-r--r--script-beta/vm/getClass.lua44
-rw-r--r--script-beta/vm/getInfer.lua12
-rw-r--r--script-beta/vm/getLibrary.lua9
9 files changed, 77 insertions, 49 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua
index 9da40027..4b63b8ef 100644
--- a/script-beta/await.lua
+++ b/script-beta/await.lua
@@ -87,10 +87,13 @@ function m.close(id)
if not map then
return
end
+ local count = 0
for co in pairs(map) do
map[co] = nil
coroutine.close(co)
+ count = count + 1
end
+ log.debug('Close await:', count)
end
--- 休眠一段时间
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index 0d243aff..17316367 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -42,14 +42,13 @@ local function getField(src)
src = src.parent
end
end
- local tp = vm.getInferType(src)
- local class = vm.getClass(src)
- local literal = vm.getInferLiteral(src)
- local key = getKey(src)
+ local tp = vm.getInferType(src, 'simple')
+ local class = vm.getClass(src, 'simple')
+ local literal = vm.getInferLiteral(src, 'simple')
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
end
- return key, class or tp, literal
+ return class or tp, literal
end
local function buildAsHash(classes, literals)
@@ -150,10 +149,11 @@ return function (source)
local literals = {}
local classes = {}
vm.eachField(source, function (src)
- local key, class, literal = getField(src)
+ local key = getKey(src)
if not key then
return
end
+ local class, literal = getField(src)
if not classes[key] then
classes[key] = {}
end
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index d1267b39..b9de7363 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -994,6 +994,7 @@ function m.status(parentStatus, interface)
interface = parentStatus and parentStatus.interface or {},
locks = parentStatus and parentStatus.locks or {},
index = parentStatus and (parentStatus.index + 1) or 1,
+ simple = parentStatus and parentStatus.simple,
results = {},
}
status.lock = status.locks[status.index] or {}
@@ -1692,7 +1693,7 @@ function m.checkSameSimple(status, simple, data, mode, results, queue)
m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue)
-- 检查自己是特殊分支的情况
m.checkSameSimpleInSpecialBranch(status, ref, i, queue)
- if cmode == 'ref' then
+ if cmode == 'ref' and not status.simple then
-- 检查形如 { a = f } 的情况
m.checkSameSimpleAsTableField(status, ref, i, queue)
-- 检查形如 return m 的情况
@@ -2881,7 +2882,10 @@ function m.searchInfer(status, obj)
obj = obj.parent
end
- local cache, makeCache = m.getRefCache(status, obj, 'infer')
+ local cache, makeCache
+ if not status.simple then
+ cache, makeCache = m.getRefCache(status, obj, 'infer')
+ end
if cache then
for i = 1, #cache do
status.results[#status.results+1] = cache[i]
@@ -2905,7 +2909,9 @@ function m.searchInfer(status, obj)
return
end
- m.inferByDef(status, obj)
+ if not status.simple then
+ m.inferByDef(status, obj)
+ end
m.inferBySet(status, obj)
m.inferByCall(status, obj)
m.inferByGetTable(status, obj)
@@ -2923,8 +2929,9 @@ end
--- 与 `return function` 形式。
--- 不穿透 `setmetatable` ,考虑由
--- 业务层进行反向 def 搜索。
-function m.requestReference(obj, interface)
+function m.requestReference(obj, interface, simple)
local status = m.status(nil, interface)
+ status.simple = simple
-- 根据 field 搜索引用
m.searchRefs(status, obj, 'ref')
@@ -2940,8 +2947,9 @@ end
--- 请求对象的定义,包括 `a.b.c` 形式
--- 与 `return function` 形式。
--- 穿透 `setmetatable` 。
-function m.requestDefinition(obj, interface)
+function m.requestDefinition(obj, interface, simple)
local status = m.status(nil, interface)
+ status.simple = simple
-- 根据 field 搜索定义
m.searchRefs(status, obj, 'def')
@@ -2954,8 +2962,9 @@ function m.requestFields(obj, interface)
end
--- 请求对象的类型推测
-function m.requestInfer(obj, interface)
+function m.requestInfer(obj, interface, simple)
local status = m.status(nil, interface)
+ status.simple = simple
m.searchInfer(status, obj)
return status.results, status.cache.count
diff --git a/script-beta/provider/provider.lua b/script-beta/provider/provider.lua
index 07ecae1f..4673ecf9 100644
--- a/script-beta/provider/provider.lua
+++ b/script-beta/provider/provider.lua
@@ -383,7 +383,10 @@ proto.on('textDocument/completion', function (params)
end
items[i] = item
end
- return items
+ return {
+ isIncomplete = false,
+ items = items,
+ }
end)
proto.on('completionItem/resolve', function (item)
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 320f3e97..ec3930ed 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -6,8 +6,8 @@ local await = require 'await'
local m = {}
-function m.eachDef(source, results)
- results = results or {}
+function m.eachDef(source, simple)
+ local results = {}
local lock = vm.lock('eachDef', source)
if not lock then
return results
@@ -16,7 +16,7 @@ function m.eachDef(source, results)
await.delay()
local clock = os.clock()
- local myResults, count = guide.requestDefinition(source, vm.interface)
+ local myResults, count = guide.requestDefinition(source, vm.interface, simple)
if DEVELOP and os.clock() - clock > 0.1 then
log.warn('requestDefinition', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
end
@@ -27,7 +27,7 @@ function m.eachDef(source, results)
return results
end
-function vm.getDefs(source)
+function vm.getDefs(source, simple)
if guide.isGlobal(source) then
local name = guide.getKeyName(source)
local cache = vm.getCache('eachDefOfGlobal')[name]
@@ -35,6 +35,8 @@ function vm.getDefs(source)
or m.eachDef(source)
vm.getCache('eachDefOfGlobal')[name] = cache
return cache
+ elseif simple then
+ return m.eachDef(source, simple)
else
local cache = vm.getCache('eachDef')[source]
or m.eachDef(source)
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index cfdc1d19..babfa4d8 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -3,8 +3,8 @@ local guide = require 'parser.guide'
local util = require 'utility'
local await = require 'await'
-local function getRefs(source, results)
- results = results or {}
+local function getRefs(source, simple)
+ local results = {}
local lock = vm.lock('eachDef', source)
if not lock then
return results
@@ -13,7 +13,7 @@ local function getRefs(source, results)
await.delay()
local clock = os.clock()
- local myResults, count = guide.requestReference(source, vm.interface)
+ local myResults, count = guide.requestReference(source, vm.interface, simple)
if DEVELOP and os.clock() - clock > 0.1 then
log.warn('requestReference', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
end
@@ -24,7 +24,7 @@ local function getRefs(source, results)
return results
end
-function vm.getRefs(source)
+function vm.getRefs(source, simple)
if guide.isGlobal(source) then
local name = guide.getKeyName(source)
local cache = vm.getCache('eachRefOfGlobal')[name]
@@ -32,6 +32,8 @@ function vm.getRefs(source)
or getRefs(source)
vm.getCache('eachRefOfGlobal')[name] = cache
return cache
+ elseif simple then
+ return getRefs(source, simple)
else
local cache = vm.getCache('eachRef')[source]
or getRefs(source)
diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua
index 03cde93a..522ca026 100644
--- a/script-beta/vm/getClass.lua
+++ b/script-beta/vm/getClass.lua
@@ -1,8 +1,8 @@
local vm = require 'vm.vm'
local guide = require 'parser.guide'
-local function getClass(source, classes, deep)
- local lib = vm.getLibrary(source)
+local function getClass(source, classes, deep, simple)
+ local lib = vm.getLibrary(source, simple)
if lib then
if lib.value.type == 'table' then
classes[#classes+1] = lib.value.name
@@ -15,33 +15,39 @@ local function getClass(source, classes, deep)
return
end
local value = guide.getObjectValue(source) or source
- vm.eachField(value, function (src)
- local key = vm.getKeyName(src)
- if not key then
- return
+ if simple and value == source then
+ if value and value.type == 'string' then
+ classes[#classes+1] = value[1]
end
- local lkey = key:lower()
- if lkey == 's|type'
- or lkey == 's|__name'
- or lkey == 's|name'
- or lkey == 's|class' then
- local value = guide.getObjectValue(src)
- if value and value.type == 'string' then
- classes[#classes+1] = value[1]
+ else
+ vm.eachField(value, function (src)
+ local key = vm.getKeyName(src)
+ if not key then
+ return
end
- end
- end)
+ local lkey = key:lower()
+ if lkey == 's|type'
+ or lkey == 's|__name'
+ or lkey == 's|name'
+ or lkey == 's|class' then
+ local value = guide.getObjectValue(src)
+ if value and value.type == 'string' then
+ classes[#classes+1] = value[1]
+ end
+ end
+ end)
+ end
if #classes ~= 0 then
return
end
vm.eachMeta(source, function (mt)
- getClass(mt, classes, deep + 1)
+ getClass(mt, classes, deep + 1, simple)
end)
end
-function vm.getClass(source)
+function vm.getClass(source, simple)
local classes = {}
- getClass(source, classes, 1)
+ getClass(source, classes, 1, simple)
if #classes == 0 then
return nil
end
diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua
index 9e48e432..18f7f0ef 100644
--- a/script-beta/vm/getInfer.lua
+++ b/script-beta/vm/getInfer.lua
@@ -29,13 +29,13 @@ function vm.hasInferType(source, type)
return false
end
-function vm.getInferType(source)
- local infers = vm.getInfers(source)
+function vm.getInferType(source, simple)
+ local infers = vm.getInfers(source, simple)
return guide.viewInferType(infers)
end
-function vm.getInferLiteral(source)
- local infers = vm.getInfers(source)
+function vm.getInferLiteral(source, simple)
+ local infers = vm.getInfers(source, simple)
local literals = {}
local mark = {}
for _, infer in ipairs(infers) do
@@ -54,12 +54,12 @@ end
--- 获取对象的值
--- 会尝试穿透函数调用
-function vm.getInfers(source)
+function vm.getInfers(source, simple)
if not source then
return
end
local clock = os.clock()
- local infers = guide.requestInfer(source, vm.interface)
+ local infers = guide.requestInfer(source, vm.interface, simple)
if os.clock() - clock > 0.1 then
log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })))
end
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index f02c78a2..68fb22a9 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -1,14 +1,14 @@
local vm = require 'vm.vm'
local guide = require 'parser.guide'
-local function getLibrary(source)
+local function getLibrary(source, simple)
if source.type == 'library' then
return source
end
if source.library then
return source.library
end
- local defs = vm.getDefs(source)
+ local defs = vm.getDefs(source, simple)
for _, def in ipairs(defs) do
if def.type == 'library' then
return def
@@ -17,7 +17,10 @@ local function getLibrary(source)
return nil
end
-function vm.getLibrary(source)
+function vm.getLibrary(source, simple)
+ if simple then
+ return getLibrary(source, simple) or false
+ end
local cache = vm.getCache('getLibrary')[source]
if cache ~= nil then
return cache