diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-29 17:47:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-29 17:47:55 +0800 |
commit | e02e98690dec2fd355a5a59af6b87cb2d94ed8b1 (patch) | |
tree | d6113e2035d039dafebd531251fd8a14d9e0a57a /server-beta/src/parser | |
parent | 8b37f59c00f7c56e5da89d9fdcf7b98710e59fbd (diff) | |
download | lua-language-server-e02e98690dec2fd355a5a59af6b87cb2d94ed8b1.zip |
暂存
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r-- | server-beta/src/parser/compile.lua | 6 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 51 |
2 files changed, 56 insertions, 1 deletions
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua index 90b3f269..fe4198f0 100644 --- a/server-beta/src/parser/compile.lua +++ b/server-beta/src/parser/compile.lua @@ -43,7 +43,11 @@ local function getValue(obj) if vref then return vref end - addValue(obj, {}) + if guide.isLiteral(obj) then + addValue(obj, obj) + else + addValue(obj, {}) + end return obj.vref end diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 69b49f85..fdd29be7 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -1,5 +1,6 @@ local error = error local type = type +local next = next _ENV = nil @@ -58,6 +59,16 @@ m.childMap = { ['list'] = {'#'}, } +--- 是否是字面量 +function m.isLiteral(obj) + local tp = obj.type + return tp == 'nil' + or tp == 'boolean' + or tp == 'string' + or tp == 'number' + or tp == 'table' +end + --- 寻找所在函数 function m.getParentFunction(obj) for _ = 1, 1000 do @@ -338,6 +349,7 @@ function m.lineRange(lines, row) return line.start + 1, line.finish end +--- 获取对象作为key时的名字 function m.getKeyName(obj) if obj.type == 'getglobal' or obj.type == 'setglobal' then return 'string|' .. obj[1] @@ -346,4 +358,43 @@ function m.getKeyName(obj) end end +--- 获取对象所有field的key与valueObj +function m.eachField(obj, callback) + local vref = obj.vref + if not vref then + return + end + for i = 1, #vref do + local v = vref[i] + local child = v.child + if child then + for fieldName, cvref in next, child do + for j = 1, #cvref do + callback(fieldName, cvref[j]) + end + end + end + end +end + +--- 获取对象所有指定field的key与valueObj +function m.eachFieldOf(obj, field, callback) + local vref = obj.vref + if not vref then + return + end + for i = 1, #vref do + local v = vref[i] + local child = v.child + if child then + local cvref = child[field] + if cvref then + for j = 1, #cvref do + callback(cvref[j]) + end + end + end + end +end + return m |