diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 20:06:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 20:06:20 +0800 |
commit | bafe0e44914ad3b669388b94b91d9992edeb8e07 (patch) | |
tree | 26f78a3934dc38d31f82bbf9b33975dfecb3a0d8 /server-beta/src/core/hover | |
parent | c354b5e8bd05ba117857ac93e8d647980875d98d (diff) | |
download | lua-language-server-bafe0e44914ad3b669388b94b91d9992edeb8e07.zip |
hover的第一步
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 |