summaryrefslogtreecommitdiff
path: root/server-beta/src/core/definition.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/core/definition.lua')
-rw-r--r--server-beta/src/core/definition.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index e69de29b..da0e6d69 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -0,0 +1,44 @@
+local guide = require 'parser.guide'
+
+local m = {}
+
+function m.asgetlocal(ast, source, callback)
+ local loc = ast.root[source.loc]
+ if not loc then
+ return
+ end
+ return m.aslocal(ast, loc, callback)
+end
+
+function m.assetlocal(ast, source, callback)
+ local loc = ast.root[source.loc]
+ if not loc then
+ return
+ end
+ return m.aslocal(ast, loc, callback)
+end
+
+function m.aslocal(ast, source, callback)
+ callback(source, ast.uri)
+end
+
+return function (ast, text, offset)
+ local results = {}
+ guide.eachSource(ast.root, offset, function (source)
+ local tp = source.type
+ local f = m['as' .. tp]
+ if f then
+ f(ast, source, function (target, uri)
+ results[#results+1] = {
+ uri = uri or ast.uri,
+ source = source,
+ target = target,
+ }
+ end)
+ end
+ end)
+ if #results == 0 then
+ return nil
+ end
+ return results
+end