diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-12-08 19:54:23 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-12-08 19:54:23 +0800 |
commit | f3ad9225ae04dae2f9ee295709fc623587b1b4e8 (patch) | |
tree | 5ce55049395ba601ef403bf0a36663762314e0a2 /script | |
parent | d4e35887aba9ed3794d5694a19b976eed5a68269 (diff) | |
download | lua-language-server-f3ad9225ae04dae2f9ee295709fc623587b1b4e8.zip |
cleanup
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/guide.lua | 6 | ||||
-rw-r--r-- | script/vm/global.lua | 5 | ||||
-rw-r--r-- | script/vm/ref.lua | 92 |
3 files changed, 68 insertions, 35 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 206820ef..147e6237 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1009,7 +1009,11 @@ function m.getKeyName(obj) return obj.enum[1] elseif tp == 'doc.field' then return obj.field[1] - elseif tp == 'doc.field.name' then + elseif tp == 'doc.field.name' + or tp == 'doc.type.name' + or tp == 'doc.class.name' + or tp == 'doc.alias.name' + or tp == 'doc.enum.name' then return obj[1] elseif tp == 'doc.type.field' then return m.getKeyName(obj.name) diff --git a/script/vm/global.lua b/script/vm/global.lua index 64bb0e9a..37b54349 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -9,7 +9,6 @@ local vm = require 'vm.vm' ---@class vm.global.link ---@field gets parser.object[] ---@field sets parser.object[] ----@field hasGet boolean? ---@class vm.global ---@field links table<uri, vm.global.link> @@ -35,11 +34,10 @@ end ---@param uri uri ---@param source parser.object function mt:addGet(uri, source) - local link = self.links[uri] if PREVIEW then - link.hasGet = true return end + local link = self.links[uri] if not link.gets then link.gets = {} end @@ -98,7 +96,6 @@ function mt:getAllSets() return cache end ----@async ---@return parser.object[] function mt:getGets(suri) if not self.getsCache then diff --git a/script/vm/ref.lua b/script/vm/ref.lua index e2086c1a..1ed176c9 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -62,8 +62,13 @@ local function searchInAllFiles(suri, searcher, notify) end ---@async -local function searchField(source, pushResult, defMap, fileNotify) +local function searchWord(source, pushResult, defMap, fileNotify) local key = guide.getKeyName(source) + if not key then + return + end + + local global = vm.getGlobalNode(source) ---@param src parser.object local function checkDef(src) @@ -75,42 +80,53 @@ local function searchField(source, pushResult, defMap, fileNotify) end end - local pat = '[:.]%s*' .. key - ---@async local function findWord(uri) local text = files.getText(uri) if not text then return end - if not text:match(pat) then + if not text:match(key) then return end local state = files.getState(uri) if not state then return end - ---@async - guide.eachSourceTypes(state.ast, {'getfield', 'setfield'}, function (src) - if src.field and src.field[1] == key then - checkDef(src) - await.delay() - end - end) - ---@async - guide.eachSourceTypes(state.ast, {'getmethod', 'setmethod'}, function (src) - if src.method and src.method[1] == key then - checkDef(src) - await.delay() - end - end) - ---@async - guide.eachSourceTypes(state.ast, {'getindex', 'setindex'}, function (src) - if src.index and src.index.type == 'string' and src.index[1] == key then - checkDef(src) - await.delay() - end - end) + + if global then + local globalName = global:asKeyName() + ---@async + guide.eachSourceTypes(state.ast, {'getglobal', 'setglobal', 'setfield', 'getfield', 'setmethod', 'getmethod', 'setindex', 'getindex', 'doc.type.name', 'doc.class.name', 'doc.alias.name'}, function (src) + local myGlobal = vm.getGlobalNode(src) + if myGlobal and myGlobal:asKeyName() == globalName then + pushResult(src) + await.delay() + end + end) + else + ---@async + guide.eachSourceTypes(state.ast, {'getfield', 'setfield'}, function (src) + if src.field and src.field[1] == key then + checkDef(src) + await.delay() + end + end) + ---@async + guide.eachSourceTypes(state.ast, {'getmethod', 'setmethod'}, function (src) + if src.method and src.method[1] == key then + checkDef(src) + await.delay() + end + end) + ---@async + guide.eachSourceTypes(state.ast, {'getindex', 'setindex'}, function (src) + if src.index and src.index.type == 'string' and src.index[1] == key then + checkDef(src) + await.delay() + end + end) + end end searchInAllFiles(guide.getUri(source), findWord, fileNotify) @@ -165,18 +181,35 @@ local nodeSwitch = util.switch() return end - searchField(source, pushResult, defMap, fileNotify) + searchWord(source, pushResult, defMap, fileNotify) end) : case 'tablefield' : case 'tableindex' + : case 'doc.field.name' ---@async : call(function (source, pushResult, defMap, fileNotify) - searchField(source, pushResult, defMap, fileNotify) + searchWord(source, pushResult, defMap, fileNotify) end) - : case 'doc.field.name' + : case 'setglobal' + : case 'getglobal' + ---@async + : call(function (source, pushResult, defMap, fileNotify) + searchWord(source, pushResult, defMap, fileNotify) + end) + : case 'doc.alias.name' + : case 'doc.class.name' + : case 'doc.enum.name' + ---@async + : call(function (source, pushResult, defMap, fileNotify) + searchWord(source.parent, pushResult, defMap, fileNotify) + end) + : case 'doc.alias' + : case 'doc.class' + : case 'doc.enum' + : case 'doc.type.name' ---@async : call(function (source, pushResult, defMap, fileNotify) - searchField(source, pushResult, defMap, fileNotify) + searchWord(source, pushResult, defMap, fileNotify) end) : case 'function' : case 'doc.type.function' @@ -216,7 +249,6 @@ function searchByParentNode(source, pushResult, defMap, fileNotify) nodeSwitch(source.type, source, pushResult, defMap, fileNotify) end ----@async local function searchByGlobal(source, pushResult) if source.type == 'field' or source.type == 'method' |