summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-25 17:47:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-25 17:47:55 +0800
commit2b3fad482ec76d2b63af79c6c9ba8ee62dc6dc3f (patch)
tree39b6ec7242957d9beb481c2104b7e056efab38cf
parentf74154aac067a7c9e2e4f302d69be4193a960b04 (diff)
downloadlua-language-server-2b3fad482ec76d2b63af79c6c9ba8ee62dc6dc3f.zip
用引用链
-rw-r--r--server/src/matcher/vm.lua3
-rw-r--r--server/src/service.lua45
2 files changed, 26 insertions, 22 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 2156b0e8..4f6b4952 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -549,6 +549,7 @@ function mt:tryRequireOne(strValue, mode)
end
-- 如果取不到VM(不编译),则做个标记,之后再取一次
local destVM = self.lsp:getVM(uri)
+ self.lsp:compileChain(self.uri, uri)
if destVM then
if mode == 'require' then
return self:getRequire(strValue, destVM)
@@ -557,8 +558,6 @@ function mt:tryRequireOne(strValue, mode)
elseif mode == 'dofile' then
return self:getRequire(strValue, destVM)
end
- else
- self.lsp:compileChain(self.uri, uri)
end
end
return nil
diff --git a/server/src/service.lua b/server/src/service.lua
index 21bb6015..7092e84d 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -143,9 +143,14 @@ function mt:compileAll()
local size = 0
local clock = os.clock()
for _, uri in ipairs(list) do
+ self._compiled[uri] = true
local obj = self:compileVM(uri)
- size = size + #obj.text
+ if obj then
+ size = size + #obj.text
+ end
end
+ self._compiled = {}
+
local passed = os.clock() - clock
if passed > 0.1 then
log.debug(('\n\z
@@ -171,6 +176,9 @@ function mt:needCompile(uri)
if self._needCompile[uri] then
return
end
+ if self._compiled[uri] then
+ return
+ end
self._needCompile[uri] = true
table.insert(self._needCompile, 1, uri)
end
@@ -253,6 +261,15 @@ function mt:compileVM(uri)
end
local ast = parser:ast(obj.text)
+ -- 编译前清除节点信息
+ if obj.parent then
+ for pUri in pairs(obj.parent) do
+ local parent = self._file[pUri]
+ if parent and parent.child then
+ parent.child[uri] = nil
+ end
+ end
+ end
obj.vm = matcher.vm(ast, self, uri)
obj.lines = parser:lines(obj.text, 'utf8')
if not obj.vm then
@@ -261,24 +278,13 @@ function mt:compileVM(uri)
self._needDiagnostics[uri] = true
if obj.child then
+ local list = {}
for child in pairs(obj.child) do
- obj.child[child] = nil
- self:needCompile(child)
+ list[#list+1] = child
end
- obj.child = nil
- end
-
- if obj.parent then
- local hasParent
- for parent in pairs(obj.parent) do
- if self:getVM(parent) then
- obj.parent[parent] = nil
- else
- hasParent = true
- end
- end
- if not hasParent then
- obj.parent = nil
+ table.sort(list)
+ for _, child in ipairs(list) do
+ self:needCompile(child)
end
end
@@ -290,9 +296,6 @@ function mt:getVM(uri)
if not obj then
return nil
end
- if self._needCompile[uri] then
- return nil
- end
return obj.vm
end
@@ -376,8 +379,10 @@ return function ()
_file = {},
_needCompile = {},
_needDiagnostics = {},
+ _compiled = {},
_opening = {},
_clock = -100,
+ _version = 0,
}, mt)
return session
end