summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/files.lua10
-rw-r--r--server-beta/src/proto/provider.lua6
-rw-r--r--server-beta/src/pub/init.lua15
-rw-r--r--server-beta/src/pub/pub.lua13
-rw-r--r--server-beta/src/service/service.lua2
-rw-r--r--server-beta/src/task.lua12
-rw-r--r--server-beta/src/workspace/workspace.lua95
7 files changed, 118 insertions, 35 deletions
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index f0c1c876..370b50eb 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -88,6 +88,13 @@ function m.getText(uri)
return file.text
end
+function m.remove(uri)
+ if platform.OS == 'Windows' then
+ uri = uri:lower()
+ end
+ m.fileMap[uri] = nil
+end
+
--- 获取文件语法树(异步)
function m.getAst(uri)
if platform.OS == 'Windows' then
@@ -135,6 +142,9 @@ end
--- 判断是否是Lua文件
function m.isLua(uri)
local ext = uri:match '%.(.-)$'
+ if not ext then
+ return false
+ end
if m.eq(ext, 'lua') then
return true
end
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
index 3fdbd34c..4eb1a669 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/proto/provider.lua
@@ -110,6 +110,9 @@ proto.on('workspace/configuration', function ()
updateConfig()
end)
+proto.on('workspace/didChangeWatchedFiles', function (params)
+end)
+
proto.on('textDocument/didOpen', function (params)
local doc = params.textDocument
local uri = doc.uri
@@ -122,6 +125,9 @@ proto.on('textDocument/didClose', function (params)
local doc = params.textDocument
local uri = doc.uri
files.close(uri)
+ if not files.isLua(uri) then
+ files.remove(uri)
+ end
end)
proto.on('textDocument/didChange', function (params)
diff --git a/server-beta/src/pub/init.lua b/server-beta/src/pub/init.lua
index 65343d64..fbac27f5 100644
--- a/server-beta/src/pub/init.lua
+++ b/server-beta/src/pub/init.lua
@@ -1,4 +1,5 @@
-local pub = require 'pub.pub'
+local pub = require 'pub.pub'
+local task = require 'task'
pub.on('log', function (params, brave)
log.raw(brave.id, params.level, params.msg, params.src, params.line)
@@ -10,11 +11,13 @@ end)
pub.on('proto', function (params)
local proto = require 'proto'
- if params.method then
- proto.doMethod(params)
- else
- proto.doResponse(params)
- end
+ task.create(function ()
+ if params.method then
+ proto.doMethod(params)
+ else
+ proto.doResponse(params)
+ end
+ end)
end)
return pub
diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua
index 4f245517..cf1eb955 100644
--- a/server-beta/src/pub/pub.lua
+++ b/server-beta/src/pub/pub.lua
@@ -1,6 +1,7 @@
local thread = require 'bee.thread'
local utility = require 'utility'
local task = require 'task'
+local timer = require 'timer'
local errLog = thread.channel 'errlog'
local type = type
@@ -97,7 +98,7 @@ function m.popReport(brave, name, params)
log.warn(('Brave pushed unknown report: # %d => %q'):format(brave.id, name))
return
end
- abil(params, brave)
+ xpcall(abil, log.error, params, brave)
end
--- 发布任务(异步)
@@ -210,7 +211,6 @@ function m.recieve()
else
m.popTask(brave, id, result)
end
- task.sleep(0)
::CONTINUE::
end
end
@@ -227,12 +227,9 @@ function m.checkDead()
end
function m.listen()
- task.create(function ()
- while true do
- m.checkDead()
- m.recieve()
- task.sleep(0)
- end
+ timer.loop(0.001, function ()
+ m.checkDead()
+ m.recieve()
end)
end
diff --git a/server-beta/src/service/service.lua b/server-beta/src/service/service.lua
index be486594..781de727 100644
--- a/server-beta/src/service/service.lua
+++ b/server-beta/src/service/service.lua
@@ -83,8 +83,8 @@ function m.startTimer()
end
function m.start()
- pub.recruitBraves(4)
task.setErrorHandle(log.error)
+ pub.recruitBraves(4)
proto.listen()
pub.listen()
m.report()
diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua
index b4cf46d0..c7950e44 100644
--- a/server-beta/src/task.lua
+++ b/server-beta/src/task.lua
@@ -17,8 +17,8 @@ function m.create(callback)
local co = coroutine.create(callback)
m.coTracker[co] = true
local suc, err = coroutine.resume(co)
- if not suc and m.errHandle then
- m.errHandle(debug.traceback(co, err))
+ if not suc and m.errorHandle then
+ m.errorHandle(debug.traceback(co, err))
end
end
@@ -34,8 +34,8 @@ function m.sleep(time)
end
timer.wait(time, function ()
local suc, err = coroutine.resume(co)
- if not suc and m.errHandle then
- m.errHandle(debug.traceback(co, err))
+ if not suc and m.errorHandle then
+ m.errorHandle(debug.traceback(co, err))
end
end)
return coroutine.yield()
@@ -53,8 +53,8 @@ function m.wait(waker)
end
waker(function (...)
local suc, err = coroutine.resume(co, ...)
- if not suc and m.errHandle then
- m.errHandle(debug.traceback(co, err))
+ if not suc and m.errorHandle then
+ m.errorHandle(debug.traceback(co, err))
end
end)
return coroutine.yield()
diff --git a/server-beta/src/workspace/workspace.lua b/server-beta/src/workspace/workspace.lua
index 8368df69..b17f2345 100644
--- a/server-beta/src/workspace/workspace.lua
+++ b/server-beta/src/workspace/workspace.lua
@@ -1,10 +1,15 @@
-local pub = require 'pub'
-local fs = require 'bee.filesystem'
-local furi = require 'file-uri'
-local files = require 'files'
+local pub = require 'pub'
+local fs = require 'bee.filesystem'
+local furi = require 'file-uri'
+local files = require 'files'
+local config = require 'config'
+local glob = require 'glob'
+local platform = require 'bee.platform'
local m = {}
m.type = 'workspace'
+m.ignoreVersion = -1
+m.ignoreMatcher = nil
--- 初始化工作区
function m.init(name, uri)
@@ -12,6 +17,68 @@ function m.init(name, uri)
m.uri = uri
end
+--- 创建排除文件匹配器
+function m.buildIgnoreMatcher()
+ local pattern = {}
+
+ -- config.workspace.ignoreDir
+ for path in pairs(config.config.workspace.ignoreDir) do
+ log.info('Ignore directory:', path)
+ pattern[#pattern+1] = path
+ end
+ -- config.files.exclude
+ for path, ignore in pairs(config.other.exclude) do
+ if ignore then
+ log.info('Ignore by exclude:', path)
+ pattern[#pattern+1] = path
+ end
+ end
+ -- config.workspace.ignoreSubmodules
+ if config.config.workspace.ignoreSubmodules then
+ local buf = pub.task('loadFile', furi.encode((ROOT / '.gitmodules'):string()))
+ if buf then
+ for path in buf:gmatch('path = ([^\r\n]+)') do
+ log.info('Ignore by .gitmodules:', path)
+ pattern[#pattern+1] = path
+ end
+ end
+ end
+ -- config.workspace.useGitIgnore
+ if config.config.workspace.useGitIgnore then
+ local buf = pub.task('loadFile', furi.encode((ROOT / '.gitignore'):string()))
+ if buf then
+ for line in buf:gmatch '[^\r\n]+' do
+ log.info('Ignore by .gitignore:', line)
+ pattern[#pattern+1] = line
+ end
+ end
+ end
+ -- config.workspace.library
+ for path in pairs(config.config.workspace.library) do
+ log.info('Ignore by library:', path)
+ pattern[#pattern+1] = path
+ end
+
+ local matcher = glob.gitignore(pattern)
+
+ if platform.OS == "Windows" then
+ matcher:setOption 'ignoreCase'
+ end
+
+ return matcher
+end
+
+--- 文件是否被忽略
+function m.isIgnored(uri)
+ local path = furi.decode(uri)
+ if m.ignoreVersion == config.version then
+ return m.ignoreMatcher(path)
+ end
+ m.ignoreMatcher = m.buildIgnoreMatcher()
+ m.ignoreVersion = config.version
+ return m.ignoreMatcher(path)
+end
+
--- 预读工作区内所有文件(异步)
function m.preload()
if not m.uri then
@@ -25,20 +92,20 @@ function m.preload()
end
for i = 1, #result.uris do
local childUri = result.uris[i]
- if result.dirs[childUri] then
- scan(childUri, callback)
- else
- callback(childUri)
+ if not m.isIgnored(childUri) then
+ if result.dirs[childUri] then
+ scan(childUri, callback)
+ elseif files.isLua(childUri) then
+ callback(childUri)
+ end
end
end
end
scan(m.uri, function (uri)
- if files.isLua(uri) then
- pub.syncTask('loadFile', uri, function (text)
- log.debug('Preload file at: ' .. uri, #text)
- files.setText(uri, text)
- end)
- end
+ pub.syncTask('loadFile', uri, function (text)
+ log.debug('Preload file at: ' .. uri, #text)
+ files.setText(uri, text)
+ end)
end)
log.info('Preload finish.')
end