summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-29 17:41:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-29 17:41:07 +0800
commitb5d452f3cc7315940e860a21c9bb15673e544d9c (patch)
treee41be9b3e923eef40adb4a62b77e03b4797099b0 /script-beta/core
parentcbf18dc54d2d2315ae3bace888fc428550149c7a (diff)
downloadlua-language-server-b5d452f3cc7315940e860a21c9bb15673e544d9c.zip
支持 lib 函数的 arg 与 return
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/hover/arg.lua22
-rw-r--r--script-beta/core/hover/init.lua4
-rw-r--r--script-beta/core/hover/label.lua10
-rw-r--r--script-beta/core/hover/name.lua44
4 files changed, 60 insertions, 20 deletions
diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua
index 70285e6b..268ceecf 100644
--- a/script-beta/core/hover/arg.lua
+++ b/script-beta/core/hover/arg.lua
@@ -1,7 +1,7 @@
local guide = require 'parser.guide'
local vm = require 'vm'
-local function asFunction(source)
+local function asFunction(source, caller)
if not source.args then
return ''
end
@@ -15,11 +15,25 @@ local function asFunction(source)
args[i] = ('%s'):format(vm.getType(arg))
end
end
- return table.concat(args, ', ')
+ local methodDef, methodCall
+ local parent = source.parent
+ if parent and parent.type == 'setmethod' then
+ methodDef = true
+ end
+ if caller.type == 'method'
+ or caller.type == 'getmethod'
+ or caller.type == 'setmethod' then
+ methodCall = true
+ end
+ if not methodDef and methodCall then
+ return table.concat(args, ', ', 2)
+ else
+ return table.concat(args, ', ')
+ end
end
-return function (source)
+return function (source, caller)
if source.type == 'function' then
- return asFunction(source)
+ return asFunction(source, caller)
end
end
diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua
index b99c14b2..ae4df936 100644
--- a/script-beta/core/hover/init.lua
+++ b/script-beta/core/hover/init.lua
@@ -8,7 +8,7 @@ local function getHoverAsFunction(source)
local labels = {}
for _, value in ipairs(values) do
if value.type == 'function' then
- labels[#labels+1] = getLabel(value.source)
+ labels[#labels+1] = getLabel(value.source, source)
end
end
@@ -20,7 +20,7 @@ local function getHoverAsFunction(source)
end
local function getHoverAsValue(source)
- local label = getLabel(source)
+ local label = getLabel(source, source)
return {
label = label,
source = source,
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index f5d49bb0..e9b987e1 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -6,9 +6,9 @@ local getClass = require 'core.hover.class'
local vm = require 'vm'
local util = require 'utility'
-local function asFunction(source)
- local name = buildName(source)
- local arg = buildArg(source)
+local function asFunction(source, caller)
+ local name = buildName(source, caller)
+ local arg = buildArg(source, caller)
local rtn = buildReturn(source)
local lines = {}
lines[1] = ('function %s(%s)'):format(name, arg)
@@ -89,9 +89,9 @@ local function asLibrary(source)
end
end
-return function (source)
+return function (source, caller)
if source.type == 'function' then
- return asFunction(source)
+ return asFunction(source, caller)
elseif source.type == 'local'
or source.type == 'getlocal'
or source.type == 'setlocal' then
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua
index 3d855ee5..7b8cf449 100644
--- a/script-beta/core/hover/name.lua
+++ b/script-beta/core/hover/name.lua
@@ -5,14 +5,14 @@ local function asLocal(source)
return guide.getName(source)
end
-local function asMethod(source)
+local function asMethod(source, caller)
local class = getClass(source.node)
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s:%s'):format(node, method)
end
-local function asField(source)
+local function asField(source, caller)
local class = getClass(source.node)
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
@@ -27,13 +27,39 @@ local function asGlobal(source)
return guide.getName(source)
end
-local function asLibrary(source)
- return source.doc or source.name
+local function asLibrary(source, caller)
+ local p
+ if caller.type == 'method'
+ or caller.type == 'getmethod'
+ or caller.type == 'setmethod' then
+ if source.parent then
+ for _, parent in ipairs(source.parent) do
+ if parent.type == 'object' then
+ p = parent.name .. ':'
+ break
+ end
+ end
+ end
+ else
+ if source.parent then
+ for _, parent in ipairs(source.parent) do
+ if parent.type == 'global' then
+ p = parent.name .. '.'
+ break
+ end
+ end
+ end
+ end
+ if p then
+ return ('%s%s'):format(p, source.name)
+ else
+ return source.name
+ end
end
-local function buildName(source)
+local function buildName(source, caller)
if source.library then
- return asLibrary(source) or ''
+ return asLibrary(source, caller) or ''
end
if source.type == 'local'
or source.type == 'getlocal'
@@ -46,18 +72,18 @@ local function buildName(source)
end
if source.type == 'setmethod'
or source.type == 'getmethod' then
- return asMethod(source) or ''
+ return asMethod(source, caller) or ''
end
if source.type == 'setfield'
or source.type == 'getfield' then
- return asField(source) or ''
+ return asField(source, caller) or ''
end
if source.type == 'tablefield' then
return asTableField(source) or ''
end
local parent = source.parent
if parent then
- return buildName(parent)
+ return buildName(parent, caller)
end
return ''
end