diff options
Diffstat (limited to 'server-beta/src/core')
-rw-r--r-- | server-beta/src/core/hover/label.lua | 57 | ||||
-rw-r--r-- | server-beta/src/core/hover/name.lua | 15 |
2 files changed, 70 insertions, 2 deletions
diff --git a/server-beta/src/core/hover/label.lua b/server-beta/src/core/hover/label.lua index 759938d2..d90a19b0 100644 --- a/server-beta/src/core/hover/label.lua +++ b/server-beta/src/core/hover/label.lua @@ -25,6 +25,52 @@ local function asLocal(source) end end +local function asGlobal(source) + local name = buildName(source) + local type = vm.getType(source) + local literal = vm.getLiteral(source) + if literal == nil then + return ('global %s: %s'):format(name, type) + else + return ('global %s: %s = %s'):format(name, type, util.viewLiteral(literal)) + end +end + +local function isGlobalField(source) + if source.type == 'field' + or source.type == 'method' then + source = source.parent + end + if source.type == 'setfield' + or source.type == 'getfield' + or source.type == 'setmethod' + or source.type == 'getmethod' + or source.type == 'tablefield' then + local node = source.node + if node.type == 'setglobal' + or node.type == 'getglobal' then + return true + end + return isGlobalField(node) + else + return false + end +end + +local function asField(source) + if isGlobalField(source) then + return asGlobal(source) + end + local name = buildName(source) + local type = vm.getType(source) + local literal = vm.getLiteral(source) + if literal == nil then + return ('field %s: %s'):format(name, type) + else + return ('field %s: %s = %s'):format(name, type, util.viewLiteral(literal)) + end +end + return function (source) if source.type == 'function' then return asFunction(source) @@ -32,5 +78,16 @@ return function (source) or source.type == 'getlocal' or source.type == 'setlocal' then return asLocal(source) + elseif source.type == 'setglobal' + or source.type == 'getglobal' then + return asGlobal(source) + elseif source.type == 'getfield' + or source.type == 'setfield' + or source.type == 'getmethod' + or source.type == 'setmethod' + or source.type == 'tablefield' + or source.type == 'field' + or source.type == 'method' then + return asField(source) end end diff --git a/server-beta/src/core/hover/name.lua b/server-beta/src/core/hover/name.lua index 9eb066fc..468691a7 100644 --- a/server-beta/src/core/hover/name.lua +++ b/server-beta/src/core/hover/name.lua @@ -31,16 +31,27 @@ local function asField(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 == 'setmethod' then + 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' then + if source.type == 'setfield' + or source.tyoe == 'getfield' + or source.type == 'tablefield' then return asField(source) or '' end local parent = source.parent |