From cfd28f56f6c0083aede3f16d47976337fecb28e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 16 Sep 2020 12:58:49 +0800 Subject: =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/core/hover/description.lua | 59 ++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'script-beta/core/hover/description.lua') 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) -- cgit v1.2.3