summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-05 14:28:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-05 14:28:09 +0800
commite5131f6964d22e26cfcc6075e547666452df699c (patch)
treea5f14c0fa5384a3495d73657a322991a44508d37
parent750dc445ea6f0d9010b73f9a8b884e6ca55dfb26 (diff)
downloadlua-language-server-e5131f6964d22e26cfcc6075e547666452df699c.zip
局部函数的hover
-rw-r--r--server/src/core/hover.lua31
-rw-r--r--server/src/core/hover_function.lua12
-rw-r--r--server/src/core/hover_name.lua44
-rw-r--r--server/src/vm/function.lua14
-rw-r--r--server/test/example/vm.lua1
-rw-r--r--server/test/hover/init.lua7
6 files changed, 54 insertions, 55 deletions
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index 120d65f5..06e95379 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -352,10 +352,25 @@ local function getStringHover(result, lsp)
}
end
-local function hoverAsValue(result, source, lsp, select)
- if result:getType() == 'string' then
- return getStringHover(result, lsp)
+local function hoverAsValue(source, lsp, select)
+ local lib, fullkey, isObject = findLib(source)
+ local value = source:bindValue()
+ local name = fullkey or buildValueName(source)
+
+ local hover
+ if value:getType() == 'function' then
+ if lib then
+ else
+ hover = getFunctionHover(name, value:getFunction(), source:getFlag 'object', select)
+ end
+ else
end
+
+ if not hover then
+ return nil
+ end
+ hover.name = name
+ return hover
end
local function hoverAsVar(result, source, lsp, select)
@@ -399,13 +414,11 @@ local function hoverAsVar(result, source, lsp, select)
return hover
end
-return function (result, source, lsp, select)
- if not result then
+return function (source, lsp, select)
+ if not source then
return nil
end
- if result.type == 'value' then
- return hoverAsValue(result, source, lsp, select)
- else
- return hoverAsVar(result, source, lsp, select)
+ if source:bindValue() then
+ return hoverAsValue(source, lsp, select)
end
end
diff --git a/server/src/core/hover_function.lua b/server/src/core/hover_function.lua
index 68818028..d877a0d8 100644
--- a/server/src/core/hover_function.lua
+++ b/server/src/core/hover_function.lua
@@ -1,9 +1,9 @@
-local function buildValueArgs(func, oo, select)
+local function buildValueArgs(func, object, select)
local names = {}
local values = {}
if func.args then
for i, arg in ipairs(func.args) do
- names[i] = arg.key
+ names[i] = arg:getName()
end
end
if func.argValues then
@@ -13,7 +13,7 @@ local function buildValueArgs(func, oo, select)
end
local strs = {}
local start = 1
- if oo then
+ if object then
start = 2
if select then
select = select + 1
@@ -43,7 +43,7 @@ local function buildValueArgs(func, oo, select)
strs[#strs+1] = '@ARG'
end
end
- if func.hasDots then
+ if func:hasDots() then
if max > 0 then
strs[#strs+1] = ', '
end
@@ -84,8 +84,8 @@ local function buildValueReturns(func)
return '\n -> ' .. table.concat(strs, ', ')
end
-return function (name, func, oo, select)
- local args, argLabel = buildValueArgs(func, oo, select)
+return function (name, func, object, select)
+ local args, argLabel = buildValueArgs(func, object, select)
local returns = buildValueReturns(func)
local headLen = #('function %s('):format(name)
local title = ('function %s(%s)%s'):format(name, args, returns)
diff --git a/server/src/core/hover_name.lua b/server/src/core/hover_name.lua
index 5e358820..119a9349 100644
--- a/server/src/core/hover_name.lua
+++ b/server/src/core/hover_name.lua
@@ -1,14 +1,16 @@
-return function (result, source)
- local func = result.value
+return function (source)
+ local value = source:bindValue()
+ local func = value:getFunction()
local declarat
- if func:getType() == 'function' then
- declarat = func:getDeclarat() or source
+ if func then
+ declarat = func.source.name
else
declarat = source
end
if not declarat then
- return result.key or ''
+ return source:getName() or ''
end
+
local key
if declarat.type == 'name' then
key = declarat[1]
@@ -16,38 +18,8 @@ return function (result, source)
key = ('%q'):format(declarat[1])
elseif declarat.type == 'number' or declarat.type == 'boolean' then
key = tostring(declarat[1])
- elseif func:getType() == 'function' then
- key = ''
- elseif type(result.key) == 'string' then
- key = result.key
else
key = ''
end
-
- local parentName = declarat.parentName
-
- if not parentName then
- return key or ''
- end
-
- if parentName == '?' then
- local parentType = result.parentValue and result.parentValue.type
- if parentType == 'table' then
- else
- parentName = '*' .. parentType
- end
- end
- if source.object then
- return parentName .. ':' .. key
- else
- if parentName then
- if declarat.index then
- return parentName .. '[' .. key .. ']'
- else
- return parentName .. '.' .. key
- end
- else
- return key
- end
- end
+ return key
end
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index f3d4720c..8eebb59c 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -212,6 +212,20 @@ function mt:createArgs()
end
end
+function mt:setFlag(name, v)
+ if not self._flag then
+ self._flag = {}
+ end
+ self._flag[name] = v
+end
+
+function mt:getFlag(name)
+ if not self._flag then
+ return nil
+ end
+ return self._flag[name]
+end
+
return function (source)
local self = setmetatable({
source = source,
diff --git a/server/test/example/vm.lua b/server/test/example/vm.lua
index 965a0bec..d293fc38 100644
--- a/server/test/example/vm.lua
+++ b/server/test/example/vm.lua
@@ -434,7 +434,6 @@ function mt:buildFunction(exp, object)
func.argValues[#func.args] = self:getValue(var)
elseif arg.type == '...' then
self:createDots(#func.args+1, arg)
- func.hasDots = true
for _ = 1, 10 do
func.argValues[#func.argValues+1] = self:createValue('any', arg)
end
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index cda10baa..e5686c9e 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -1,5 +1,6 @@
local parser = require 'parser'
local core = require 'core'
+local buildVM = require 'vm'
rawset(_G, 'TEST', true)
@@ -10,10 +11,10 @@ function TEST(script)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
local ast = parser:ast(new_script)
- local vm = core.vm(ast)
+ local vm = buildVM(ast)
assert(vm)
- local result, source = core.findSource(vm, pos)
- local hover = core.hover(result, source)
+ local source = core.findSource(vm, pos)
+ local hover = core.hover(source)
if expect then
assert(hover)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')