diff options
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/definition.lua | 2 | ||||
-rw-r--r-- | server-beta/src/searcher/eachDef.lua | 65 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 1 | ||||
-rw-r--r-- | server-beta/test/crossfile/definition.lua | 2 |
4 files changed, 68 insertions, 2 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua index 3fa7c3bf..a7008926 100644 --- a/server-beta/src/core/definition.lua +++ b/server-beta/src/core/definition.lua @@ -17,7 +17,7 @@ local function findDef(source, callback) and source.type ~= 'goto' then return end - searcher.eachRef(source, function (info) + searcher.eachDef(source, function (info) if info.mode == 'declare' or info.mode == 'set' or info.mode == 'return' then diff --git a/server-beta/src/searcher/eachDef.lua b/server-beta/src/searcher/eachDef.lua new file mode 100644 index 00000000..bc9f9e1c --- /dev/null +++ b/server-beta/src/searcher/eachDef.lua @@ -0,0 +1,65 @@ +local searcher = require 'searcher.searcher' +local guide = require 'parser.guide' +local files = require 'files' + +local function checkPath(source, info) + if source.type == 'goto' then + return true + end + local src = info.source + local mode = guide.getPath(source, src) + if not mode then + return true + end + if mode == 'before' then + return false + end + return true +end + +function searcher.eachDef(source, callback) + local results = {} + local valueUris = {} + local sourceUri = guide.getRoot(source).uri + searcher.eachRef(source, function (info) + if info.mode == 'declare' + or info.mode == 'set' + or info.mode == 'return' + or info.mode == 'value' then + results[#results+1] = info + local src = info.source + if info.mode == 'return' then + local uri = guide.getRoot(src).uri + valueUris[uri] = info.source + end + end + end) + + for _, info in ipairs(results) do + local src = info.source + local destUri = guide.getRoot(src).uri + -- 如果是同一个文件,则检查位置关系后放行 + if sourceUri == destUri then + if checkPath(source, info) then + callback(info) + end + goto CONTINUE + end + -- 如果是global或field,则直接放行(因为无法确定顺序) + if src.type == 'setindex' + or src.type == 'setfield' + or src.type == 'setmethod' + or src.type == 'tablefield' + or src.type == 'tableindex' + or src.type == 'setglobal' then + callback(info) + goto CONTINUE + end + -- 如果不是同一个文件,则必须在该文件 return 后才放行 + if valueUris[destUri] then + callback(info) + goto CONTINUE + end + ::CONTINUE:: + end +end diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index a43c8d96..a0e61999 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -1,6 +1,7 @@ local searcher = require 'searcher.searcher' require 'searcher.eachField' require 'searcher.eachRef' +require 'searcher.eachDef' require 'searcher.getGlobals' require 'searcher.getLinks' require 'searcher.isGlobal' diff --git a/server-beta/test/crossfile/definition.lua b/server-beta/test/crossfile/definition.lua index 9e26a60f..7cf12c74 100644 --- a/server-beta/test/crossfile/definition.lua +++ b/server-beta/test/crossfile/definition.lua @@ -396,7 +396,7 @@ TEST { { path = 'a.lua', content = [[ - local <!x!> + local x return { <!x!> = x, } |