summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-beta/src/core/diagnostics/lowercase-global.lua2
-rw-r--r--server-beta/src/core/hover/arg.lua20
-rw-r--r--server-beta/src/core/hover/function.lua10
-rw-r--r--server-beta/src/core/hover/init.lua14
-rw-r--r--server-beta/src/core/hover/label.lua14
-rw-r--r--server-beta/src/core/hover/name.lua16
-rw-r--r--server-beta/src/parser/guide.lua10
-rw-r--r--server-beta/src/vm/eachRef.lua4
-rw-r--r--server-beta/src/vm/getLibrary.lua2
-rw-r--r--server-beta/test/hover/init.lua3
10 files changed, 74 insertions, 21 deletions
diff --git a/server-beta/src/core/diagnostics/lowercase-global.lua b/server-beta/src/core/diagnostics/lowercase-global.lua
index f1ebdce5..bc48e1e6 100644
--- a/server-beta/src/core/diagnostics/lowercase-global.lua
+++ b/server-beta/src/core/diagnostics/lowercase-global.lua
@@ -20,7 +20,7 @@ return function (uri, callback)
end
guide.eachSourceType(ast.ast, 'setglobal', function (source)
- local name = guide.getKeyString(source)
+ local name = guide.getName(source)
if definedGlobal[name] then
return
end
diff --git a/server-beta/src/core/hover/arg.lua b/server-beta/src/core/hover/arg.lua
new file mode 100644
index 00000000..be344488
--- /dev/null
+++ b/server-beta/src/core/hover/arg.lua
@@ -0,0 +1,20 @@
+local guide = require 'parser.guide'
+local vm = require 'vm'
+
+local function asFunction(source)
+ if not source.args then
+ return ''
+ end
+ local args = {}
+ for i = 1, #source.args do
+ local arg = source.args[i]
+ args[i] = ('%s: %s'):format(guide.getName(arg), vm.getType(arg))
+ end
+ return table.concat(args, ', ')
+end
+
+return function (source)
+ if source.type == 'function' then
+ return asFunction(source)
+ end
+end
diff --git a/server-beta/src/core/hover/function.lua b/server-beta/src/core/hover/function.lua
deleted file mode 100644
index 15e54306..00000000
--- a/server-beta/src/core/hover/function.lua
+++ /dev/null
@@ -1,10 +0,0 @@
-local m = {}
-
-function m.label(source)
- if source.type ~= 'function' then
- return
- end
-
-end
-
-return m
diff --git a/server-beta/src/core/hover/init.lua b/server-beta/src/core/hover/init.lua
index af1bf6da..c47aee6d 100644
--- a/server-beta/src/core/hover/init.lua
+++ b/server-beta/src/core/hover/init.lua
@@ -1,21 +1,29 @@
local files = require 'files'
local guide = require 'parser.guide'
local vm = require 'vm'
-local funcHover = require 'core.hover.function'
+local getLabel = require 'core.hover.label'
local function getHoverAsFunction(source)
+ local uri = guide.getRoot(source).uri
+ local text = files.getText(uri)
local values = vm.getValue(source)
+ local labels = {}
for _, value in ipairs(values) do
if value.type == 'function' then
- local funcLabel = funcHover.label(value.source)
+ labels[#labels+1] = getLabel(value.source)
end
end
+
+ local label = table.concat(labels, '\n')
+ return {
+ label = label,
+ }
end
local function getHover(source)
local isFunction = vm.hasType(source, 'function')
if isFunction then
- getHoverAsFunction(source)
+ return getHoverAsFunction(source)
end
end
diff --git a/server-beta/src/core/hover/label.lua b/server-beta/src/core/hover/label.lua
new file mode 100644
index 00000000..1dc66fc5
--- /dev/null
+++ b/server-beta/src/core/hover/label.lua
@@ -0,0 +1,14 @@
+local buildName = require 'core.hover.name'
+local buildArg = require 'core.hover.arg'
+
+local function asFunction(source)
+ local name = buildName(source)
+ local arg = buildArg(source)
+ return ('function %s(%s)'):format(name, arg)
+end
+
+return function (source)
+ if source.type == 'function' then
+ return asFunction(source)
+ end
+end
diff --git a/server-beta/src/core/hover/name.lua b/server-beta/src/core/hover/name.lua
new file mode 100644
index 00000000..d0caf885
--- /dev/null
+++ b/server-beta/src/core/hover/name.lua
@@ -0,0 +1,16 @@
+local function asLocal(source)
+ return source[1]
+end
+
+return function (source)
+ local parent = source.parent
+ if not parent then
+ return ''
+ end
+ if parent.type == 'local'
+ or parent.type == 'getlocal'
+ or parent.type == 'setlocal' then
+ return asLocal(parent)
+ end
+ return ''
+end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index f91c677e..af511555 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -444,11 +444,15 @@ function m.lineRange(lines, row)
return line.start, line.finish
end
-function m.getKeyString(obj)
+function m.getName(obj)
local tp = obj.type
if tp == 'getglobal'
or tp == 'setglobal' then
return obj[1]
+ elseif tp == 'local'
+ or tp == 'getlocal'
+ or tp == 'setlocal' then
+ return obj[1]
elseif tp == 'getfield'
or tp == 'setfield'
or tp == 'tablefield' then
@@ -459,12 +463,12 @@ function m.getKeyString(obj)
elseif tp == 'getindex'
or tp == 'setindex'
or tp == 'tableindex' then
- return m.getKeyString(obj.index)
+ return m.getName(obj.index)
elseif tp == 'field'
or tp == 'method' then
return obj[1]
elseif tp == 'index' then
- return m.getKeyString(obj.index)
+ return m.getName(obj.index)
elseif tp == 'string' then
return obj[1]
end
diff --git a/server-beta/src/vm/eachRef.lua b/server-beta/src/vm/eachRef.lua
index 543a0c09..465b1267 100644
--- a/server-beta/src/vm/eachRef.lua
+++ b/server-beta/src/vm/eachRef.lua
@@ -163,7 +163,7 @@ end
local function asValue(source, callback)
local parent = source.parent
if parent and parent.value == source then
- if guide.getKeyString(parent) == '__index' then
+ if guide.getName(parent) == '__index' then
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
local t = parent.parent
@@ -274,7 +274,7 @@ local function ofLocal(loc, callback)
end
end
elseif ref.type == 'getglobal' then
- if guide.getKeyString(ref) == '_G' then
+ if guide.getName(ref) == '_G' then
callback {
source = ref,
mode = 'get',
diff --git a/server-beta/src/vm/getLibrary.lua b/server-beta/src/vm/getLibrary.lua
index d2645790..fd05347e 100644
--- a/server-beta/src/vm/getLibrary.lua
+++ b/server-beta/src/vm/getLibrary.lua
@@ -20,7 +20,7 @@ local function getLibInNode(source, nodeLib)
if not nodeLib.child then
return nil
end
- local key = guide.getKeyString(source)
+ local key = guide.getName(source)
local defLib = nodeLib.child[key]
return defLib
end
diff --git a/server-beta/test/hover/init.lua b/server-beta/test/hover/init.lua
index 9552e753..5349fb96 100644
--- a/server-beta/test/hover/init.lua
+++ b/server-beta/test/hover/init.lua
@@ -10,7 +10,8 @@ function TEST(script)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local hover = core(new_script, pos)
+ files.setText('', new_script)
+ local hover = core('', pos)
assert(hover)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')