summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-03 20:00:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-03 20:00:18 +0800
commitbf5578f46a2c59ba8a2d031cdba3c9ecfc092e11 (patch)
treee1e2c1655b599e2e0c248ebd1aafb558c4d13624
parentbd9aacf509cf65584d56f6673f63b48974fbe018 (diff)
downloadlua-language-server-bf5578f46a2c59ba8a2d031cdba3c9ecfc092e11.zip
解决library结构变化带来的功能错误
-rw-r--r--script-beta/core/hover/arg.lua39
-rw-r--r--script-beta/core/hover/name.lua2
-rw-r--r--script-beta/core/hover/return.lua2
-rw-r--r--script-beta/library.lua2
-rw-r--r--script-beta/parser/guide.lua7
5 files changed, 48 insertions, 4 deletions
diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua
index 37c5e6ad..a2b7e1b9 100644
--- a/script-beta/core/hover/arg.lua
+++ b/script-beta/core/hover/arg.lua
@@ -1,6 +1,40 @@
local guide = require 'parser.guide'
local vm = require 'vm'
+local function mergeTypesInLibrary(types)
+ if type(types) == 'table' then
+ return table.concat(types, '|')
+ else
+ return types
+ end
+end
+
+local function asLibrary(source, oop)
+ if not source.args then
+ return ''
+ end
+ local args = {}
+ for i = 1, #source.args do
+ local arg = source.args[i]
+ local name = arg.name
+ if name then
+ args[i] = ('%s: %s'):format(name, mergeTypesInLibrary(arg.type))
+ else
+ args[i] = ('%s'):format(mergeTypesInLibrary(arg.type))
+ end
+ end
+ local methodDef
+ local parent = source.parent
+ if parent and parent.type == 'setmethod' then
+ methodDef = true
+ end
+ if not methodDef and oop then
+ return table.concat(args, ', ', 2)
+ else
+ return table.concat(args, ', ')
+ end
+end
+
local function asFunction(source, oop)
if not source.args then
return ''
@@ -28,6 +62,11 @@ local function asFunction(source, oop)
end
return function (source, oop)
+ if source.type == 'library' then
+ return asLibrary(source.value, oop)
+ elseif source.library then
+ return asLibrary(source, oop)
+ end
if source.type == 'function' then
return asFunction(source, oop)
end
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua
index 0bc68c5b..99350301 100644
--- a/script-beta/core/hover/name.lua
+++ b/script-beta/core/hover/name.lua
@@ -57,6 +57,8 @@ end
local function buildName(source, oop)
if source.type == 'library' then
+ return asLibrary(source.value, oop) or ''
+ elseif source.library then
return asLibrary(source, oop) or ''
end
if source.type == 'local'
diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua
index 031abc5c..d42dde6c 100644
--- a/script-beta/core/hover/return.lua
+++ b/script-beta/core/hover/return.lua
@@ -68,6 +68,8 @@ end
return function (source)
if source.type == 'library' then
+ return asLibrary(source.value)
+ elseif source.library then
return asLibrary(source)
end
if source.type == 'function' then
diff --git a/script-beta/library.lua b/script-beta/library.lua
index 6776a796..961b6b4c 100644
--- a/script-beta/library.lua
+++ b/script-beta/library.lua
@@ -98,6 +98,7 @@ local function insertGlobal(tbl, key, value)
child = {},
value = value,
}
+ value.library = tbl[key]
return true
end
@@ -199,6 +200,7 @@ local function insertChild(tbl, name, key, value)
name = key,
value = value,
}
+ value.library = tbl[name].child[key]
end
local function mergeParent(alllibs, name, lib, libName)
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 1f371ad3..162b93bc 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1080,8 +1080,7 @@ function m.getObjectValue(obj)
while obj.type == 'paren' do
obj = obj.exp
end
- if obj.type == 'library'
- or obj.type == 'boolean'
+ if obj.type == 'boolean'
or obj.type == 'number'
or obj.type == 'integer'
or obj.type == 'string' then
@@ -2736,8 +2735,8 @@ function m.searchInfer(status, obj)
status.cache.clock = status.cache.clock or osClock()
end
- local checked = m.inferCheckLiteral(status, obj)
- or m.inferCheckLibrary(status, obj)
+ local checked = m.inferCheckLibrary(status, obj)
+ or m.inferCheckLiteral(status, obj)
or m.inferCheckUnary(status, obj)
or m.inferCheckBinary(status, obj)
if checked then