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

简单接入 hover 协议

parent 67ae2be2
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ local function getHoverAsFunction(source)
local label = table.concat(labels, '\n')
return {
label = label,
source = source,
}
end
......
......@@ -8,6 +8,7 @@ local define = require 'proto.define'
local workspace = require 'workspace'
local config = require 'config'
local library = require 'library'
local markdown = require 'provider.markdown'
local function updateConfig()
local configs = proto.awaitRequest('workspace/configuration', {
......@@ -143,12 +144,28 @@ proto.on('textDocument/didChange', function (params)
end
end)
proto.on('textDocument/hover', function ()
proto.on('textDocument/hover', function (params)
local core = require 'core.hover'
local doc = params.textDocument
local uri = doc.uri
if not files.exists(uri) then
return nil
end
local lines = files.getLines(uri)
local text = files.getText(uri)
local offset = define.offset(lines, text, params.position)
local hover = core(uri, offset)
if not hover then
return nil
end
local md = markdown()
md:add('lua', hover.label)
return {
contents = {
value = 'Hello loli!',
value = md:string(),
kind = 'markdown',
}
},
range = define.range(lines, text, hover.source.start, hover.source.finish),
}
end)
......
local mt = {}
mt.__index = mt
mt.__name = 'markdown'
function mt:add(language, text)
if not text then
return
end
if language == 'lua' then
self[#self+1] = ('```lua\n%s\n```'):format(text)
else
self[#self+1] = text:gsub('\n', '\n\n')
end
end
function mt:string()
return table.concat(self, '\n')
end
return function ()
return setmetatable({}, mt)
end
......@@ -768,7 +768,10 @@ end
function vm.isSameValue(a, b)
local valuesA = vm.getValue(a)
local valuesB = vm.getValue(b)
if valuesA == valuesB and valuesA ~= nil then
if not valuesA or not valuesB then
return false
end
if valuesA == valuesB then
return true
end
local values = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment