summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-22 14:28:00 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-22 14:28:00 +0800
commitdc7275ac9b56f26923c80c1e8bbce185c2d147a4 (patch)
tree8a5a325980feb3b0cd8b101ce5f37ee48779116d /server-beta
parent67ae2be22b43fec1c7bab1044842951eba84d37d (diff)
downloadlua-language-server-dc7275ac9b56f26923c80c1e8bbce185c2d147a4.zip
简单接入 hover 协议
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/hover/init.lua3
-rw-r--r--server-beta/src/provider/init.lua23
-rw-r--r--server-beta/src/provider/markdown.lua22
-rw-r--r--server-beta/src/vm/getValue.lua5
4 files changed, 48 insertions, 5 deletions
diff --git a/server-beta/src/core/hover/init.lua b/server-beta/src/core/hover/init.lua
index c47aee6d..9de5f4da 100644
--- a/server-beta/src/core/hover/init.lua
+++ b/server-beta/src/core/hover/init.lua
@@ -16,7 +16,8 @@ local function getHoverAsFunction(source)
local label = table.concat(labels, '\n')
return {
- label = label,
+ label = label,
+ source = source,
}
end
diff --git a/server-beta/src/provider/init.lua b/server-beta/src/provider/init.lua
index 41a022da..95f4b3d1 100644
--- a/server-beta/src/provider/init.lua
+++ b/server-beta/src/provider/init.lua
@@ -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)
diff --git a/server-beta/src/provider/markdown.lua b/server-beta/src/provider/markdown.lua
new file mode 100644
index 00000000..0f69ad87
--- /dev/null
+++ b/server-beta/src/provider/markdown.lua
@@ -0,0 +1,22 @@
+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
diff --git a/server-beta/src/vm/getValue.lua b/server-beta/src/vm/getValue.lua
index c8d62574..07ebe2a5 100644
--- a/server-beta/src/vm/getValue.lua
+++ b/server-beta/src/vm/getValue.lua
@@ -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 = {}