summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/definition.lua7
-rw-r--r--script-beta/core/reference.lua7
-rw-r--r--script-beta/core/rename.lua4
-rw-r--r--script-beta/parser/guide.lua11
-rw-r--r--script-beta/vm/eachDef.lua2
-rw-r--r--script-beta/vm/eachRef.lua2
-rw-r--r--script-beta/vm/getInfer.lua2
-rw-r--r--script-beta/vm/guideInterface.lua4
8 files changed, 24 insertions, 15 deletions
diff --git a/script-beta/core/definition.lua b/script-beta/core/definition.lua
index ae6dce4a..8e76bfab 100644
--- a/script-beta/core/definition.lua
+++ b/script-beta/core/definition.lua
@@ -7,8 +7,8 @@ local findSource = require 'core.find-source'
local function sortResults(results)
-- 先按照顺序排序
table.sort(results, function (a, b)
- local u1 = guide.getRoot(a.target).uri
- local u2 = guide.getRoot(b.target).uri
+ local u1 = guide.getUri(a.target)
+ local u2 = guide.getUri(b.target)
if u1 == u2 then
return a.target.start < b.target.start
else
@@ -20,8 +20,7 @@ local function sortResults(results)
for i = #results, 1, -1 do
local res = results[i].target
local f = res.finish
- local root = guide.getRoot(res)
- local uri = root and root.uri
+ local uri = guide.getUri(res)
if lf and f > lf and uri == lu then
table.remove(results, i)
else
diff --git a/script-beta/core/reference.lua b/script-beta/core/reference.lua
index 025af99b..56580d0b 100644
--- a/script-beta/core/reference.lua
+++ b/script-beta/core/reference.lua
@@ -11,8 +11,8 @@ end
local function sortResults(results)
-- 先按照顺序排序
table.sort(results, function (a, b)
- local u1 = guide.getRoot(a.target).uri
- local u2 = guide.getRoot(b.target).uri
+ local u1 = guide.getUri(a.target)
+ local u2 = guide.getUri(b.target)
if u1 == u2 then
return a.target.start < b.target.start
else
@@ -24,8 +24,7 @@ local function sortResults(results)
for i = #results, 1, -1 do
local res = results[i].target
local f = res.finish
- local root = guide.getRoot(res)
- local uri = root and root.uri
+ local uri = guide.getUri(res)
if lf and f > lf and uri == lu then
table.remove(results, i)
else
diff --git a/script-beta/core/rename.lua b/script-beta/core/rename.lua
index 23929858..2de21bac 100644
--- a/script-beta/core/rename.lua
+++ b/script-beta/core/rename.lua
@@ -174,7 +174,7 @@ local function renameField(source, newname, callback)
end
callback(source, source.start, source.finish, newname)
elseif parent.type == 'setmethod' then
- local uri = guide.getRoot(source).uri
+ local uri = guide.getUri(source)
local text = files.getText(uri)
local func = parent.value
-- function mt:name () end --> mt['newname'] = function (self) end
@@ -377,7 +377,7 @@ function m.rename(uri, pos, newname)
start = start,
finish = finish,
text = text,
- uri = guide.getRoot(target).uri,
+ uri = guide.getUri(target),
}
end)
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 1e548b9d..e6c65888 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -207,6 +207,17 @@ function m.getRoot(obj)
error('guide.getRoot overstack')
end
+function m.getUri(obj)
+ if obj.uri then
+ return obj.uri
+ end
+ local root = m.getRoot(obj)
+ if root then
+ return root.uri
+ end
+ return ''
+end
+
--- 寻找函数的不定参数,返回不定参在第几个参数上,以及该参数对象。
--- 如果函数是主函数,则返回`0, nil`。
---@return table
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index e251cda5..e1d964ee 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -18,7 +18,7 @@ function m.eachDef(source, results)
local clock = os.clock()
local myResults, count = guide.requestDefinition(source, vm.interface)
if DEVELOP and os.clock() - clock > 0.1 then
- log.warn('requestDefinition', count, os.clock() - clock, guide.getRoot(source).uri, util.dump(source, { deep = 1 }))
+ log.warn('requestDefinition', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
end
vm.mergeResults(results, myResults)
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 616dccdd..35321d24 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -15,7 +15,7 @@ local function getRefs(source, results)
local clock = os.clock()
local myResults, count = guide.requestReference(source, vm.interface)
if DEVELOP and os.clock() - clock > 0.1 then
- log.warn('requestReference', count, os.clock() - clock, guide.getRoot(source).uri, util.dump(source, { deep = 1 }))
+ log.warn('requestReference', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
end
vm.mergeResults(results, myResults)
diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua
index 077ec982..9e48e432 100644
--- a/script-beta/vm/getInfer.lua
+++ b/script-beta/vm/getInfer.lua
@@ -61,7 +61,7 @@ function vm.getInfers(source)
local clock = os.clock()
local infers = guide.requestInfer(source, vm.interface)
if os.clock() - clock > 0.1 then
- log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getRoot(source).uri, util.dump(source, { deep = 1 })))
+ log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })))
end
return infers
end
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
index 2bca395b..c8658b42 100644
--- a/script-beta/vm/guideInterface.lua
+++ b/script-beta/vm/guideInterface.lua
@@ -26,7 +26,7 @@ function m.require(args, index)
return nil
end
local results = {}
- local myUri = guide.getRoot(args[1]).uri
+ local myUri = guide.getUri(args[1])
local uris = ws.findUrisByRequirePath(reqName, true)
for _, uri in ipairs(uris) do
if not files.eq(myUri, uri) then
@@ -49,7 +49,7 @@ function m.dofile(args, index)
return
end
local results = {}
- local myUri = guide.getRoot(args[1]).uri
+ local myUri = guide.getUri(args[1])
local uris = ws.findUrisByFilePath(reqName, true)
for _, uri in ipairs(uris) do
if not files.eq(myUri, uri) then