diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-24 21:58:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-24 21:58:16 +0800 |
commit | 5e9f40d4666055c5998df0c3137db83127f5623b (patch) | |
tree | bb448f1fd7f2ef811d12cd0b99699818a4392986 /server-beta | |
parent | c025849321b444b84eacd4e091cfa574ca6bc472 (diff) | |
download | lua-language-server-5e9f40d4666055c5998df0c3137db83127f5623b.zip |
更新 definition
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/definition.lua | 20 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 24 | ||||
-rw-r--r-- | server-beta/test/definition/set.lua | 2 |
3 files changed, 36 insertions, 10 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua index 6f6689b4..fd01072e 100644 --- a/server-beta/src/core/definition.lua +++ b/server-beta/src/core/definition.lua @@ -37,22 +37,24 @@ function m.aslocal(state, ast, source) end end -function m.assetglobal(state, ast, source) +function m.globals(state, ast, source) local name = source[1] - guide.eachSourceOf(ast.root, 'setglobal', function (src) - if src[1] == name then + guide.eachGloabl(ast.root, function (src, gname) + if name ~= gname then + return + end + if src.type == 'setglobal' or src.type == 'setfield' then state.callback(src, ast.uri) end end) end +function m.assetglobal(state, ast, source) + m.globals(state, ast, source) +end + function m.asgetglobal(state, ast, source) - local name = source[1] - guide.eachSourceOf(ast.root, 'setglobal', function (src) - if src[1] == name then - state.callback(src, ast.uri) - end - end) + m.globals(state, ast, source) end return function (ast, text, offset) diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index bd7f9150..e6be631d 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -215,6 +215,30 @@ function m.eachSourceOf(root, types, callback) end end +--- 遍历全局变量 +function m.eachGloabl(root, callback) + m.eachSourceOf(root, {'setglobal', 'getglobal', 'setfield', 'getfield'}, function (src) + if src.type == 'setglobal' or src.type == 'getglobal' then + callback(src, src[1]) + elseif src.type == 'setfield' or src.type == 'getfield' then + local node = root[src.node] + if m.isGlobal(root, node) then + callback(src, src.field[1]) + end + end + end) +end + +--- 判断全局变量 +function m.isGlobal(root, obj) + if obj.type == 'getglobal' then + if obj[1] == '_G' or obj[1] == '_ENV' then + return true + end + end + return false +end + --- 获取偏移对应的坐标(row从0开始,col为光标位置) ---@param lines table ---@return integer {name = 'row'} diff --git a/server-beta/test/definition/set.lua b/server-beta/test/definition/set.lua index 44277d33..ec582d38 100644 --- a/server-beta/test/definition/set.lua +++ b/server-beta/test/definition/set.lua @@ -40,7 +40,7 @@ print(<?x?>) ]] TEST [[ -_G.<!x!> = 1 +<!_G.x!> = 1 print(<?x?>) ]] |