diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-07 17:23:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-07 17:23:07 +0800 |
commit | 07bdb57b7358bc62630c6cdaaacd68b151aa6d08 (patch) | |
tree | 875d13f9faee60b1de5eeeff31c050e0063de0dc /script | |
parent | ba6cecf5d9f233dbdcfe5b721e9794658f74e056 (diff) | |
download | lua-language-server-07bdb57b7358bc62630c6cdaaacd68b151aa6d08.zip |
#1192 don't search local in simple
use the methods provided by `local-id` to avoid wasting on `gets`
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/def.lua | 65 | ||||
-rw-r--r-- | script/vm/local-id.lua | 1 | ||||
-rw-r--r-- | script/vm/ref.lua | 51 |
3 files changed, 1 insertions, 116 deletions
diff --git a/script/vm/def.lua b/script/vm/def.lua index ad343ae6..accfbb1b 100644 --- a/script/vm/def.lua +++ b/script/vm/def.lua @@ -5,72 +5,7 @@ local guide = require 'parser.guide' local simpleSwitch -local function searchGetLocal(source, node, pushResult) - local key = guide.getKeyName(source) - for _, ref in ipairs(node.node.ref) do - if ref.type == 'getlocal' - and ref.next - and guide.isSet(ref.next) - and guide.getKeyName(ref.next) == key then - pushResult(ref.next) - end - end -end - simpleSwitch = util.switch() - : case 'local' - : call(function (source, pushResult) - pushResult(source) - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - pushResult(ref) - end - end - end - end) - : case 'sellf' - : call(function (source, pushResult) - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - pushResult(ref) - end - end - end - for _, res in ipairs(vm.getDefs(source.method.node)) do - pushResult(res) - end - end) - : case 'getlocal' - : case 'setlocal' - : call(function (source, pushResult) - simpleSwitch('local', source.node, pushResult) - end) - : case 'field' - : call(function (source, pushResult) - local parent = source.parent - if parent.type ~= 'tablefield' then - simpleSwitch(parent.type, parent, pushResult) - end - end) - : case 'setfield' - : case 'getfield' - : call(function (source, pushResult) - local node = source.node - if node.type == 'getlocal' then - searchGetLocal(source, node, pushResult) - return - end - end) - : case 'getindex' - : case 'setindex' - : call(function (source, pushResult) - local node = source.node - if node.type == 'getlocal' then - searchGetLocal(source, node, pushResult) - end - end) : case 'goto' : call(function (source, pushResult) if source.node then diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index bb12a927..e0c8770d 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -21,6 +21,7 @@ local compileSwitch = util.switch() compileLocalID(ref) end end) + : case 'setlocal' : case 'getlocal' : call(function (source) source._localID = ('%d'):format(source.node.start) diff --git a/script/vm/ref.lua b/script/vm/ref.lua index 031a2e69..c97ca5e6 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -9,58 +9,7 @@ local lang = require 'language' local simpleSwitch -local function searchGetLocal(source, node, pushResult) - local key = guide.getKeyName(source) - for _, ref in ipairs(node.node.ref) do - if ref.type == 'getlocal' - and ref.next - and guide.getKeyName(ref.next) == key then - pushResult(ref.next) - end - end -end - simpleSwitch = util.switch() - : case 'local' - : call(function (source, pushResult) - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' - or ref.type == 'getlocal' then - pushResult(ref) - end - end - end - end) - : case 'getlocal' - : case 'setlocal' - : call(function (source, pushResult) - simpleSwitch('local', source.node, pushResult) - end) - : case 'field' - : call(function (source, pushResult) - local parent = source.parent - if parent.type ~= 'tablefield' then - simpleSwitch(parent.type, parent, pushResult) - end - end) - : case 'setfield' - : case 'getfield' - : call(function (source, pushResult) - local node = source.node - if node.type == 'getlocal' then - searchGetLocal(source, node, pushResult) - return - end - end) - : case 'getindex' - : case 'setindex' - : call(function (source, pushResult) - local node = source.node - if node.type == 'getlocal' then - searchGetLocal(source, node, pushResult) - end - end) : case 'goto' : call(function (source, pushResult) if source.node then |