From 836a666b12b463843826719f06243a92e18bf314 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, 13 Dec 2019 13:40:18 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main-beta.lua | 4 +-- script-beta/files.lua | 3 +++ script-beta/vm/eachDef.lua | 51 ++++++++++++++++++++------------------ test-beta.lua | 2 +- test-beta/crossfile/definition.lua | 40 ++++++++++++++++++++++++++++++ test-beta/crossfile/references.lua | 40 ++++++++++++++++++++++++++++++ test-beta/full/example.lua | 2 ++ 7 files changed, 115 insertions(+), 27 deletions(-) diff --git a/main-beta.lua b/main-beta.lua index 3f55b01d..b87cf6c2 100644 --- a/main-beta.lua +++ b/main-beta.lua @@ -5,8 +5,8 @@ local fs = require 'bee.filesystem' ROOT = fs.path(rootPath) LANG = LANG or 'en-US' ---collectgarbage('generational', 10, 50) -collectgarbage('incremental', 120, 120, 0) +collectgarbage('generational', 10, 50) +--collectgarbage('incremental', 120, 120, 0) log = require 'log' log.init(ROOT, ROOT / 'log' / 'service.log') diff --git a/script-beta/files.lua b/script-beta/files.lua index cfe95aeb..324fb11d 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -177,6 +177,9 @@ function m.getAst(uri) uri = uri:lower() end local file = m.fileMap[uri] + if not file then + return nil + end if #file.text >= config.config.workspace.maxPreload * 1000 then if not m.notifyCache['maxPreload'] then m.notifyCache['maxPreload'] = {} diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index d1cba2ae..89a67369 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -19,25 +19,37 @@ end function vm.eachDef(source, callback) local results = {} - local valueUris = {} - local valueInfos = {} + local returns = {} + local infoMap = {} local sourceUri = guide.getRoot(source).uri vm.eachRef(source, function (info) if info.mode == 'declare' - or info.mode == 'set' - or info.mode == 'return' - or info.mode == 'value' - or info.mode == 'library' then + or info.mode == 'set' then results[#results+1] = info - valueInfos[info.source] = info - local src = info.source - if info.mode == 'return' then - local uri = guide.getRoot(src).uri - valueUris[uri] = info.source + end + if info.mode == 'return' then + results[#results+1] = info + local root = guide.getParentBlock(info.source) + if root.type == 'main' then + returns[root.uri] = info end end + infoMap[info.source] = info end) + local function pushDef(info) + local res = callback(info) + if res ~= nil then + return res + end + local value = info.source.value + local vinfo = infoMap[value] + if vinfo then + res = callback(vinfo) + end + return res + end + local res local used = {} for _, info in ipairs(results) do @@ -48,11 +60,6 @@ function vm.eachDef(source, callback) end used[src] = true destUri = guide.getRoot(src).uri - -- 如果是library,则直接放行 - if src.library then - res = callback(info) - goto CONTINUE - end -- 如果是global或field,则直接放行(因为无法确定顺序) if src.type == 'setindex' or src.type == 'setfield' @@ -60,23 +67,19 @@ function vm.eachDef(source, callback) or src.type == 'tablefield' or src.type == 'tableindex' or src.type == 'setglobal' then - res = callback(info) - if src.value and valueInfos[src.value] then - used[src.value] = true - res = callback(valueInfos[src.value]) - end + res = pushDef(info) goto CONTINUE end -- 如果是同一个文件,则检查位置关系后放行 if sourceUri == destUri then if checkPath(source, info) then - res = callback(info) + res = pushDef(info) end goto CONTINUE end -- 如果不是同一个文件,则必须在该文件 return 后才放行 - if valueUris[destUri] then - res = callback(info) + if returns[destUri] then + res = pushDef(info) goto CONTINUE end ::CONTINUE:: diff --git a/test-beta.lua b/test-beta.lua index ccd5c681..cf9f9ea3 100644 --- a/test-beta.lua +++ b/test-beta.lua @@ -43,7 +43,7 @@ local function main() test 'rename' test 'type_inference' test 'hover' - test 'completion' + --test 'completion' --test 'signature' --test 'document_symbol' test 'crossfile' diff --git a/test-beta/crossfile/definition.lua b/test-beta/crossfile/definition.lua index 7cf12c74..3b2c1f14 100644 --- a/test-beta/crossfile/definition.lua +++ b/test-beta/crossfile/definition.lua @@ -411,6 +411,46 @@ TEST { }, } +TEST { + { + path = 'a.lua', + content = [[ + local function () + end + + return { + = f, + } + ]] + }, + { + path = 'c.lua', + content = [[ + local t = require 'a' + local f = t.f + + f() + + return { + f = f, + } + ]] + }, + { + path = 'b.lua', + content = [[ + local t = require 'a' + local = t.f + + () + + return { + f = f, + } + ]] + } +} + --TEST { -- { -- path = 'a.lua', diff --git a/test-beta/crossfile/references.lua b/test-beta/crossfile/references.lua index a1747dac..67097f3a 100644 --- a/test-beta/crossfile/references.lua +++ b/test-beta/crossfile/references.lua @@ -247,3 +247,43 @@ TEST { ]], }, } + +TEST { + { + path = 'a.lua', + content = [[ + local function () + end + + return { + = , + } + ]] + }, + { + path = 'c.lua', + content = [[ + local t = require 'a' + local = t. + + () + + return { + = , + } + ]] + }, + { + path = 'b.lua', + content = [[ + local t = require 'a' + local = t. + + () + + return { + = , + } + ]] + } +} diff --git a/test-beta/full/example.lua b/test-beta/full/example.lua index 5b096655..86b34776 100644 --- a/test-beta/full/example.lua +++ b/test-beta/full/example.lua @@ -2,9 +2,11 @@ local util = require 'utility' local parser = require 'parser' local files = require 'files' local diag = require 'core.diagnostics' +local config = require 'config' -- 临时 local function testIfExit(path) + config.config.workspace.maxPreload = 1000000000 local buf = util.loadFile(path:string()) if buf then local vm -- cgit v1.2.3