From 5540352b5a3f71ff2e1830a77b34b220078f02ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 23 Jan 2019 16:03:35 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E8=AE=A1=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/service.lua | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'server/src/service.lua') diff --git a/server/src/service.lua b/server/src/service.lua index 3b3b4f1d..6c7b83d7 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -6,6 +6,7 @@ local rpc = require 'rpc' local parser = require 'parser' local core = require 'core' local lang = require 'language' +local updateTimer = require 'timer' local ErrorCodes = { -- Defined by JSON RPC @@ -65,6 +66,16 @@ function mt:_callMethod(name, params) end end +function mt:responseProto(id, response, err) + local container = table.container() + if err then + container.error = err + else + container.result = response + end + rpc:response(id, container) +end + function mt:_doProto(proto) local id = proto.id local name = proto.method @@ -73,13 +84,13 @@ function mt:_doProto(proto) if not id then return end - local container = table.container() - if err then - container.error = err + if type(response) == 'function' then + return function (final) + self:responseProto(id, final) + end else - container.result = response + self:responseProto(id, response, err) end - rpc:response(id, container) end function mt:clearDiagnostics(uri) @@ -111,6 +122,14 @@ function mt:needCompile(uri, compiled) table.insert(self._needCompile, 1, uri) end +function mt:isWaitingCompile() + if self._needCompile[1] then + return true + else + return false + end +end + function mt:saveText(uri, version, text) local obj = self._file[uri] if obj then @@ -404,7 +423,7 @@ function mt:checkWorkSpaceComplete() end function mt:_createCompileTask() - if not self._needCompile[1] and not next(self._needDiagnostics) then + if not self:isWaitingCompile() and not next(self._needDiagnostics) then return end self._compileTask = coroutine.create(function () @@ -484,9 +503,14 @@ function mt:listen() local _, out = async.run 'proto' self._proto = out + local clock = os.clock() while true do async.onTick() self:onTick() + + local delta = os.clock() - clock + clock = os.clock() + updateTimer(delta) thread.sleep(0.001) end end -- cgit v1.2.3