diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-05-29 18:59:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-05-29 18:59:09 +0800 |
commit | 24219a8f0ff74d4bc402e311023ae81672fdc53c (patch) | |
tree | 28860a72a8591f0602db5396373c025d35086e1d /script-beta | |
parent | 56660210803cd9128d52007fe14b0b0f5a726ff5 (diff) | |
download | lua-language-server-24219a8f0ff74d4bc402e311023ae81672fdc53c.zip |
整理 highlight 代码
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/highlight.lua | 105 |
1 files changed, 35 insertions, 70 deletions
diff --git a/script-beta/core/highlight.lua b/script-beta/core/highlight.lua index 5c5f1dc5..e2ed2c43 100644 --- a/script-beta/core/highlight.lua +++ b/script-beta/core/highlight.lua @@ -4,83 +4,30 @@ local vm = require 'vm' local define = require 'proto.define' local findSource = require 'core.find-source' -local function ofLocal(source, callback) - callback(source) - if source.ref then - for _, ref in ipairs(source.ref) do - callback(ref) - end - end -end - -local function ofField(source, uri, callback) - local parent = source.parent - if not parent then - return - end - local myKey = vm.getKeyName(source) - if parent.type == 'tableindex' - or parent.type == 'tablefield' then - local tbl = parent.parent - vm.eachField(tbl, function (src) - if vm.getKeyName(src) ~= myKey then - return - end - local destUri = guide.getRoot(src).uri - if destUri ~= uri then - return - end - callback(src) - end) - else - vm.eachField(parent.node, function (src) - if vm.getKeyName(src) ~= myKey then - return - end - local destUri = guide.getRoot(src).uri - if destUri ~= uri then - return - end - callback(src) - end) - end -end - -local function ofIndex(source, uri, callback) - local parent = source.parent - if not parent then - return +local function eachRef(source, callback) + local results = guide.requestReference(source) + for i = 1, #results do + callback(results[i]) end - if parent.type == 'setindex' - or parent.type == 'getindex' - or parent.type == 'tableindex' then - ofField(source, uri, callback) - end -end - -local function ofLabel(source, callback) - vm.eachRef(source, callback) end local function find(source, uri, callback) - if source.type == 'local' then - ofLocal(source, callback) - elseif source.type == 'getlocal' - or source.type == 'setlocal' then - ofLocal(source.node, callback) - elseif source.type == 'field' - or source.type == 'method' then - ofField(source, uri, callback) + if source.type == 'local' + or source.type == 'getlocal' + or source.type == 'setlocal' + or source.type == 'field' + or source.type == 'method' + or source.type == 'getindex' + or source.type == 'setindex' + or source.type == 'tableindex' + or source.type == 'goto' + or source.type == 'label' then + eachRef(source, callback) elseif source.type == 'string' or source.type == 'boolean' - or source.type == 'number' then - ofIndex(source, uri, callback) - callback(source) - elseif source.type == 'nil' then + or source.type == 'number' + or source.type == 'nil' then callback(source) - elseif source.type == 'goto' - or source.type == 'label' then - ofLabel(source, callback) end end @@ -183,6 +130,24 @@ return function (uri, offset) elseif target.type == 'getindex' then target = target.index kind = define.DocumentHighlightKind.Read + elseif target.type == 'field' then + if target.parent.type == 'getfield' then + kind = define.DocumentHighlightKind.Read + else + kind = define.DocumentHighlightKind.Write + end + elseif target.type == 'method' then + if target.parent.type == 'getmethod' then + kind = define.DocumentHighlightKind.Read + else + kind = define.DocumentHighlightKind.Write + end + elseif target.type == 'index' then + if target.parent.type == 'getindex' then + kind = define.DocumentHighlightKind.Read + else + kind = define.DocumentHighlightKind.Write + end elseif target.type == 'setindex' or target.type == 'tableindex' then target = target.index |