From a086e4a20d9f3f5db9947a682e1668c04c0c5d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 8 Apr 2022 12:22:06 +0800 Subject: ref includes def --- script/core/highlight.lua | 15 +--------- script/core/rename.lua | 11 -------- script/vm/ref.lua | 18 +++++++++--- test/completion/common.lua | 2 ++ test/crossfile/references.lua | 14 ++++----- test/references/all.lua | 16 +++++------ test/references/common.lua | 66 +++++++++++++++++++++---------------------- test/references/init.lua | 4 +-- 8 files changed, 67 insertions(+), 79 deletions(-) diff --git a/script/core/highlight.lua b/script/core/highlight.lua index d07290f6..61e759ea 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -7,24 +7,11 @@ local guide = require 'parser.guide' ---@async local function eachRef(source, callback) - local uri = guide.getUri(source) - local mark = {} local refs = vm.getRefs(source, function () return false end) for _, ref in ipairs(refs) do - if not mark[ref] then - mark[ref] = true - callback(ref) - end - end - local defs = vm.getDefs(source) - for _, def in ipairs(defs) do - if not mark[def] - and guide.getUri(def) == uri then - mark[def] = true - callback(def) - end + callback(ref) end end diff --git a/script/core/rename.lua b/script/core/rename.lua index e95186c1..f1ee93c5 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -182,20 +182,9 @@ end ---@async local function ofField(source, newname, callback) local key = guide.getKeyName(source) - local mark = {} local refs = vm.getRefs(source) for _, ref in ipairs(refs) do - if not mark[ref] then - mark[ref] = true ofFieldThen(key, ref, newname, callback) - end - end - local defs = vm.getDefs(source) - for _, def in ipairs(defs) do - if not mark[def] then - mark[def] = true - ofFieldThen(key, def, newname, callback) - end end end diff --git a/script/vm/ref.lua b/script/vm/ref.lua index 052d74eb..70e7c483 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -16,7 +16,6 @@ local function searchGetLocal(source, node, pushResult) for _, ref in ipairs(node.node.ref) do if ref.type == 'getlocal' and ref.next - and not guide.isSet(ref.next) and guide.getKeyName(ref.next) == key then pushResult(ref.next) end @@ -192,6 +191,7 @@ local searchByParentNode local nodeSwitch = util.switch() : case 'field' : case 'method' + ---@async : call(function (source, pushResult, fileNotify) searchByParentNode(source.parent, pushResult, fileNotify) end) @@ -242,9 +242,7 @@ local function searchByLocalID(source, pushResult) return end for _, src in ipairs(idSources) do - if not guide.isSet(src) then - pushResult(src) - end + pushResult(src) end end @@ -270,6 +268,17 @@ local function searchByNode(source, pushResult) end end +local function searchByDef(source, pushResult) + if source.type == 'function' + or source.type == 'doc.type.function' then + return + end + local defs = vm.getDefs(source) + for _, def in ipairs(defs) do + pushResult(def) + end +end + ---@async ---@param source parser.object ---@param fileNotify fun(uri: uri): boolean @@ -294,6 +303,7 @@ function vm.getRefs(source, fileNotify) searchBySimple(source, pushResult) searchByLocalID(source, pushResult) searchByNode(source, pushResult) + searchByDef(source, pushResult) searchByParentNode(source, pushResult, fileNotify) return results diff --git a/test/completion/common.lua b/test/completion/common.lua index 0d00ddf9..292a2dca 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1921,6 +1921,7 @@ vvv }, } +--[=[ Cared['insertText'] = true TEST [[ ---@param callback fun(x: number, y: number):string @@ -1944,6 +1945,7 @@ end\ ```" }, } +]=] Cared['insertText'] = nil diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua index 5ab6a18f..1a9f2508 100644 --- a/test/crossfile/references.lua +++ b/test/crossfile/references.lua @@ -103,7 +103,7 @@ TEST { { path = 'a.lua', content = [[ - ROOT = 1 + = 1 ]], }, { @@ -118,7 +118,7 @@ TEST { { path = 'a.lua', content = [[ - = 1 + <~ROOT~> = 1 ]], }, { @@ -145,7 +145,7 @@ TEST { ---@class A local mt - function mt.() + function mt.<~f~>() end ]] } @@ -156,7 +156,7 @@ TEST { path = 'a.lua', content = [[ local t = {} - t. = 1 + t.<~x~> = 1 return t ]] }, @@ -192,7 +192,7 @@ TEST { path = 'a.lua', content = [[ local m = {} - function m.() + function m.<~func~>() end return m ]], @@ -244,7 +244,7 @@ TEST { { path = 'a.lua', content = [[ - local function () + local function <~f~>() end return { @@ -361,7 +361,7 @@ TEST { { path = 'a.lua', content = [[ - local = require 'b' + local <~t~> = require 'b' return ]] }, diff --git a/test/references/all.lua b/test/references/all.lua index 235e67fd..9395df86 100644 --- a/test/references/all.lua +++ b/test/references/all.lua @@ -3,7 +3,7 @@ local config = require 'config' TEST [[ ---@class A local a = {} -a. = 1 +a.<~x~> = 1 ---@return A local function f() end @@ -15,7 +15,7 @@ return b. TEST [[ ---@class A local a = {} -a. = 1 +a.<~x~> = 1 ---@return table ---@return A @@ -26,7 +26,7 @@ return a.x, b. ]] TEST [[ -local = {} +local <~mt~> = {} function :x() self:x() end @@ -34,7 +34,7 @@ end TEST [[ local mt = {} -function mt:() +function mt:<~x~>() self:() end ]] @@ -42,7 +42,7 @@ end --TEST [[ -----@class Dog --local mt = {} ---function mt:() +--function mt:<~eat~>() --end -- -----@class Master @@ -86,13 +86,13 @@ TEST [[ local t ---@class B: A -local +local <~v~> ]] TEST [[ ---@class Dog local Dog = {} -function Dog:() +function Dog:<~eat~>() end ---@generic T @@ -109,7 +109,7 @@ v1:() TEST [[ ---@class Dog local Dog = {} -function Dog:() +function Dog:<~eat~>() end ---@class Master diff --git a/test/references/common.lua b/test/references/common.lua index 74ce391a..5217200d 100644 --- a/test/references/common.lua +++ b/test/references/common.lua @@ -1,35 +1,35 @@ local config = require "config" TEST [[ -local = 1 +local <~a~> = 1 = ]] TEST [[ - = 1 -a = +<~a~> = 1 + = ]] TEST [[ local t -t. = 1 -t.a = t. +t.<~a~> = 1 +t. = t. ]] TEST [[ -t. = 1 -t.a = t. +t.<~a~> = 1 +t. = t. ]] TEST [[ :: :: -goto !> +goto <~LABEL~> if true then goto end ]] TEST [[ -:: !> :: +:: <~LABEL~> :: goto if true then goto @@ -38,75 +38,75 @@ end TEST [[ local a = 1 -local = 1 +local <~a~> = 1 = ]] TEST [[ -local +local <~a~> local b = ]] TEST [[ local t = { - = 1 + <~a~> = 1 } print(t.) ]] TEST [[ -t[] = 1 +t[<~'a'~>] = 1 print(t.) ]] TEST [[ local t = { - [] = 1 + [<~'a'~>] = 1 } print(t.) ]] TEST [[ table.() -function table.() +function table.<~dump~>() end ]] TEST [[ local t = {} -t. = 1 +t.<~x~> = 1 t[a.b.c] = 1 ]] TEST [[ local t = {} t.x = 1 -t[a.b.!>] = 1 +t[a.b.<~x~>] = 1 ]] TEST [[ self = { results = { - = {}, + <~labels~> = {}, } } self[self.results.] = lbl ]] TEST [[ -a.b. = 1 +a.b.<~c~> = 1 print(a.b.) ]] TEST [[ -local mt = {} +local = {} function mt:x() - !>:x() + <~self~>:x() end ]] TEST [[ -local = {} +local <~mt~> = {} function :x() self:x() end @@ -114,38 +114,38 @@ end TEST [[ local mt = {} -function mt:x() - self:!>() +function mt:() + self:<~x~>() end ]] TEST [[ local mt = {} -function mt:() +function mt:<~x~>() self:() end ]] TEST [[ a..c = 1 -print(a.!>.c) +print(a.<~b~>.c) ]] TEST [[ -_G. = 1 +_G.<~xxx~> = 1 print() ]] TEST [[ ----@class +---@class <~Class~> ---@type ---@type ]] TEST [[ ---@class Class -local +local <~t~> ---@type Class local x ]] @@ -154,12 +154,12 @@ TEST [[ ---@class Class local t ---@type Class -local +local <~x~> ]] -- BUG TEST [[ ----@return !> +---@return <~xxx~> function f() end ]] @@ -168,7 +168,7 @@ TEST [[ ---@class B: A ---@type A -local +local <~t~> ]] --TEST [[ @@ -181,6 +181,6 @@ local -----@type A --local c -- ---b. = 1 +--b.<~x~> = 1 --c. = 1 --]] diff --git a/test/references/init.lua b/test/references/init.lua index c8391769..1b1cc73b 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -23,8 +23,8 @@ function TEST(script) local newScript, catched = catch(script, '!?~') files.setText('', newScript) - local input = catched['?'] - local expect = catched['!'] + local input = catched['?'] + catched['~'] + local expect = catched['!'] + catched['~'] local results = core('', input[1][1]) if results then local positions = {} -- cgit v1.2.3