diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-20 16:13:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-20 16:13:53 +0800 |
commit | 665af3bd3d2c7e51b2b23336446eb04d5de2e060 (patch) | |
tree | a297a41989eb4ccf2c0872ef2a540212188979d9 /server-beta | |
parent | 14fd68e06334352a9a7247b3d5bd9ba4259229a9 (diff) | |
download | lua-language-server-665af3bd3d2c7e51b2b23336446eb04d5de2e060.zip |
编译任务
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/brave/init.lua | 13 | ||||
-rw-r--r-- | server-beta/src/parser/compile.lua | 6 | ||||
-rw-r--r-- | server-beta/src/parser/parse.lua | 4 | ||||
-rw-r--r-- | server-beta/src/proto/init.lua | 22 | ||||
-rw-r--r-- | server-beta/src/pub/pub.lua | 21 |
5 files changed, 60 insertions, 6 deletions
diff --git a/server-beta/src/brave/init.lua b/server-beta/src/brave/init.lua index 39b66bac..aac92a38 100644 --- a/server-beta/src/brave/init.lua +++ b/server-beta/src/brave/init.lua @@ -1,5 +1,6 @@ local brave = require 'brave.brave' local jsonrpc = require 'jsonrpc' +local parser = require 'parser' brave.on('loadProto', function () while true do @@ -10,4 +11,16 @@ brave.on('loadProto', function () end end) +brave.on('compile', function (text) + local state, err = parser:compile(text, 'lua', 'Lua 5.4') + if not state then + log.debug(err) + return + end + return { + root = state.root, + errs = state.errs, + } +end) + return brave diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua index f6efb6e1..0e6b4848 100644 --- a/server-beta/src/parser/compile.lua +++ b/server-beta/src/parser/compile.lua @@ -556,9 +556,9 @@ local function PostCompile() end return function (self, lua, mode, version) - local state, errs = self:parse(lua, mode, version) + local state, err = self:parse(lua, mode, version) if not state then - return errs + return nil, err end pushError = state.pushError Root = state.root @@ -570,5 +570,5 @@ return function (self, lua, mode, version) PostCompile() state.ast = nil Cache = nil - return state, errs + return state end diff --git a/server-beta/src/parser/parse.lua b/server-beta/src/parser/parse.lua index cec946c0..0fd64e80 100644 --- a/server-beta/src/parser/parse.lua +++ b/server-beta/src/parser/parse.lua @@ -7,6 +7,7 @@ return function (self, lua, mode, version) lua = lua, emmy = {}, root = {}, + errs = errs, pushError = function (err) if err.finish < err.start then err.finish = err.start @@ -30,8 +31,7 @@ return function (self, lua, mode, version) end if not res then state.pushError(err) - return nil, errs end state.ast = res - return state, errs + return state end diff --git a/server-beta/src/proto/init.lua b/server-beta/src/proto/init.lua index 5474b1d8..6e52fcbe 100644 --- a/server-beta/src/proto/init.lua +++ b/server-beta/src/proto/init.lua @@ -1,9 +1,11 @@ local proto = require 'proto.proto' local util = require 'utility' local cap = require 'proto.capability' +local pub = require 'pub' +local task = require 'task' proto.on('initialize', function (params) - log.debug(util.dump(params)) + --log.debug(util.dump(params)) return { capabilities = cap.initer, } @@ -32,4 +34,22 @@ proto.on('textDocument/hover', function () } end) +proto.on('textDocument/didOpen', function (params) + local doc = params.textDocument + local uri = doc.uri + local text = doc.text + local state = pub.task('compile', text) +end) + +proto.on('textDocument/didClose', function (params) +end) + +proto.on('textDocument/didChange', function (params) + local doc = params.textDocument + local change = params.contentChanges + local uri = doc.uri + local text = change[1].text + local state = pub.task('compile', text) +end) + return proto diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua index 9a1a6049..69331357 100644 --- a/server-beta/src/pub/pub.lua +++ b/server-beta/src/pub/pub.lua @@ -19,6 +19,7 @@ local m = {} m.type = 'pub' m.braves = {} m.ability = {} +m.taskList = {} --- 注册酒馆的功能 function m.on(name, callback) @@ -71,6 +72,7 @@ function m.popTask(brave, id, result) return end brave.taskList[id] = nil + m.checkWaitingTask(brave) waker(result) end @@ -92,6 +94,25 @@ function m.task(name, params) return m.pushTask(brave, name, params) end end + -- 如果所有勇者都在战斗,那么把任务缓存到队列里 + -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 + -- 交给该勇者 + m.taskList[#m.taskList+1] = function (brave) + return m.pushTask(brave, name, params) + end +end + +--- 检查堆积任务 +function m.checkWaitingTask(brave) + if #m.taskList == 0 then + return + end + -- 如果勇者还有其他活要忙,那么让他继续忙去吧 + if next(brave.taskList) then + return + end + local waiting = table.remove(m.taskList, 1) + waiting(brave) end --- 接收反馈 |