summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/hover.lua14
-rw-r--r--server/src/matcher/vm.lua8
-rw-r--r--server/src/method/textDocument/hover.lua2
-rw-r--r--server/test/crossfile/hover.lua42
4 files changed, 53 insertions, 13 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua
index 774cce92..7b157892 100644
--- a/server/src/matcher/hover.lua
+++ b/server/src/matcher/hover.lua
@@ -182,13 +182,13 @@ local function buildValueName(result, source)
elseif declarat.type == 'number' or declarat.type == 'boolean' then
key = tostring(declarat[1])
else
- key = '?'
+ key = ''
end
local parentName = declarat.parentName
if not parentName then
- return result.key or ''
+ return key or ''
end
if parentName == '?' then
@@ -282,14 +282,14 @@ end
local function getFunctionHover(name, result, source, lib, oo, select)
local args = ''
local returns
- local enum = ''
- local tip = ''
+ local enum
+ local tip
local argLabel
if lib then
args, argLabel = buildLibArgs(lib, oo, select)
returns = buildLibReturns(lib)
enum = buildEnum(lib)
- tip = lib.description or ''
+ tip = lib.description
else
args, argLabel = buildValueArgs(result, source, select)
returns = buildValueReturns(result)
@@ -362,10 +362,9 @@ local function getValueHover(name, valueType, result, source, lib)
local tip
if lib then
value = lib.code or (lib.value and ('%q'):format(lib.value))
- tip = lib.description or ''
+ tip = lib.description
else
value = result.value.value and ('%q'):format(result.value.value)
- tip = ''
end
local text
@@ -389,7 +388,6 @@ local function getStringHover(result, lsp)
end
local path = lsp.workspace:relativePathByUri(result.uri)
return {
- label = '',
description = ('[%s](%s)'):format(path:string(), result.uri),
}
end
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 48a8a49c..de55c12e 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -114,6 +114,11 @@ function mt:addInfo(obj, type, source)
else
self.results.sources[source] = obj
end
+ if type == 'set' or type == 'return' then
+ if not obj.declarat then
+ obj.declarat = source
+ end
+ end
end
return obj
end
@@ -262,9 +267,6 @@ function mt:setValue(var, value, source)
if source and source.start then
self:addInfo(var, 'set', source)
self:addInfo(value, 'set', source)
- if not value.declarat then
- value.declarat = source
- end
end
return value
end
diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua
index dfc9a043..ca894797 100644
--- a/server/src/method/textDocument/hover.lua
+++ b/server/src/method/textDocument/hover.lua
@@ -27,7 +27,7 @@ return function (lsp, params)
```lua
%s
```
-]]):format(hover.label, hover.description, hover.enum or '')
+]]):format(hover.label or '', hover.description or '', hover.enum or '')
local response = {
contents = {
diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua
index 0fbb59e6..59ad4fe1 100644
--- a/server/test/crossfile/hover.lua
+++ b/server/test/crossfile/hover.lua
@@ -88,7 +88,47 @@ TEST {
content = 'require <?"a"?>',
},
hover = {
- label = '',
description = [[[a.lua](file:///C%3A/Users/sunyi/.vscode/extensions/sumneko.lua-language-server/server/a.lua)]],
}
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ local function f(a, b)
+ end
+ return f
+ ]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ local x = require 'a'
+ <?x?>()
+ ]]
+ },
+ hover = {
+ label = 'function f(a: any, b: any)',
+ }
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ return function (a, b)
+ end
+ ]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ local f = require 'a'
+ <?f?>()
+ ]]
+ },
+ hover = {
+ label = 'function (a: any, b: any)',
+ }
+}