summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 16:57:46 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 16:57:46 +0800
commitebdfb86387f51fd29ec37b6ca586a062b086f525 (patch)
treee7f84d82687c544f14ea484c067fa561f59672bf /server/src/core
parent08ad84a4f6c579a12e7a7e92d438f60c5c360044 (diff)
downloadlua-language-server-ebdfb86387f51fd29ec37b6ca586a062b086f525.zip
支持部分函数写法
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/document_symbol.lua32
-rw-r--r--server/src/core/hover.lua52
-rw-r--r--server/src/core/hover_function.lua8
-rw-r--r--server/src/core/hover_name.lua49
4 files changed, 78 insertions, 63 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 4dc0ebac..b67a97db 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -1,4 +1,5 @@
-local hover = require 'core.hover'
+local hoverFunction = require 'core.hover_function'
+local hoverName = require 'core.hover_name'
local SymbolKind = {
File = 1,
@@ -31,21 +32,34 @@ local SymbolKind = {
local function buildFunc(vm, func, nextFunction, nextFinish)
local source = func.source
- local var = vm.results.sources[source.name] or vm.results.sources[source]
- if not var then
- return
+ local name
+ if source.name then
+ local var = vm.results.sources[source.name]
+ if var then
+ name = hoverName(var, source.name)
+ else
+ name = ''
+ end
+ else
+ name = ''
end
- local hvr = hover(var, source.name or source)
- if not hvr then
+ local hover = hoverFunction(name, func)
+ if not hover then
return
end
+ local selectionRange
+ if source.name then
+ selectionRange = { source.name.start, source.name.finish }
+ else
+ selectionRange = { source.start, source.start }
+ end
return {
- name = hvr.name,
+ name = name,
-- 前端不支持多行
- detail = hvr.label:gsub('[\r\n]', ''),
+ detail = hover.label:gsub('[\r\n]', ''),
kind = SymbolKind.Function,
range = { source.start, source.finish },
- selectionRange = { source.name.start, source.name.finish },
+ selectionRange = selectionRange,
}
end
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index 627a64f5..ea22f1be 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -1,5 +1,6 @@
local findLib = require 'core.find_lib'
local getFunctionHover = require 'core.hover_function'
+local buildValueName = require 'core.hover_name'
local OriginTypes = {
['any'] = true,
@@ -171,55 +172,6 @@ local function buildEnum(lib)
return table.concat(strs)
end
-local function buildValueName(result, source)
- local func = result.value
- local declarat = func.declarat or source
- if declarat then
- local key
- if declarat.type == 'name' then
- key = declarat[1]
- elseif declarat.type == 'string' then
- key = ('%q'):format(declarat[1])
- elseif declarat.type == 'number' or declarat.type == 'boolean' then
- key = tostring(declarat[1])
- elseif func.type == '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
- end
- return result.key or ''
-end
-
local function getFunctionHoverAsLib(name, lib, oo, select)
local args, argLabel = buildLibArgs(lib, oo, select)
local returns = buildLibReturns(lib)
@@ -400,7 +352,7 @@ return function (result, source, lsp, select)
if lib then
hover = getFunctionHoverAsLib(name, lib, oo, select)
else
- hover = getFunctionHover(name, result.value, source, select)
+ hover = getFunctionHover(name, result.value, source.object, select)
end
else
hover = getValueHover(name, valueType, result, source, lib)
diff --git a/server/src/core/hover_function.lua b/server/src/core/hover_function.lua
index 08581a3e..4573bcc2 100644
--- a/server/src/core/hover_function.lua
+++ b/server/src/core/hover_function.lua
@@ -1,4 +1,4 @@
-local function buildValueArgs(func, source, select)
+local function buildValueArgs(func, oo, select)
local names = {}
local values = {}
if func.args then
@@ -14,7 +14,7 @@ local function buildValueArgs(func, source, select)
local strs = {}
local argLabel
local start = 1
- if source.object then
+ if oo then
start = 2
if select then
select = select + 1
@@ -60,8 +60,8 @@ local function buildValueReturns(func)
return '\n -> ' .. table.concat(strs, ', ')
end
-return function (name, func, source, select)
- local args, argLabel = buildValueArgs(func, source, select)
+return function (name, func, oo, select)
+ local args, argLabel = buildValueArgs(func, oo, select)
local returns = buildValueReturns(func)
local title = ('function %s(%s)%s'):format(name, args, returns)
return {
diff --git a/server/src/core/hover_name.lua b/server/src/core/hover_name.lua
new file mode 100644
index 00000000..d8e7b043
--- /dev/null
+++ b/server/src/core/hover_name.lua
@@ -0,0 +1,49 @@
+
+return function (result, source)
+ local func = result.value
+ local declarat = func.declarat or source
+ if declarat then
+ local key
+ if declarat.type == 'name' then
+ key = declarat[1]
+ elseif declarat.type == 'string' then
+ key = ('%q'):format(declarat[1])
+ elseif declarat.type == 'number' or declarat.type == 'boolean' then
+ key = tostring(declarat[1])
+ elseif func.type == '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
+ end
+ return result.key or ''
+end