summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-beta/src/core/definition.lua2
-rw-r--r--server-beta/src/file-uri.lua6
-rw-r--r--server-beta/src/files.lua21
-rw-r--r--server-beta/src/proto/provider.lua2
-rw-r--r--server-beta/test/crossfile/definition.lua37
-rw-r--r--server-beta/test/crossfile/init.lua2
-rw-r--r--server-beta/test/definition/init.lua2
7 files changed, 44 insertions, 28 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index b3ec7cf8..e0589752 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -1,7 +1,7 @@
local guide = require 'parser.guide'
local engineer = require 'core.engineer'
-return function (ast, text, offset)
+return function (ast, offset)
local results = {}
local searcher = engineer(ast)
guide.eachSourceContain(ast.ast, offset, function (source)
diff --git a/server-beta/src/file-uri.lua b/server-beta/src/file-uri.lua
index e58a86eb..8acd4f64 100644
--- a/server-beta/src/file-uri.lua
+++ b/server-beta/src/file-uri.lua
@@ -38,6 +38,9 @@ local m = {}
-- /usr/home --> file:///usr/home
-- \\server\share\some\path --> file://server/share/some/path
+--- path -> uri
+---@param path string
+---@return string uri
function m.encode(path)
local authority = ''
if platform.OS == 'Windows' then
@@ -77,6 +80,9 @@ end
-- file:///usr/home --> /usr/home
-- file://server/share/some/path --> \\server\share\some\path
+--- uri -> path
+---@param uri string
+---@return string path
function m.decode(uri)
local scheme, authority, path = uri:match('([^:]*):?/?/?([^/]*)(.*)')
if not scheme then
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 9a90aabb..5de2a8fc 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -14,6 +14,7 @@ m.assocVersion = -1
m.assocMatcher = nil
--- 打开文件
+---@param uri string
function m.open(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -22,6 +23,7 @@ function m.open(uri)
end
--- 关闭文件
+---@param uri string
function m.close(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -30,6 +32,8 @@ function m.close(uri)
end
--- 设置文件文本
+---@param uri string
+---@param text string
function m.setText(uri, text)
local originUri = uri
if platform.OS == 'Windows' then
@@ -63,6 +67,8 @@ function m.onCompiled(uri, callback)
end
--- 获取文件文本
+---@param uri string
+---@return string text
function m.getText(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -74,6 +80,8 @@ function m.getText(uri)
return file.text
end
+--- 移除文件
+---@param uri string
function m.remove(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -81,7 +89,16 @@ function m.remove(uri)
m.fileMap[uri] = nil
end
+--- 移除所有文件
+function m.removeAll()
+ for uri in pairs(m.fileMap) do
+ m.fileMap[uri] = nil
+ end
+end
+
--- 获取文件语法树
+---@param uri string
+---@return table ast
function m.getAst(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -102,6 +119,8 @@ function m.getAst(uri)
end
--- 获取文件行信息
+---@param uri string
+---@return table lines
function m.getLines(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
@@ -142,6 +161,8 @@ function m.getAssoc()
end
--- 判断是否是Lua文件
+---@param uri string
+---@return boolean
function m.isLua(uri)
local ext = uri:match '%.([^%.%/%\\]-)$'
if not ext then
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
index 0c029a45..9ad5147a 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/proto/provider.lua
@@ -157,7 +157,7 @@ proto.on('textDocument/definition', function (params)
local lines = files.getLines(uri)
local text = files.getText(uri)
local offset = inte.offset(lines, text, params.position)
- local result = core(ast, text, offset)
+ local result = core(ast, offset)
if not result then
return nil
end
diff --git a/server-beta/test/crossfile/definition.lua b/server-beta/test/crossfile/definition.lua
index c765d98a..630539d2 100644
--- a/server-beta/test/crossfile/definition.lua
+++ b/server-beta/test/crossfile/definition.lua
@@ -1,8 +1,6 @@
-local service = require 'service'
-local workspace = require 'workspace'
-local fs = require 'bee.filesystem'
-local core = require 'core'
-local uric = require 'uri'
+local files = require 'files'
+local furi = require 'file-uri'
+local core = require 'core.definition'
rawset(_G, 'TEST', true)
@@ -43,30 +41,27 @@ local function founded(targets, results)
end
function TEST(datas)
- local lsp = service()
- local ws = workspace(lsp, 'test')
- lsp.workspace = ws
+ files.removeAll()
- local compiled = {}
local targetList = {}
- local sourceList, sourceUri
-
+ local sourceList
+ local sourceUri
for i, data in ipairs(datas) do
- local uri = uric.encode(fs.path(data.path))
+ local uri = furi.encode(data.path)
local new, list = catch_target(data.content, '!')
if new ~= data.content or data.target then
if data.target then
targetList[#targetList+1] = {
data.target[1],
data.target[2],
- uri
+ uri,
}
else
for _, position in ipairs(list) do
targetList[#targetList+1] = {
position[1],
position[2],
- uri
+ uri,
}
end
end
@@ -74,23 +69,17 @@ function TEST(datas)
end
new, list = catch_target(data.content, '?')
if new ~= data.content then
- compiled[i] = new
sourceList = list
sourceUri = uri
data.content = new
end
- lsp:saveText(uri, 1, data.content)
- ws:addFile(uric.decode(uri))
- end
-
- while lsp._needCompile[1] do
- lsp:compileVM(lsp._needCompile[1])
+ files.setText(uri, data.content)
end
- local sourceVM = lsp:getVM(sourceUri)
- assert(sourceVM)
+ local sourceAst = files.getAst(sourceUri)
+ assert(sourceAst)
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local positions = core.definition(sourceVM, sourcePos, 'definition')
+ local positions = core(sourceAst, sourcePos)
if positions then
assert(founded(targetList, positions))
else
diff --git a/server-beta/test/crossfile/init.lua b/server-beta/test/crossfile/init.lua
index b7a52a4d..836d201c 100644
--- a/server-beta/test/crossfile/init.lua
+++ b/server-beta/test/crossfile/init.lua
@@ -1,4 +1,4 @@
---require 'crossfile.definition'
+require 'crossfile.definition'
--require 'crossfile.hover'
--require 'crossfile.completion'
--require 'crossfile.document_symbol'
diff --git a/server-beta/test/definition/init.lua b/server-beta/test/definition/init.lua
index 54e0be4b..f2c68f14 100644
--- a/server-beta/test/definition/init.lua
+++ b/server-beta/test/definition/init.lua
@@ -43,7 +43,7 @@ function TEST(script)
local ast = parser:compile(new_script, 'lua', 'Lua 5.3')
assert(ast)
- local results = core(ast, new_script, pos)
+ local results = core(ast, pos)
if results then
local positions = {}
for i, result in ipairs(results) do