diff options
Diffstat (limited to 'server-beta/src/core/hover')
-rw-r--r-- | server-beta/src/core/hover/arg.lua | 20 | ||||
-rw-r--r-- | server-beta/src/core/hover/function.lua | 10 | ||||
-rw-r--r-- | server-beta/src/core/hover/init.lua | 14 | ||||
-rw-r--r-- | server-beta/src/core/hover/label.lua | 14 | ||||
-rw-r--r-- | server-beta/src/core/hover/name.lua | 16 |
5 files changed, 61 insertions, 13 deletions
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 |