diff options
-rw-r--r-- | script/core/definition.lua | 1 | ||||
-rw-r--r-- | script/core/reference.lua | 4 | ||||
-rw-r--r-- | script/vm/compiler.lua | 4 | ||||
-rw-r--r-- | script/vm/def.lua | 4 | ||||
-rw-r--r-- | script/vm/ref.lua | 21 | ||||
-rw-r--r-- | test/references/common.lua | 15 |
6 files changed, 48 insertions, 1 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua index 866e8f84..1a886a91 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -56,6 +56,7 @@ local accept = { ['doc.see.field'] = true, ['doc.cast.name'] = true, ['doc.enum.name'] = true, + ['doc.field.name'] = true, } local function checkRequire(source, offset) diff --git a/script/core/reference.lua b/script/core/reference.lua index fa838cff..c1d99ed9 100644 --- a/script/core/reference.lua +++ b/script/core/reference.lua @@ -51,6 +51,7 @@ local accept = { ['doc.extends.name'] = true, ['doc.alias.name'] = true, ['doc.enum.name'] = true, + ['doc.field.name'] = true, } ---@async @@ -115,7 +116,8 @@ return function (uri, position) and source.type ~= 'doc.class.name' and source.type ~= 'doc.enum.name' and source.type ~= 'doc.extends.name' - and source.type ~= 'doc.see.name' then + and source.type ~= 'doc.see.name' + and source.type ~= 'doc.alias.name' then goto CONTINUE end end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 69cfdc55..a38329f8 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1610,6 +1610,10 @@ local compilerSwitch = util.switch() end vm.setNode(source, fieldNode) end) + : case 'doc.field.name' + : call(function (source) + vm.setNode(source, vm.compileNode(source.parent)) + end) : case 'doc.type.field' : call(function (source) if not source.extends then diff --git a/script/vm/def.lua b/script/vm/def.lua index 7ce8ad7a..b1bedc43 100644 --- a/script/vm/def.lua +++ b/script/vm/def.lua @@ -19,6 +19,10 @@ simpleSwitch = util.switch() pushResult(loc) end end) + : case 'doc.field' + : call(function (source, pushResult) + pushResult(source) + end) ---@param source parser.object ---@param pushResult fun(src: parser.object) diff --git a/script/vm/ref.lua b/script/vm/ref.lua index 0135d11f..247fb4db 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -26,6 +26,19 @@ simpleSwitch = util.switch() end end end) + : case 'doc.alias.name' + : call(function (source, pushResult) + local global = vm.getGlobal('type', source[1]) + if not global then + return + end + for _, get in ipairs(global:getGets(guide.getUri(source))) do + pushResult(get) + end + for _, set in ipairs(global:getSets(guide.getUri(source))) do + pushResult(set) + end + end) ---@async local function searchInAllFiles(suri, searcher, notify) @@ -173,6 +186,11 @@ local nodeSwitch = util.switch() : call(function (source, pushResult, defMap, fileNotify) searchField(source, pushResult, defMap, fileNotify) end) + : case 'doc.field.name' + ---@async + : call(function (source, pushResult, defMap, fileNotify) + searchField(source, pushResult, defMap, fileNotify) + end) : case 'function' : case 'doc.type.function' ---@async @@ -237,6 +255,9 @@ local function searchByDef(source, pushResult) or source.type == 'method' then source = source.parent end + if source.type == 'doc.field.name' then + source = source.parent + end defMap[source] = true if guide.isSet(source) then local defs = vm.getDefs(source) diff --git a/test/references/common.lua b/test/references/common.lua index c20b32ed..7f7e91a6 100644 --- a/test/references/common.lua +++ b/test/references/common.lua @@ -201,3 +201,18 @@ local b = { } a.color = { 1, 1, 1 } b.<~color~> = a.color ]] + +TEST [[ +---@alias <~A~> number + +---@type <!A!> +]] + +TEST [[ +---@class A +---@field <~x~> number + +---@type A +local t +print(t.<!x!>) +]] |