summaryrefslogtreecommitdiff
path: root/script/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-05-19 14:41:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-05-19 14:41:18 +0800
commitb2e8f04b3509caf5df2f41fa0858ef92df3700fc (patch)
tree219f5d3223cd18e8ce11aa45f7539f4eebe07075 /script/parser
parent81a3ad79e4f057d5670689e27823acf8391ce621 (diff)
downloadlua-language-server-b2e8f04b3509caf5df2f41fa0858ef92df3700fc.zip
update
Diffstat (limited to 'script/parser')
-rw-r--r--script/parser/guide.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 5de14856..f87bbbaa 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -723,4 +723,73 @@ function m.getSpecial(source)
return source.special
end
+function m.getKeyNameOfLiteral(obj)
+ if not obj then
+ return nil
+ end
+ local tp = obj.type
+ if tp == 'field'
+ or tp == 'method' then
+ return obj[1]
+ elseif tp == 'string' then
+ local s = obj[1]
+ if s then
+ return s
+ end
+ elseif tp == 'number' then
+ local n = obj[1]
+ if n then
+ return ('%s'):format(util.viewLiteral(obj[1]))
+ end
+ elseif tp == 'boolean' then
+ local b = obj[1]
+ if b then
+ return tostring(b)
+ end
+ end
+end
+
+function m.getKeyName(obj)
+ if not obj then
+ return nil
+ end
+ local tp = obj.type
+ if tp == 'getglobal'
+ or tp == 'setglobal' then
+ return obj[1]
+ elseif tp == 'local'
+ or tp == 'getlocal'
+ or tp == 'setlocal' then
+ return obj[1]
+ elseif tp == 'getfield'
+ or tp == 'setfield'
+ or tp == 'tablefield' then
+ if obj.field then
+ return obj.field[1]
+ end
+ elseif tp == 'getmethod'
+ or tp == 'setmethod' then
+ if obj.method then
+ return obj.method[1]
+ end
+ elseif tp == 'getindex'
+ or tp == 'setindex'
+ or tp == 'tableindex' then
+ return m.getKeyNameOfLiteral(obj.index)
+ elseif tp == 'field'
+ or tp == 'method'
+ or tp == 'doc.see.field' then
+ return obj[1]
+ elseif tp == 'doc.class' then
+ return obj.class[1]
+ elseif tp == 'doc.alias' then
+ return obj.alias[1]
+ elseif tp == 'doc.field' then
+ return obj.field[1]
+ elseif tp == 'dummy' then
+ return obj[1]
+ end
+ return m.getKeyNameOfLiteral(obj)
+end
+
return m