diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 23:26:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 23:26:32 +0800 |
commit | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (patch) | |
tree | bb34518d70b85de7656dbdbe958dfa221a3ff3b3 /script-beta/src/core/hover/name.lua | |
parent | 0a2c2ad15e1ec359171fb0dd4c72e57c5b66e9ba (diff) | |
download | lua-language-server-d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a.zip |
整理一下目录结构
Diffstat (limited to 'script-beta/src/core/hover/name.lua')
-rw-r--r-- | script-beta/src/core/hover/name.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/script-beta/src/core/hover/name.lua b/script-beta/src/core/hover/name.lua new file mode 100644 index 00000000..a22a8b5a --- /dev/null +++ b/script-beta/src/core/hover/name.lua @@ -0,0 +1,64 @@ +local guide = require 'parser.guide' +local vm = require 'vm' + +local function asLocal(source) + return guide.getName(source) +end + +local function asMethod(source) + local class = vm.eachField(source.node, function (info) + if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then + if info.value and info.value.type == 'string' then + return info.value[1] + end + end + end) + local node = class or guide.getName(source.node) or '?' + local method = guide.getName(source) + return ('%s:%s'):format(node, method) +end + +local function asField(source) + local class = vm.eachField(source.node, function (info) + if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then + if info.value and info.value.type == 'string' then + return info.value[1] + end + end + end) + local node = class or guide.getName(source.node) or '?' + local method = guide.getName(source) + return ('%s.%s'):format(node, method) +end + +local function asGlobal(source) + return guide.getName(source) +end + +local function buildName(source) + if source.type == 'local' + or source.type == 'getlocal' + or source.type == 'setlocal' then + return asLocal(source) or '' + end + if source.type == 'setglobal' + or source.type == 'getglobal' then + return asGlobal(source) or '' + end + if source.type == 'setmethod' + or source.type == 'getmethod' then + return asMethod(source) or '' + end + if source.type == 'setfield' + or source.tyoe == 'getfield' + or source.type == 'tablefield' then + return asField(source) or '' + end + local parent = source.parent + if parent then + return buildName(parent) + end + return '' +end + +return buildName |