diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-21 16:00:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-21 16:00:05 +0800 |
commit | e9c7d91660f032190eb6d2365f2bad8cf9500ba9 (patch) | |
tree | c6d0420d2deadca2bd6133a819bfa2d8afe320a3 | |
parent | feb215f22fa60904506bffdf63e96f90739a89d3 (diff) | |
download | lua-language-server-e9c7d91660f032190eb6d2365f2bad8cf9500ba9.zip |
使用协程启动语法树编译
-rw-r--r-- | server/src/service.lua | 89 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 5 | ||||
-rw-r--r-- | server/test/crossfile/definition.lua | 5 | ||||
-rw-r--r-- | server/test/crossfile/document_symbol.lua | 5 |
4 files changed, 46 insertions, 58 deletions
diff --git a/server/src/service.lua b/server/src/service.lua index 96eafc1e..dc680ec0 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -133,55 +133,6 @@ function mt:clearDiagnostics(uri) }) end -function mt:compileAll() - if not next(self._needCompile) then - return - end - local list = {} - for i, uri in ipairs(self._needCompile) do - list[i] = uri - end - - local size = 0 - local clock = os.clock() - for _, uri in ipairs(list) do - local obj = self:compileVM(uri) - if obj then - size = size + #obj.text - end - end - - local passed = os.clock() - clock - if passed > 0.1 then - local astCost = 0 - local vmCost = 0 - local lineCost = 0 - for _, uri in ipairs(list) do - local obj = self._file[uri] - if obj and obj.astCost and obj.vmCost and obj.lineCost then - astCost = astCost + obj.astCost - vmCost = vmCost + obj.vmCost - lineCost = lineCost + obj.lineCost - end - end - log.debug(('\n\z - Cache completion\n\z - Cost: [%.3f]sec\n\z - Ast: [%.3f]sec\n\z - VM: [%.3f]sec\n\z - Line: [%.3f]sec\n\z - Num: [%d]\n\z - Size: [%.3f]kb'):format( - passed, - astCost, - vmCost, - lineCost, - #list, - size / 1000 - )) - end -end - function mt:read(mode) if not self._input then return nil @@ -411,7 +362,38 @@ function mt:checkWorkSpaceComplete() }) end -function mt:onTick() +function mt:_createCompileTask() + local uri = self._needCompile[1] + if not uri then + return nil + end + self._compileTask = coroutine.create(function () + self:compileVM(uri) + self:_doDiagnostic() + end) +end + +function mt:_doCompileTask() + if not self._compileTask then + self:_createCompileTask() + end + if not self._compileTask then + return + end + while true do + local suc, res = coroutine.resume(self._compileTask) + if not suc then + break + end + if coroutine.status(self._compileTask) == 'dead' then + self._compileTask = nil + break + end + self:_loadProto() + end +end + +function mt:_loadProto() while true do local ok, proto = self._proto:pop() if not ok then @@ -423,8 +405,11 @@ function mt:onTick() rpc:recieve(proto) end end - self:compileAll() - self:_doDiagnostic() +end + +function mt:onTick() + self:_loadProto() + self:_doCompileTask() if os.clock() - self._clock >= 600 then self._clock = os.clock() diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index 82a1fbc0..bccf6cdf 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -83,8 +83,9 @@ function TEST(data) ws:addFile(uri) end - lsp:compileAll() - lsp:compileAll() + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end local vm = lsp:loadVM(mainUri) assert(vm) diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua index dda1bf9a..a0df15a4 100644 --- a/server/test/crossfile/definition.lua +++ b/server/test/crossfile/definition.lua @@ -42,8 +42,9 @@ function TEST(data) ws:addFile(sourceUri) lsp:saveText(targetUri, 1, targetScript) ws:addFile(targetUri) - lsp:compileAll() - lsp:compileAll() + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end local sourceVM = lsp:getVM(sourceUri) assert(sourceVM) diff --git a/server/test/crossfile/document_symbol.lua b/server/test/crossfile/document_symbol.lua index 7852c645..e8ffbedf 100644 --- a/server/test/crossfile/document_symbol.lua +++ b/server/test/crossfile/document_symbol.lua @@ -74,8 +74,9 @@ function TEST(data) ws:addFile(sourceUri) lsp:saveText(targetUri, 1, data[1].content) ws:addFile(targetUri) - lsp:compileAll() - lsp:compileAll() + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end local sourceVM = lsp:getVM(sourceUri) assert(sourceVM) |