summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src')
-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
4 files changed, 29 insertions, 2 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