summaryrefslogtreecommitdiff
path: root/script-beta/core/hover/description.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-16 12:58:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-16 12:58:49 +0800
commitcfd28f56f6c0083aede3f16d47976337fecb28e9 (patch)
tree1bf2c8b11d847f03f49445f3a19c7b68f9b44c9e /script-beta/core/hover/description.lua
parent720824b2b118df49b7fa03a7ccc98bd48cbff2c6 (diff)
downloadlua-language-server-cfd28f56f6c0083aede3f16d47976337fecb28e9.zip
查看文档
Diffstat (limited to 'script-beta/core/hover/description.lua')
-rw-r--r--script-beta/core/hover/description.lua59
1 files changed, 52 insertions, 7 deletions
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua
index 9f44b72d..746d602e 100644
--- a/script-beta/core/hover/description.lua
+++ b/script-beta/core/hover/description.lua
@@ -1,8 +1,12 @@
-local vm = require 'vm'
-local ws = require 'workspace'
-local furi = require 'file-uri'
-local files = require 'files'
-local guide = require 'parser.guide'
+local vm = require 'vm'
+local ws = require 'workspace'
+local furi = require 'file-uri'
+local files = require 'files'
+local guide = require 'parser.guide'
+local markdown = require 'provider.markdown'
+local config = require 'config'
+local client = require 'provider.client'
+local lang = require 'language'
local function asString(source)
local literal = guide.getLiteral(source)
@@ -40,12 +44,53 @@ local function asString(source)
end
end
+local function getDocFormater()
+ local version = config.config.runtime.version
+ if client.client() == 'vscode' then
+ if version == 'Lua 5.1' then
+ return 'HOVER_NATIVE_DOCUMENT_LUA51'
+ elseif version == 'Lua 5.2' then
+ return 'HOVER_NATIVE_DOCUMENT_LUA52'
+ elseif version == 'Lua 5.3' then
+ return 'HOVER_NATIVE_DOCUMENT_LUA53'
+ elseif version == 'Lua 5.4' then
+ return 'HOVER_NATIVE_DOCUMENT_LUA54'
+ elseif version == 'LuaJIT' then
+ return 'HOVER_NATIVE_DOCUMENT_LUAJIT'
+ end
+ else
+ if version == 'Lua 5.1' then
+ return 'HOVER_DOCUMENT_LUA51'
+ elseif version == 'Lua 5.2' then
+ return 'HOVER_DOCUMENT_LUA52'
+ elseif version == 'Lua 5.3' then
+ return 'HOVER_DOCUMENT_LUA53'
+ elseif version == 'Lua 5.4' then
+ return 'HOVER_DOCUMENT_LUA54'
+ elseif version == 'LuaJIT' then
+ return 'HOVER_DOCUMENT_LUAJIT'
+ end
+ end
+end
+
local function tryLibrary(source)
local lib = vm.getLibrary(source)
if not lib then
- return
+ return nil
+ end
+ local fmt = getDocFormater()
+ local md = markdown()
+ if lib.value.description then
+ md:add('markdown', lib.value.description:gsub('%(doc%:(.-)%)', function (tag)
+ if fmt then
+ return '(' .. lang.script(fmt, tag) .. ')'
+ end
+ end))
+ end
+ if lib.value.doc and fmt then
+ md:add('markdown', ('[%s](%s)'):format(lang.script.HOVER_VIEW_DOCUMENTS, lang.script(fmt, 'pdf-' .. lib.value.doc)))
end
- return lib.value.description
+ return md:string()
end
return function (source)