summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-18 20:36:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-18 20:36:20 +0800
commita2075b5411c81ab4e7c3da79be1d0e6e56ea7f45 (patch)
treef318445077df15b94776314a650d83adf349a19c
parentfb1d31d354648445d975fe827c237351f036c562 (diff)
downloadlua-language-server-a2075b5411c81ab4e7c3da79be1d0e6e56ea7f45.zip
cleanup
-rw-r--r--script/brave/work.lua40
-rw-r--r--script/core/noder.lua8
-rw-r--r--script/library.lua4
-rw-r--r--script/plugin.lua4
-rw-r--r--script/provider/provider.lua3
-rw-r--r--script/workspace/workspace.lua17
-rw-r--r--test.lua48
-rw-r--r--test/tclient/init.lua1
-rw-r--r--test/tclient/tests/library-ignore-limit.lua4
-rw-r--r--test/tclient/tests/multi-workspace.lua80
-rw-r--r--test/tclient/tests/single-mode.lua1
11 files changed, 113 insertions, 97 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index e1c08a79..6307c777 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -24,43 +24,3 @@ brave.on('timer', function (time)
brave.push('wakeup')
end
end)
-
-brave.on('compile', function (text)
- local state, err = parser.compile(text, 'Lua', 'Lua 5.4')
- if not state then
- log.error(err)
- return
- end
- local lines = parser.lines(text)
- return {
- root = state.root,
- value = state.value,
- errs = state.errs,
- lines = lines,
- }
-end)
-
-brave.on('listDirectory', function (uri)
- local path = fs.path(furi.decode(uri))
- local uris = {}
- for child in fs.pairs(path) do
- local childUri = furi.encode(child:string())
- uris[#uris+1] = childUri
- end
- return uris
-end)
-
-brave.on('isDirectory', function (uri)
- local path = fs.path(furi.decode(uri))
- return fs.is_directory(path)
-end)
-
-brave.on('loadFile', function (uri)
- local filename = furi.decode(uri)
- return util.loadFile(filename)
-end)
-
-brave.on('saveFile', function (params)
- local filename = furi.decode(params.uri)
- return util.saveFile(filename, params.text)
-end)
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 6681fa7c..f648d6c5 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -1894,11 +1894,17 @@ function m.compileGlobalNodes(root)
end)
end
+for uri in files.eachFile() do
+ local state = files.getState(uri)
+ if state then
+ m.compileGlobalNodes(state.ast)
+ end
+end
+
files.watch(function (ev, uri)
if ev == 'update' then
local state = files.getState(uri)
if state then
- --m.compileAllNodes(state.ast)
m.compileGlobalNodes(state.ast)
end
end
diff --git a/script/library.lua b/script/library.lua
index 7925d414..a4f14514 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -496,10 +496,6 @@ files.watch(function (ev, uri)
end)
function m.init()
- if m.inited then
- return
- end
- m.inited = true
initBuiltIn(nil)
for _, scp in ipairs(ws.folders) do
initBuiltIn(scp.uri)
diff --git a/script/plugin.lua b/script/plugin.lua
index 0914c0c0..7f2165db 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -70,10 +70,6 @@ end
---@param scp scope
function m.init(scp)
- if m.hasInited then
- return
- end
- m.hasInited = true
await.call(function () ---@async
local ws = require 'workspace'
m.interface = {}
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 4b22cb47..b16a076f 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -17,6 +17,7 @@ local converter = require 'proto.converter'
local filewatch = require 'filewatch'
local json = require 'json'
local scope = require 'workspace.scope'
+local furi = require 'file-uri'
---@async
local function updateConfig(uri)
@@ -167,7 +168,7 @@ m.register 'workspace/didCreateFiles' {
log.debug('workspace/didCreateFiles', util.dump(params))
for _, file in ipairs(params.files) do
if workspace.isValidLuaUri(file.uri) then
- files.setText(file.uri, pub.awaitTask('loadFile', file.uri), false)
+ files.setText(file.uri, util.loadFile(furi.decode(file.uri)), false)
end
end
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 159f397b..3676efb5 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -55,7 +55,6 @@ function m.reset()
---@type scope[]
m.folders = {}
m.rootUri = nil
- m.inited = false
end
m.reset()
@@ -92,7 +91,6 @@ local globInteferFace = {
}
--- 创建排除文件匹配器
----@async
---@param scp scope
function m.getNativeMatcher(scp)
if scp:get 'nativeMatcher' then
@@ -107,7 +105,7 @@ function m.getNativeMatcher(scp)
end
end
if scp.uri and config.get(scp.uri, 'Lua.workspace.useGitIgnore') then
- local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitignore')
+ local buf = util.loadFile(furi.decode(scp.uri) .. '/.gitignore')
if buf then
for line in buf:gmatch '[^\r\n]+' do
if line:sub(1, 1) ~= '#' then
@@ -116,7 +114,7 @@ function m.getNativeMatcher(scp)
end
end
end
- buf = pub.awaitTask('loadFile', scp.uri .. '/.git/info/exclude')
+ buf = util.loadFile(furi.decode(scp.uri).. '/.git/info/exclude')
if buf then
for line in buf:gmatch '[^\r\n]+' do
if line:sub(1, 1) ~= '#' then
@@ -127,7 +125,7 @@ function m.getNativeMatcher(scp)
end
end
if scp.uri and config.get(scp.uri, 'Lua.workspace.ignoreSubmodules') then
- local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitmodules')
+ local buf = util.loadFile(furi.decode(scp.uri) .. '/.gitmodules')
if buf then
for path in buf:gmatch('path = ([^\r\n]+)') do
log.info('Ignore by .gitmodules:', path)
@@ -383,9 +381,6 @@ end
---@param scp scope
function m.reload(scp)
- if not m.inited then
- return
- end
---@async
await.call(function ()
m.awaitReload(scp)
@@ -393,10 +388,6 @@ function m.reload(scp)
end
function m.init()
- if m.inited then
- return
- end
- m.inited = true
if m.rootUri then
for _, folder in ipairs(scope.folders) do
m.reload(folder)
@@ -526,7 +517,7 @@ fw.event(function (changes) ---@async
if m.isValidLuaUri(uri) then
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
if not files.isOpen(uri) then
- files.setText(uri, pub.awaitTask('loadFile', uri), false)
+ files.setText(uri, util.loadFile(furi.decode(uri)), false)
end
else
local filename = fs.path(path):filename():string()
diff --git a/test.lua b/test.lua
index f094c0c2..9f29b9d9 100644
--- a/test.lua
+++ b/test.lua
@@ -31,20 +31,6 @@ local function loadAllLibs()
assert(require 'lpeglabel')
end
-local function loadDocMetas()
- local files = require 'files'
- local library = require 'library'
- local furi = require 'file-uri'
- local fsu = require 'fs-utility'
- local client = require 'client'
- client.client 'vscode'
- for path in pairs(library.metaPaths) do
- local uri = furi.encode(path)
- files.setText(uri, fsu.loadFile(path))
- --scope.fallback:addLink(uri)
- end
-end
-
local function test(name)
local clock = os.clock()
print(('测试[%s]...'):format(name))
@@ -81,30 +67,28 @@ local function testAll()
end
local function main()
+ LOCALE = 'zh-cn'
require 'utility'.enableCloseFunction()
- require 'library'.init()
- test 'tclient'
+ require 'client' .client 'VSCode'
- --config.Lua.intelliSense.searchDepth = 5
- --loadDocMetas()
+ local lclient = require 'tclient.lclient'
+ local ws = require 'workspace'
- --test 'full';do return end
- require 'workspace.workspace'.reset()
- require 'files'.reset()
- require 'workspace.scope'.reset()
- require 'language' 'zh-cn'
- loadDocMetas()
- require 'bee.platform'.OS = 'Windows'
- testAll()
- require 'bee.platform'.OS = 'Linux'
- testAll()
- require 'bee.platform'.OS = 'macOS'
- testAll()
+ for _, os in ipairs {'Windows', 'Linux', 'macOS'} do
+ require 'bee.platform'.OS = os
+ ---@async
+ lclient():start(function (client)
+ client:registerFakers()
+ client:initialize()
- --test 'tclient'
+ ws.awaitReady()
- test 'full'
+ testAll()
+ end)
+ end
+ test 'tclient'
+ test 'full'
print('测试完成')
end
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index 8e7df570..872c34a4 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -1,2 +1,3 @@
require 'tclient.tests.single-mode'
require 'tclient.tests.library-ignore-limit'
+require 'tclient.tests.multi-workspace'
diff --git a/test/tclient/tests/library-ignore-limit.lua b/test/tclient/tests/library-ignore-limit.lua
index baf42978..dcf8717a 100644
--- a/test/tclient/tests/library-ignore-limit.lua
+++ b/test/tclient/tests/library-ignore-limit.lua
@@ -21,7 +21,9 @@ lclient():start(function (client)
end)
fs.create_directories(fs.path(libraryPath))
- util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000))
+ if not fs.exists(fs.path(largeFilePath)) then
+ util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000))
+ end
client:initialize()
diff --git a/test/tclient/tests/multi-workspace.lua b/test/tclient/tests/multi-workspace.lua
new file mode 100644
index 00000000..99b7f122
--- /dev/null
+++ b/test/tclient/tests/multi-workspace.lua
@@ -0,0 +1,80 @@
+local lclient = require 'tclient.lclient'
+local fs = require 'bee.filesystem'
+local util = require 'utility'
+local furi = require 'file-uri'
+local ws = require 'workspace'
+local files = require 'files'
+
+local rootPath = LOGPATH .. '/multi-workspace'
+local rootUri = furi.encode(rootPath)
+
+for _, name in ipairs { 'ws1', 'ws2', 'share', 'lb1', 'lb2' } do
+ fs.create_directories(fs.path(rootPath .. '/' .. name))
+ util.saveFile(rootPath .. '/' .. name .. '/test.lua', '')
+end
+
+---@async
+lclient():start(function (client)
+ client:registerFakers()
+
+ client:register('workspace/configuration', function (params)
+ local uri = params.items[1].scopeUri
+ if uri == rootUri .. '/ws1' then
+ return {
+ {
+ ['workspace.library'] = {
+ rootPath .. '/share',
+ rootPath .. '/lb1',
+ }
+ }
+ }
+ end
+ if uri == rootUri .. '/ws2' then
+ return {
+ {
+ ['workspace.library'] = {
+ rootPath .. '/share',
+ rootPath .. '/lb2',
+ }
+ }
+ }
+ end
+ return {}
+ end)
+
+ client:initialize {
+ rootPath = rootPath,
+ rootUri = rootUri,
+ workspaceFolders = {
+ {
+ name = 'ws1',
+ uri = rootUri .. '/ws1',
+ },
+ {
+ name = 'ws2',
+ uri = rootUri .. '/ws2',
+ },
+ }
+ }
+
+ ws.awaitReady(rootUri .. '/ws1')
+ ws.awaitReady(rootUri .. '/ws2')
+
+ assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil)
+ assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil)
+ assert(files.getState(rootUri .. '/share/test.lua') ~= nil)
+ assert(files.getState(rootUri .. '/lb1/test.lua') ~= nil)
+ assert(files.getState(rootUri .. '/lb2/test.lua') ~= nil)
+
+ assert(ws.getScope(rootUri .. '/ws1/test.lua').uri == rootUri .. '/ws1')
+ assert(ws.getScope(rootUri .. '/ws2/test.lua').uri == rootUri .. '/ws2')
+ assert(ws.getScope(rootUri .. '/share/test.lua').uri == rootUri .. '/ws1')
+ assert(ws.getScope(rootUri .. '/lb1/test.lua').uri == rootUri .. '/ws1')
+ assert(ws.getScope(rootUri .. '/lb2/test.lua').uri == rootUri .. '/ws2')
+
+ assert(files.isLibrary(rootUri .. '/ws1/test.lua') == false)
+ assert(files.isLibrary(rootUri .. '/ws2/test.lua') == false)
+ assert(files.isLibrary(rootUri .. '/share/test.lua') == true)
+ assert(files.isLibrary(rootUri .. '/lb1/test.lua') == true)
+ assert(files.isLibrary(rootUri .. '/lb2/test.lua') == true)
+end)
diff --git a/test/tclient/tests/single-mode.lua b/test/tclient/tests/single-mode.lua
index d26eb98a..0a7f85ff 100644
--- a/test/tclient/tests/single-mode.lua
+++ b/test/tclient/tests/single-mode.lua
@@ -1,4 +1,3 @@
-local await = require 'await'
local lclient = require 'tclient.lclient'
local ws = require 'workspace'
local util = require 'utility'