summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/locale/en-US/script.lni6
-rw-r--r--server/locale/zh-CN/script.lni6
-rw-r--r--server/src/core/completion.lua3
-rw-r--r--server/src/core/hover/lib_function.lua24
-rw-r--r--server/src/core/library.lua8
-rw-r--r--server/src/method/textDocument/hover.lua3
6 files changed, 46 insertions, 4 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni
index 51f99eb6..d38e34a4 100644
--- a/server/locale/en-US/script.lni
+++ b/server/locale/en-US/script.lni
@@ -60,6 +60,12 @@ PARSER_UNSUPPORT_SYMBOL = '{version} does not support this grammar.'
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/work/doc/manual.html#pdf-{})'
+HOVER_DOCUMENT_LUAJIT = '[View documents](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
+
ACTION_DISABLE_DIAG = 'Disable diagnostics ({}).'
ACTION_MARK_GLOBAL = 'Mark `{}` as defined global.'
ACTION_REMOVE_SPACE = 'Clear all postemptive spaces.'
diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni
index aa2daf05..5e7a43eb 100644
--- a/server/locale/zh-CN/script.lni
+++ b/server/locale/zh-CN/script.lni
@@ -60,6 +60,12 @@ PARSER_UNSUPPORT_SYMBOL = '{version} 不支持该符号。'
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/work/doc/manual.html#pdf-{})'
+HOVER_DOCUMENT_LUAJIT = '[查看文档](http://www.lua.org/manual/5.1/manual.html#pdf-{})'
+
ACTION_DISABLE_DIAG = '禁用诊断({})。'
ACTION_MARK_GLOBAL = '标记 `{}` 为已定义的全局变量。'
ACTION_REMOVE_SPACE = '清除所有后置空格。'
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index c192535d..3c6d9057 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -69,7 +69,8 @@ local function getDucumentation(name, value)
```lua
%s
```
-]]):format(hover.label or '', hover.description or '', hover.enum or '')
+%s
+]]):format(hover.label or '', hover.description or '', hover.enum or '', hover.doc or '')
return {
kind = 'markdown',
value = text,
diff --git a/server/src/core/hover/lib_function.lua b/server/src/core/hover/lib_function.lua
index c3caea7a..56e6e22f 100644
--- a/server/src/core/hover/lib_function.lua
+++ b/server/src/core/hover/lib_function.lua
@@ -1,4 +1,5 @@
-
+local lang = require 'language'
+local config = require 'config'
local function buildLibArgs(lib, object, select)
if not lib.args then
return ''
@@ -171,11 +172,31 @@ local function buildEnum(lib)
return table.concat(strs)
end
+local function buildDoc(lib)
+ local doc = lib.doc
+ if not doc then
+ return
+ end
+ local version = config.config.runtime.version
+ if version == 'Lua 5.1' then
+ return lang.script('HOVER_DOCUMENT_LUA51', doc)
+ elseif version == 'Lua 5.2' then
+ return lang.script('HOVER_DOCUMENT_LUA52', doc)
+ elseif version == 'Lua 5.3' then
+ return lang.script('HOVER_DOCUMENT_LUA53', doc)
+ elseif version == 'Lua 5.4' then
+ return lang.script('HOVER_DOCUMENT_LUA54', doc)
+ elseif version == 'LuaJIT' then
+ return lang.script('HOVER_DOCUMENT_LUAJIT', doc)
+ end
+end
+
return function (name, lib, object, select)
local args, argLabel = buildLibArgs(lib, object, select)
local returns = buildLibReturns(lib)
local enum = buildEnum(lib)
local tip = lib.description
+ local doc = buildDoc(lib)
local headLen = #('function %s('):format(name)
local title = ('function %s(%s)%s'):format(name, args, returns)
if argLabel then
@@ -187,5 +208,6 @@ return function (name, lib, object, select)
description = tip,
enum = enum,
argLabel = argLabel,
+ doc = doc,
}
end
diff --git a/server/src/core/library.lua b/server/src/core/library.lua
index f0c292aa..d5edad66 100644
--- a/server/src/core/library.lua
+++ b/server/src/core/library.lua
@@ -88,6 +88,9 @@ local function insertGlobal(tbl, key, value)
if not isMatchVersion(value.version) then
return false
end
+ if not value.doc then
+ value.doc = key
+ end
tbl[key] = value
return true
end
@@ -175,6 +178,9 @@ local function insertChild(tbl, name, key, value)
if not isMatchVersion(value.version) then
return
end
+ if not value.doc then
+ value.doc = ('%s.%s'):format(name, key)
+ end
if not tbl[name] then
tbl[name] = {
type = name,
@@ -189,7 +195,7 @@ local function mergeParent(alllibs, name, lib, libName)
for _, parent in ipairs(lib.parent) do
if parent.type == 'global' then
if isEnableGlobal(libName) then
- insertChild(alllibs.global, parent.name, name, lib)
+ insertChild(alllibs.global, parent.name, name, lib)
end
elseif parent.type == 'library' then
insertChild(alllibs.library, parent.name, name, lib)
diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua
index 4ea76d6d..4e4b754d 100644
--- a/server/src/method/textDocument/hover.lua
+++ b/server/src/method/textDocument/hover.lua
@@ -27,7 +27,8 @@ return function (lsp, params)
```lua
%s
```
-]]):format(hover.label or '', hover.description or '', hover.enum or '')
+%s
+]]):format(hover.label or '', hover.description or '', hover.enum or '', hover.doc or '')
local response = {
contents = {