summaryrefslogtreecommitdiff
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
parent2d5c2cc1bfb64cc07ec72512522eedb07a8a9180 (diff)
downloadlua-language-server-c21f410d16d03a24464e21212cb7dfe8f7787746.zip
API描述内部的链接使用本地文档
-rw-r--r--locale/en-US/libs/@lua/string.lni10
-rw-r--r--locale/en-US/script.lni22
-rw-r--r--locale/zh-CN/libs/@lua/string.lni10
-rw-r--r--locale/zh-CN/script.lni22
-rw-r--r--script/core/hover/lib_function.lua58
5 files changed, 73 insertions, 49 deletions
diff --git a/locale/en-US/libs/@lua/string.lni b/locale/en-US/libs/@lua/string.lni
index 2055b16b..4d0587c6 100644
--- a/locale/en-US/libs/@lua/string.lni
+++ b/locale/en-US/libs/@lua/string.lni
@@ -8,7 +8,7 @@ description = 'Returns a string with length equal to the number of arguments, in
description = 'Returns a string containing a binary representation (a *binary chunk*) of the given function.'
[find]
-description = 'Looks for the first match of [`pattern`](https://www.lua.org/manual/5.3/manual.html#6.4.1) in the string.'
+description = 'Looks for the first match of [`pattern`](doc:6.4.1) in the string.'
[format]
description = 'Returns a formatted version of its variable number of arguments following the description given in its first argument.'
@@ -36,7 +36,7 @@ end
]]
[gsub]
-description = 'Returns a copy of s in which all (or the first `n`, if given) occurrences of the [`pattern`](https://www.lua.org/manual/5.3/manual.html#6.4.1) have been replaced by a replacement string specified by `repl`.'
+description = 'Returns a copy of s in which all (or the first `n`, if given) occurrences of the [`pattern`](doc:6.4.1) have been replaced by a replacement string specified by `repl`.'
[len]
description = 'Returns its length.'
@@ -45,10 +45,10 @@ description = 'Returns its length.'
description = 'Returns a copy of this string with all uppercase letters changed to lowercase.'
[match]
-description = 'Looks for the first match of [`pattern`](https://www.lua.org/manual/5.3/manual.html#6.4.1) in the string.'
+description = 'Looks for the first match of [`pattern`](doc:6.4.1) in the string.'
[pack]
-description = 'Returns a binary string containing the values `v1`, `v2`, etc. packed (that is, serialized in binary form) according to the format string [`fmt`](https://www.lua.org/manual/5.3/manual.html#6.4.2).'
+description = 'Returns a binary string containing the values `v1`, `v2`, etc. packed (that is, serialized in binary form) according to the format string [`fmt`](doc:6.4.2).'
[packsize]
description = 'Returns the size of a string resulting from `string.pack` with the given format.'
@@ -66,7 +66,7 @@ description = 'Returns a string that is the string `s` reversed.'
description = 'Returns the substring of the string that starts at `i` and continues until `j`.'
[unpack]
-description = 'Returns the values packed in string according to the format string [`fmt`](https://www.lua.org/manual/5.3/manual.html#6.4.2).'
+description = 'Returns the values packed in string according to the format string [`fmt`](doc:6.4.2).'
[upper]
description = 'Returns a copy of this string with all lowercase letters changed to uppercase.'
diff --git a/locale/en-US/script.lni b/locale/en-US/script.lni
index 1c151197..fd049d7f 100644
--- a/locale/en-US/script.lni
+++ b/locale/en-US/script.lni
@@ -84,18 +84,20 @@ PARSER_MISS_SEP_IN_TABLE = 'Miss symbol `,` or `;` .'
SYMBOL_ANONYMOUS = '<Anonymous>'
-HOVER_DOCUMENT_LUA51 = '[View documents](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA52 = '[View documents](http://www.lua.org/manual/5.2/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA53 = '[View documents](http://www.lua.org/manual/5.3/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA54 = '[View documents](http://www.lua.org/manual/5.4/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUAJIT = '[View documents](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
+HOVER_VIEW_DOCUMENTS = 'View documents'
+HOVER_DOCUMENT_LUA51 = 'http://www.lua.org/manual/5.1/manual.html#{}'
+HOVER_DOCUMENT_LUA52 = 'http://www.lua.org/manual/5.2/manual.html#{}'
+HOVER_DOCUMENT_LUA53 = 'http://www.lua.org/manual/5.3/manual.html#{}'
+HOVER_DOCUMENT_LUA54 = 'http://www.lua.org/manual/5.4/manual.html#{}'
+HOVER_DOCUMENT_LUAJIT = 'http://www.lua.org/manual/5.1/manual.html#{}'
-HOVER_NATIVE_DOCUMENT_LUA51 = '[View documents](command:extension.lua.doc?["en-us/51/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA52 = '[View documents](command:extension.lua.doc?["en-us/52/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA53 = '[View documents](command:extension.lua.doc?["en-us/53/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA54 = '[View documents](command:extension.lua.doc?["en-us/54/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUAJIT = '[View documents](command:extension.lua.doc?["en-us/51/manual.html/pdf-{}"])'
+
+HOVER_NATIVE_DOCUMENT_LUA51 = 'command:extension.lua.doc?["en-us/51/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA52 = 'command:extension.lua.doc?["en-us/52/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA53 = 'command:extension.lua.doc?["en-us/53/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA54 = 'command:extension.lua.doc?["en-us/54/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUAJIT = 'command:extension.lua.doc?["en-us/51/manual.html/{}"]'
HOVER_MULTI_PROTOTYPE = '({} prototypes)'
diff --git a/locale/zh-CN/libs/@lua/string.lni b/locale/zh-CN/libs/@lua/string.lni
index 6aa78cce..49ad538a 100644
--- a/locale/zh-CN/libs/@lua/string.lni
+++ b/locale/zh-CN/libs/@lua/string.lni
@@ -8,7 +8,7 @@ description = '接收零或更多的整数。 返回和参数数量相同长度
description = '返回包含有以二进制方式表示的(一个 *二进制代码块* )指定函数的字符串。'
[find]
-description = '查找第一个字符串中匹配到的 [`pattern`](https://cloudwu.github.io/lua53doc/manual.html#6.4.1)。'
+description = '查找第一个字符串中匹配到的 [`pattern`](doc:6.4.1)。'
[format]
description = '返回不定数量参数的格式化版本,格式化串为第一个参数。'
@@ -25,7 +25,7 @@ end
]]
[gsub]
-description = '将字符串中,所有的(或是在 `n` 给出时的前 `n` 个) [`pattern`](https://cloudwu.github.io/lua53doc/manual.html#6.4.1) 都替换成 `repl` ,并返回其副本。'
+description = '将字符串中,所有的(或是在 `n` 给出时的前 `n` 个) [`pattern`](doc:6.4.1) 都替换成 `repl` ,并返回其副本。'
[len]
description = '返回其长度。'
@@ -34,10 +34,10 @@ description = '返回其长度。'
description = '将其中的大写字符都转为小写后返回其副本。'
[match]
-description = '在字符串中找到第一个能用 [`pattern`](https://cloudwu.github.io/lua53doc/manual.html#6.4.1) 匹配到的部分。'
+description = '在字符串中找到第一个能用 [`pattern`](doc:6.4.1) 匹配到的部分。'
[pack]
-description = '返回一个打包了(即以二进制形式序列化) `v1`, `v2` 等值的二进制字符串。 字符串 [`fmt`](https://cloudwu.github.io/lua53doc/manual.html#6.4.2) 为打包格式。'
+description = '返回一个打包了(即以二进制形式序列化) `v1`, `v2` 等值的二进制字符串。 字符串 [`fmt`](doc:6.4.2) 为打包格式。'
[packsize]
description = '返回以指定格式用 `string.pack` 打包的字符串的长度。'
@@ -55,7 +55,7 @@ description = '返回字符串的翻转串。'
description = '返回字符串的子串, 该子串从 `i` 开始到 `j` 为止。'
[unpack]
-description = '返回以格式 [`fmt`](https://cloudwu.github.io/lua53doc/manual.html#6.4.2) 打包在字符串中的值。'
+description = '返回以格式 [`fmt`](doc:6.4.2) 打包在字符串中的值。'
[upper]
description = '接收一个字符串,将其中的小写字符都转为大写后返回其副本。'
diff --git a/locale/zh-CN/script.lni b/locale/zh-CN/script.lni
index aa819aff..f08872f4 100644
--- a/locale/zh-CN/script.lni
+++ b/locale/zh-CN/script.lni
@@ -84,17 +84,19 @@ PARSER_MISS_SEP_IN_TABLE = '需要用`,`或`;`进行分割。'
SYMBOL_ANONYMOUS = '<匿名函数>'
-HOVER_DOCUMENT_LUA51 = '[查看文档](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA52 = '[查看文档](http://www.lua.org/manual/5.2/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA53 = '[查看文档](http://cloudwu.github.io/lua53doc/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUA54 = '[查看文档](http://www.lua.org/manual/5.4/manual.html#pdf-{})'
-HOVER_DOCUMENT_LUAJIT = '[查看文档](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
+HOVER_VIEW_DOCUMENTS = '查看文档'
-HOVER_NATIVE_DOCUMENT_LUA51 = '[查看文档](command:extension.lua.doc?["en-us/51/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA52 = '[查看文档](command:extension.lua.doc?["en-us/52/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA53 = '[查看文档](command:extension.lua.doc?["zh-cn/53/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUA54 = '[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-{}"])'
-HOVER_NATIVE_DOCUMENT_LUAJIT = '[查看文档](command:extension.lua.doc?["en-us/51/manual.html/pdf-{}"])'
+HOVER_DOCUMENT_LUA51 = 'http://www.lua.org/manual/5.1/manual.html#{}'
+HOVER_DOCUMENT_LUA52 = 'http://www.lua.org/manual/5.2/manual.html#{}'
+HOVER_DOCUMENT_LUA53 = 'http://cloudwu.github.io/lua53doc/manual.html#{}'
+HOVER_DOCUMENT_LUA54 = 'http://www.lua.org/manual/5.4/manual.html#{}'
+HOVER_DOCUMENT_LUAJIT = 'http://www.lua.org/manual/5.1/manual.html#{}'
+
+HOVER_NATIVE_DOCUMENT_LUA51 = 'command:extension.lua.doc?["en-us/51/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA52 = 'command:extension.lua.doc?["en-us/52/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA53 = 'command:extension.lua.doc?["zh-cn/53/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUA54 = 'command:extension.lua.doc?["en-us/54/manual.html/{}"]'
+HOVER_NATIVE_DOCUMENT_LUAJIT = 'command:extension.lua.doc?["en-us/51/manual.html/{}"]'
HOVER_MULTI_PROTOTYPE = '({} 个原型)'
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),