diff options
-rw-r--r-- | script-beta/parser/guide.lua | 75 | ||||
-rw-r--r-- | test-beta/references/init.lua | 12 |
2 files changed, 60 insertions, 27 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index d9dab5ed..2592955a 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -464,6 +464,17 @@ function m.lineRange(lines, row) return line.start, line.finish end +function m.getNameOfLiteral(obj) + if not obj then + return nil + end + local tp = obj.type + if tp == 'string' then + return obj[1] + end + return nil +end + function m.getName(obj) local tp = obj.type if tp == 'getglobal' @@ -483,41 +494,22 @@ function m.getName(obj) elseif tp == 'getindex' or tp == 'setindex' or tp == 'tableindex' then - return m.getName(obj.index) + return m.getNameOfLiteral(obj.index) elseif tp == 'field' or tp == 'method' then return obj[1] elseif tp == 'index' then - return m.getName(obj.index) - elseif tp == 'string' then - return obj[1] + return m.getNameOfLiteral(obj.index) end - return nil + return m.getNameOfLiteral(obj) end -function m.getKeyName(obj) +function m.getKeyNameOfLiteral(obj) + if not obj then + return nil + end local tp = obj.type - if tp == 'getglobal' - or tp == 'setglobal' then - return 's|' .. obj[1] - elseif tp == 'getfield' - or tp == 'setfield' - or tp == 'tablefield' then - if obj.field then - return 's|' .. obj.field[1] - end - elseif tp == 'getmethod' - or tp == 'setmethod' then - if obj.method then - return 's|' .. obj.method[1] - end - elseif tp == 'getindex' - or tp == 'setindex' - or tp == 'tableindex' then - if obj.index then - return m.getKeyName(obj.index) - end - elseif tp == 'field' + if tp == 'field' or tp == 'method' then return 's|' .. obj[1] elseif tp == 'string' then @@ -545,6 +537,35 @@ function m.getKeyName(obj) return nil end +function m.getKeyName(obj) + local tp = obj.type + if tp == 'getglobal' + or tp == 'setglobal' then + return 's|' .. obj[1] + elseif tp == 'getfield' + or tp == 'setfield' + or tp == 'tablefield' then + if obj.field then + return 's|' .. obj.field[1] + end + elseif tp == 'getmethod' + or tp == 'setmethod' then + if obj.method then + return 's|' .. obj.method[1] + end + elseif tp == 'getindex' + or tp == 'setindex' + or tp == 'tableindex' then + return m.getKeyNameOfLiteral(obj.index) + elseif tp == 'index' then + return m.getKeyNameOfLiteral(obj.index) + elseif tp == 'field' + or tp == 'method' then + return 's|' .. obj[1] + end + return m.getKeyNameOfLiteral(obj) +end + function m.getENV(ast) if ast.type ~= 'main' then return nil diff --git a/test-beta/references/init.lua b/test-beta/references/init.lua index 4a122b7a..3cbb5ed8 100644 --- a/test-beta/references/init.lua +++ b/test-beta/references/init.lua @@ -192,6 +192,18 @@ local t = init() t:<?add?>() ]] +TEST [[ +local t = {} +t.<?x?> = 1 +t[a.b.x] = 1 +]] + +TEST [[ +local t = {} +t.x = 1 +t[a.b.<?x?>] = 1 +]] + --TEST [[ -----@class <!Class!> -----@type <?Class?> |