summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-06-03 11:13:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-06-03 11:13:57 +0800
commitc21f410d16d03a24464e21212cb7dfe8f7787746 (patch)
treecff1cb28dd87d55446b3d934ac438c9a53551d68 /script/core
parent2d5c2cc1bfb64cc07ec72512522eedb07a8a9180 (diff)
downloadlua-language-server-c21f410d16d03a24464e21212cb7dfe8f7787746.zip
API描述内部的链接使用本地文档
Diffstat (limited to 'script/core')
-rw-r--r--script/core/hover/lib_function.lua58
1 files changed, 39 insertions, 19 deletions
diff --git a/script/core/hover/lib_function.lua b/script/core/hover/lib_function.lua
index 92e6a34f..162b6b75 100644
--- a/script/core/hover/lib_function.lua
+++ b/script/core/hover/lib_function.lua
@@ -181,39 +181,59 @@ local function buildEnum(lib)
return table.concat(strs), raw
end
-local function buildDoc(lib)
- local doc = lib.doc
- if not doc then
- return
- end
- if lib.web then
- return lang.script(lib.web, doc)
- end
+local function getDocFormater()
local version = config.config.runtime.version
if client.client() == 'vscode' then
if version == 'Lua 5.1' then
- return lang.script('HOVER_NATIVE_DOCUMENT_LUA51', doc)
+ return 'HOVER_NATIVE_DOCUMENT_LUA51'
elseif version == 'Lua 5.2' then
- return lang.script('HOVER_NATIVE_DOCUMENT_LUA52', doc)
+ return 'HOVER_NATIVE_DOCUMENT_LUA52'
elseif version == 'Lua 5.3' then
- return lang.script('HOVER_NATIVE_DOCUMENT_LUA53', doc)
+ return 'HOVER_NATIVE_DOCUMENT_LUA53'
elseif version == 'Lua 5.4' then
- return lang.script('HOVER_NATIVE_DOCUMENT_LUA54', doc)
+ return 'HOVER_NATIVE_DOCUMENT_LUA54'
elseif version == 'LuaJIT' then
- return lang.script('HOVER_NATIVE_DOCUMENT_LUAJIT', doc)
+ return 'HOVER_NATIVE_DOCUMENT_LUAJIT'
end
else
if version == 'Lua 5.1' then
- return lang.script('HOVER_DOCUMENT_LUA51', doc)
+ return 'HOVER_DOCUMENT_LUA51'
elseif version == 'Lua 5.2' then
- return lang.script('HOVER_DOCUMENT_LUA52', doc)
+ return 'HOVER_DOCUMENT_LUA52'
elseif version == 'Lua 5.3' then
- return lang.script('HOVER_DOCUMENT_LUA53', doc)
+ return 'HOVER_DOCUMENT_LUA53'
elseif version == 'Lua 5.4' then
- return lang.script('HOVER_DOCUMENT_LUA54', doc)
+ return 'HOVER_DOCUMENT_LUA54'
elseif version == 'LuaJIT' then
- return lang.script('HOVER_DOCUMENT_LUAJIT', doc)
+ return 'HOVER_DOCUMENT_LUAJIT'
+ end
+ end
+end
+
+local function buildDescription(lib)
+ local desc = lib.description
+ if not desc then
+ return
+ end
+ return desc:gsub('%(doc%:(.-)%)', function (tag)
+ local fmt = getDocFormater()
+ if fmt then
+ return '(' .. lang.script(fmt, tag) .. ')'
end
+ end)
+end
+
+local function buildDoc(lib)
+ local doc = lib.doc
+ if not doc then
+ return
+ end
+ if lib.web then
+ return lang.script(lib.web, doc)
+ end
+ local fmt = getDocFormater()
+ if fmt then
+ return ('[%s](%s)'):format(lang.script.HOVER_VIEW_DOCUMENTS, lang.script(fmt, 'pdf-' .. doc))
end
end
@@ -221,7 +241,7 @@ return function (name, lib, object, select)
local argStr, argLabel, args = buildLibArgs(lib, object, select)
local returns = buildLibReturns(lib)
local enum, rawEnum = buildEnum(lib)
- local tip = lib.description
+ local tip = buildDescription(lib)
local doc = buildDoc(lib)
return {
label = ('function %s(%s)%s'):format(name, argStr, returns),