summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-21 16:44:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-21 16:44:21 +0800
commitbc0ab7b1fa924076a549cdcaaf3e90a6ef67600f (patch)
tree6c93154af1822b87d02915bdcdb028fec48338f9
parent70da60a80f2d00c235560f235d3f5ded703dfe4e (diff)
downloadlua-language-server-bc0ab7b1fa924076a549cdcaaf3e90a6ef67600f.zip
hover在外部完成格式化
-rw-r--r--server/src/matcher/hover.lua29
-rw-r--r--server/src/method/textDocument/hover.lua14
-rw-r--r--server/test/hover/init.lua10
3 files changed, 22 insertions, 31 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua
index 9a556104..2ccf6941 100644
--- a/server/src/matcher/hover.lua
+++ b/server/src/matcher/hover.lua
@@ -13,7 +13,7 @@ local OriginTypes = {
['function'] = true,
}
-local function buildLibArgs(lib, oo)
+local function buildLibArgs(lib, oo, select)
if not lib.args then
return ''
end
@@ -259,30 +259,22 @@ local function buildValueReturns(result)
return '\n -> ' .. table.concat(strs, ', ')
end
-local function getFunctionHover(name, result, source, lib, oo)
+local function getFunctionHover(name, result, source, lib, oo, select)
local args = ''
local returns
local enum = ''
local tip = ''
if lib then
- args = buildLibArgs(lib, oo)
+ args = buildLibArgs(lib, oo, select)
returns = buildLibReturns(lib)
enum = buildEnum(lib)
tip = lib.description or ''
else
- args = buildValueArgs(result, source)
+ args = buildValueArgs(result, source, select)
returns = buildValueReturns(result)
end
local title = ('function %s(%s)%s'):format(name, args, returns)
- return ([[
-```lua
-%s
-```
-%s
-```lua
-%s
-```
-]]):format(title, tip, enum)
+ return { title, tip, enum }
end
local function findClass(result)
@@ -356,12 +348,7 @@ local function getValueHover(name, valueType, result, source, lib)
else
text = ('%s %s = %s'):format(valueType, name, value)
end
- return ([[
-```lua
-%s
-```
-%s
-]]):format(text, tip)
+ return { text, tip }
end
local function getStringHover(result, lsp)
@@ -375,7 +362,7 @@ local function getStringHover(result, lsp)
return ('[%s](%s)'):format(path:string(), result.uri)
end
-return function (result, source, lsp)
+return function (result, source, lsp, select)
if not result.value then
return
end
@@ -388,7 +375,7 @@ return function (result, source, lsp)
local valueType = lib and lib.type or result.value.type or 'nil'
local name = fullKey or buildValueName(result, source)
if valueType == 'function' then
- return getFunctionHover(name, result, source, lib, oo)
+ return getFunctionHover(name, result, source, lib, oo, select)
else
return getValueHover(name, valueType, result, source, lib)
end
diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua
index cf6c4aa4..3048d4f8 100644
--- a/server/src/method/textDocument/hover.lua
+++ b/server/src/method/textDocument/hover.lua
@@ -14,11 +14,21 @@ return function (lsp, params)
return nil
end
- local text = matcher.hover(result, source, lsp)
- if not text then
+ local results = matcher.hover(result, source, lsp)
+ if not results then
return nil
end
+ local text = ([[
+```lua
+%s
+```
+%s
+```lua
+%s
+```
+]]):format(results[1], results[2], results[3] or '')
+
local response = {
contents = {
value = text,
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 7aaad1e4..81057039 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -13,10 +13,10 @@ function TEST(script)
local vm = matcher.vm(ast)
assert(vm)
local result, source = matcher.findResult(vm, pos)
- local result = matcher.hover(result, source)
+ local results = matcher.hover(result, source)
assert(result)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
- result = result:gsub('```lua[\r\n]*', ''):gsub('[\r\n]*```', ''):gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
+ local result = results[1]:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
assert(expect == result)
end
end
@@ -167,11 +167,6 @@ TEST [[
[=[
function load(chunk: string/function [, chunkname: string [, mode: string [, env: table]]])
-> function, error_message: string
-Loads a chunk.
-mode: string
- | "b" -- Only binary chunks.
- | "t" -- Only text chunks.
- -> "bt" -- Both binary and text.
]=]
TEST [[
@@ -180,7 +175,6 @@ string.<?lower?>()
[[
function string.lower(string)
-> string
-Returns a copy of this string with all uppercase letters changed to lowercase.
]]
TEST [[