diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-30 11:01:04 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-30 11:01:04 +0800 |
commit | 8e065707060a5f5902ed2552187a61dda51130f8 (patch) | |
tree | 6e11b7b4d33dc19f4bfc1f3977f328ed40812b45 | |
parent | 64efd65a7e8793a2e29ab922bceeacc6a2b03ee2 (diff) | |
download | lua-language-server-8e065707060a5f5902ed2552187a61dda51130f8.zip |
修正初始化编译耗时过高的问题
-rw-r--r-- | server/src/service.lua | 23 | ||||
-rw-r--r-- | server/src/workspace.lua | 3 |
2 files changed, 18 insertions, 8 deletions
diff --git a/server/src/service.lua b/server/src/service.lua index d218f3f8..51fb756b 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -174,7 +174,7 @@ function mt:isOpen(uri) end end -function mt:readText(uri, path, buf) +function mt:readText(uri, path, buf, compiled) local obj = self._file[uri] if obj then return @@ -189,7 +189,7 @@ function mt:readText(uri, path, buf) text = text, uri = uri, } - self:needCompile(uri) + self:needCompile(uri, compiled) end function mt:removeText(uri) @@ -220,10 +220,10 @@ function mt:loadVM(uri) return obj.vm, obj.lines, obj.text end -function mt:_markCompiled(uri) - local compiled = self._needCompile[uri] - if compiled then - compiled[uri] = true +function mt:_markCompiled(uri, compiled) + local newCompiled = self._needCompile[uri] + if newCompiled then + newCompiled[uri] = true self._needCompile[uri] = nil end for i, u in ipairs(self._needCompile) do @@ -232,6 +232,12 @@ function mt:_markCompiled(uri) break end end + if newCompiled == compiled then + return compiled + end + for k, v in pairs(newCompiled) do + compiled[k] = v + end return compiled end @@ -317,7 +323,7 @@ function mt:compileVM(uri) return nil end if self._needCompile[uri] then - compiled = self:_markCompiled(uri) + self:_markCompiled(uri, compiled) else return nil end @@ -331,6 +337,9 @@ function mt:compileVM(uri) self._needDiagnostics[uri] = true + if obj.vmCost > 0.1 then + log.debug(('Compile VM[%s] takes: %.3f sec'):format(uri, obj.vmCost)) + end if not obj.vm then return nil end diff --git a/server/src/workspace.lua b/server/src/workspace.lua index c02f2854..1000558e 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -102,6 +102,7 @@ function mt:init(rootUri) log.debug('忽略文件:\r\n' .. table.concat(ignored, '\r\n')) + local compiled = {} async.run('scanfiles', { root = self.root:string(), ignored = ignored, @@ -118,7 +119,7 @@ function mt:init(rootUri) local name = path:string():lower() local uri = self:uriEncode(path) self.files[name] = uri - self.lsp:readText(uri, path, file.buf) + self.lsp:readText(uri, path, file.buf, compiled) end end) end |