Skip to content
Snippets Groups Projects
Commit cfd28f56 authored by 最萌小汐's avatar 最萌小汐
Browse files

查看文档

parent 720824b2
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,10 @@ 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)
......
local nonil = require 'without-check-nil'
local m = {}
function m.client()
nonil.enable()
local name = m.info.clientInfo.name
nonil.disable()
return name
end
function m.init(t)
m.info = t
end
return m
......@@ -9,7 +9,7 @@ function mt:add(language, text)
if language == 'lua' then
self[#self+1] = ('```lua\n%s\n```'):format(text)
else
self[#self+1] = text
self[#self+1] = text .. '\n'
end
end
......
......@@ -9,6 +9,7 @@ local workspace = require 'workspace'
local config = require 'config'
local library = require 'library'
local markdown = require 'provider.markdown'
local client = require 'provider.client'
local function updateConfig()
local configs = proto.awaitRequest('workspace/configuration', {
......@@ -77,6 +78,7 @@ end)
proto.on('initialized', function (params)
updateConfig()
client.init(params)
proto.awaitRequest('client/registerCapability', {
registrations = {
-- 监视文件变化
......
local m = {}
local mt = {}
mt.__add = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a + b
end
mt.__sub = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a - b
end
mt.__mul = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a * b
end
mt.__div = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a / b
end
mt.__mod = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a % b
end
mt.__pow = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a ^ b
end
mt.__unm = function ()
return 0
end
mt.__concat = function (a, b)
if a == nil then a = '' end
if b == nil then b = '' end
return a .. b
end
mt.__len = function ()
return 0
end
mt.__lt = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a < b
end
mt.__le = function (a, b)
if a == nil then a = 0 end
if b == nil then b = 0 end
return a <= b
end
mt.__index = function () end
mt.__newindex = function () end
mt.__call = function () end
mt.__pairs = function () end
mt.__ipairs = function () end
if _VERSION == 'Lua 5.3' or _VERSION == 'Lua 5.4' then
mt.__idiv = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a // b
]]
mt.__band = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a & b
]]
mt.__bor = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a | b
]]
mt.__bxor = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a ~ b
]]
mt.__bnot = load[[
return ~ 0
]]
mt.__shl = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a << b
]]
mt.__shr = load[[
local a, b = ...
if a == nil then a = 0 end
if b == nil then b = 0 end
return a >> b
]]
end
for event, func in pairs(mt) do
mt[event] = function (...)
local watch = m.watch
if not watch then
return func(...)
end
local care, result = watch(event, ...)
if not care then
return func(...)
end
return result
end
end
function m.enable()
debug.setmetatable(nil, mt)
end
function m.disable()
if debug.getmetatable(nil) == mt then
debug.setmetatable(nil, nil)
end
end
return m
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment