summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/definition.lua2
-rw-r--r--script/core/jump-source.lua33
-rw-r--r--script/core/reference.lua2
-rw-r--r--script/core/type-definition.lua2
4 files changed, 39 insertions, 0 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index e4868532..ac2513e9 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -4,6 +4,7 @@ local vm = require 'vm'
local findSource = require 'core.find-source'
local guide = require 'parser.guide'
local rpath = require 'workspace.require-path'
+local jumpSource = require 'core.jump-source'
local function sortResults(results)
-- 先按照顺序排序
@@ -197,6 +198,7 @@ return function (uri, offset)
end
sortResults(results)
+ jumpSource(results)
return results
end
diff --git a/script/core/jump-source.lua b/script/core/jump-source.lua
new file mode 100644
index 00000000..76d7324b
--- /dev/null
+++ b/script/core/jump-source.lua
@@ -0,0 +1,33 @@
+local guide = require 'parser.guide'
+
+---@param results table
+return function (results)
+ for _, result in ipairs(results) do
+ if result.target.type == 'doc.field.name' then
+ local doc = result.target.parent.source
+ if doc then
+ result.uri = doc.source
+ result.target.uri = doc.source
+ result.target.start = guide.positionOf(doc.line - 1, 0)
+ result.target.finish = guide.positionOf(doc.line - 1, 0)
+ end
+ else
+ local target = result.target
+ if target.type == 'method'
+ or target.type == 'field' then
+ target = target.parent
+ end
+ if target.bindDocs then
+ for _, doc in ipairs(target.bindDocs) do
+ if doc.type == 'doc.source'
+ and doc.bindSource == target then
+ result.uri = doc.source
+ result.target.uri = doc.source
+ result.target.start = guide.positionOf(doc.line - 1, 0)
+ result.target.finish = guide.positionOf(doc.line - 1, 0)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/script/core/reference.lua b/script/core/reference.lua
index 4c9c193d..a468afde 100644
--- a/script/core/reference.lua
+++ b/script/core/reference.lua
@@ -2,6 +2,7 @@ local guide = require 'parser.guide'
local files = require 'files'
local vm = require 'vm'
local findSource = require 'core.find-source'
+local jumpSource = require 'core.jump-source'
local function sortResults(results)
-- 先按照顺序排序
@@ -132,6 +133,7 @@ return function (uri, position)
end
sortResults(results)
+ jumpSource(results)
return results
end
diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua
index d8434c8c..2140090b 100644
--- a/script/core/type-definition.lua
+++ b/script/core/type-definition.lua
@@ -4,6 +4,7 @@ local vm = require 'vm'
local findSource = require 'core.find-source'
local guide = require 'parser.guide'
local rpath = require 'workspace.require-path'
+local jumpSource = require 'core.jump-source'
local function sortResults(results)
-- 先按照顺序排序
@@ -164,6 +165,7 @@ return function (uri, offset)
end
sortResults(results)
+ jumpSource(results)
return results
end