From ff8e98d0e4824a96b93ccde1a40779a83e4405ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 27 Dec 2018 14:49:41 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/service.lua | 66 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'server') diff --git a/server/src/service.lua b/server/src/service.lua index e98667fb..165de434 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -256,14 +256,7 @@ function mt:loadVM(uri) return obj.vm, obj.lines end -function mt:compileVM(uri) - local obj = self._file[uri] - if not obj then - return nil - end - if not self._needCompile[uri] then - return nil - end +function mt:_markCompiled(uri) local compiled = self._needCompile[uri] if compiled then compiled[uri] = true @@ -275,6 +268,10 @@ function mt:compileVM(uri) break end end + return compiled +end + +function mt:compileAst(obj) local ast, err = parser:ast(obj.text) if not ast then if type(err) == 'string' then @@ -284,10 +281,14 @@ function mt:compileVM(uri) type = 3, message = lang.script('PARSER_CRASH', err:match 'grammar%.lua%:%d+%:(.+)'), }) + else + obj.astErr = err end end + return ast +end - -- 编译前清除节点信息 +function mt:_clearChainNode(obj, uri) if obj.parent then for pUri in pairs(obj.parent) do local parent = self._file[pUri] @@ -296,26 +297,47 @@ function mt:compileVM(uri) end end end +end + +function mt:_compileChain(obj, compiled) + if not obj.child then + return + end + if not compiled then + compiled = {} + end + local list = {} + for child in pairs(obj.child) do + list[#list+1] = child + end + table.sort(list) + for _, child in ipairs(list) do + self:needCompile(child, compiled) + end +end + +function mt:compileVM(uri) + local obj = self._file[uri] + if not obj then + return nil + end + if not self._needCompile[uri] then + return nil + end + + local compiled = self:_markCompiled(uri) + local ast = self:compileAst(obj) + self:_clearChainNode(obj, uri) + obj.vm = matcher.vm(ast, self, uri) obj.lines = parser:lines(obj.text, 'utf8') if not obj.vm then return obj end + self:_compileChain(obj, compiled) + self._needDiagnostics[uri] = true - if obj.child then - if not compiled then - compiled = {} - end - local list = {} - for child in pairs(obj.child) do - list[#list+1] = child - end - table.sort(list) - for _, child in ipairs(list) do - self:needCompile(child, compiled) - end - end return obj end -- cgit v1.2.3