summaryrefslogtreecommitdiff
path: root/server/src/workspace.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-24 10:50:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-24 10:50:21 +0800
commitbc40e38ee557b338bad56e4c09489ba031fc8787 (patch)
tree694f60ab63161551236017a339213a371b6341c2 /server/src/workspace.lua
parent3847677348a5d1a8bd23a854d773040f276a77ad (diff)
downloadlua-language-server-bc40e38ee557b338bad56e4c09489ba031fc8787.zip
跨越文件的测试
Diffstat (limited to 'server/src/workspace.lua')
-rw-r--r--server/src/workspace.lua63
1 files changed, 31 insertions, 32 deletions
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index ff26ff53..42ce3343 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -1,7 +1,29 @@
local fs = require 'bee.filesystem'
local async = require 'async'
-local function uriDecode(uri)
+local function split(str, sep)
+ local t = {}
+ for s in str:gmatch('[^' .. sep .. ']+') do
+ t[#t+1] = s
+ end
+ return t
+end
+
+local function similarity(a, b)
+ local ta = split(a, '/\\')
+ local tb = split(b, '/\\')
+ for i = 1, #ta do
+ if ta[i] ~= tb[i] then
+ return i - 1
+ end
+ end
+ return #ta
+end
+
+local mt = {}
+mt.__index = mt
+
+function mt:uriDecode(uri)
if uri:sub(1, 8) ~= 'file:///' then
log.error('uri decode failed: ', uri)
return nil
@@ -24,7 +46,7 @@ local function uriDecode(uri)
return fs.absolute(path)
end
-local function uriEncode(path)
+function mt:uriEncode(path)
local names = {}
local cur = fs.absolute(path)
while true do
@@ -45,30 +67,8 @@ local function uriEncode(path)
return 'file:///' .. table.concat(names, '/')
end
-local function split(str, sep)
- local t = {}
- for s in str:gmatch('[^' .. sep .. ']+') do
- t[#t+1] = s
- end
- return t
-end
-
-local function similarity(a, b)
- local ta = split(a, '/\\')
- local tb = split(b, '/\\')
- for i = 1, #ta do
- if ta[i] ~= tb[i] then
- return i - 1
- end
- end
- return #ta
-end
-
-local mt = {}
-mt.__index = mt
-
function mt:init(rootUri)
- self.root = uriDecode(rootUri)
+ self.root = self:uriDecode(rootUri)
if not self.root then
return
end
@@ -94,7 +94,7 @@ function mt:init(rootUri)
for _, filename in ipairs(list) do
local path = fs.absolute(fs.path(filename))
local name = path:string():lower()
- self.files[name] = uriEncode(path)
+ self.files[name] = self:uriEncode(path)
end
self:reset()
end)
@@ -102,13 +102,13 @@ end
function mt:addFile(uri)
if uri:sub(-4) == '.lua' then
- local name = uriDecode(uri):string():lower()
+ local name = self:uriDecode(uri):string():lower()
self.files[name] = uri
end
end
function mt:removeFile(uri)
- local name = uriDecode(uri):string():lower()
+ local name = self:uriDecode(uri):string():lower()
self.files[name] = nil
end
@@ -137,7 +137,7 @@ function mt:findPath(baseUri, searchers)
end)
uri = results[1]
end
- self.lsp:readText(uri, uriDecode(uri))
+ self.lsp:readText(uri, self:uriDecode(uri))
return uri
end
@@ -179,12 +179,12 @@ function mt:reset()
end
function mt:relativePathByUri(uri)
- local path = uriDecode(uri)
+ local path = self:uriDecode(uri)
local relate = fs.relative(path, self.root)
return relate
end
-return function (lsp, name, uri)
+return function (lsp, name)
local workspace = setmetatable({
lsp = lsp,
name = name,
@@ -197,6 +197,5 @@ return function (lsp, name, uri)
'?/?.lua',
},
}, mt)
- workspace:init(uri)
return workspace
end