summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-13 13:40:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-13 13:40:18 +0800
commit836a666b12b463843826719f06243a92e18bf314 (patch)
tree7982688e1fdc499f2624cb7a7f0c58481cd013bb
parent9db050598e3df70063fb697dbe19cdb90295c1e1 (diff)
downloadlua-language-server-836a666b12b463843826719f06243a92e18bf314.zip
暂存
-rw-r--r--main-beta.lua4
-rw-r--r--script-beta/files.lua3
-rw-r--r--script-beta/vm/eachDef.lua51
-rw-r--r--test-beta.lua2
-rw-r--r--test-beta/crossfile/definition.lua40
-rw-r--r--test-beta/crossfile/references.lua40
-rw-r--r--test-beta/full/example.lua2
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 <!f!>()
+ end
+
+ return {
+ <!f!> = 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 <!f!> = t.f
+
+ <?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 <!f!>()
+ end
+
+ return {
+ <!f!> = <!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 <!f!> = t.<!f!>
+
+ <?f?>()
+
+ return {
+ <!f!> = <!f!>,
+ }
+ ]]
+ }
+}
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