summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/vm.lua13
-rw-r--r--server/src/method/textDocument/didClose.lua2
-rw-r--r--server/src/service.lua61
3 files changed, 49 insertions, 27 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 05b4f2e6..07b41d62 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -1188,21 +1188,19 @@ function mt:mergeRequire(value, destVM)
self:mergeValue(value, mainValue)
end
-function mt:loadRequires()
- if not self.lsp or not self.lsp.workspace then
- return
- end
+function mt:loadRequires(lsp)
for _, req in ipairs(self.requires) do
local str = req.str
if type(str) == 'string' then
- local uri = self.lsp.workspace:searchPath(str)
+ local uri = lsp.workspace:searchPath(str)
-- 如果循环require,这里会返回nil
- local destVM = self.lsp:loadVM(uri)
+ local destVM = lsp:loadVM(uri)
if destVM then
self:mergeRequire(req.value, destVM)
end
end
end
+ self.requires = {}
end
local function compile(ast, lsp)
@@ -1233,9 +1231,6 @@ local function compile(ast, lsp)
-- 执行代码
vm:doActions(ast)
- -- 合并requires
- vm:loadRequires()
-
return vm
end
diff --git a/server/src/method/textDocument/didClose.lua b/server/src/method/textDocument/didClose.lua
index 5da33010..7d097407 100644
--- a/server/src/method/textDocument/didClose.lua
+++ b/server/src/method/textDocument/didClose.lua
@@ -1,6 +1,6 @@
return function (lsp, params)
local doc = params.textDocument
- --lsp:removeText(doc.uri, doc.version)
+ lsp:removeText(doc.uri, doc.version)
lsp:close(doc.uri)
return true
end
diff --git a/server/src/service.lua b/server/src/service.lua
index 912917ae..445572b7 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -89,19 +89,27 @@ function mt:_doDiagnostic()
local clock = os.clock()
local count = 0
local copy = {}
- for uri, data in pairs(self._needDiagnostics) do
- count = count + 1
- copy[uri] = data
+ for uri in pairs(self._needDiagnostics) do
self._needDiagnostics[uri] = nil
+ count = count + 1
+ copy[uri] = true
end
- for uri, data in pairs(copy) do
- local name = 'textDocument/publishDiagnostics'
- local res = self:_callMethod(name, data)
- if res then
- rpc:notify(name, {
- uri = uri,
- diagnostics = res,
- })
+ for uri in pairs(copy) do
+ local obj = self._file[uri]
+ if obj then
+ local data = {
+ uri = uri,
+ vm = obj.vm,
+ lines = obj.lines,
+ }
+ local name = 'textDocument/publishDiagnostics'
+ local res = self:_callMethod(name, data)
+ if res then
+ rpc:notify(name, {
+ uri = uri,
+ diagnostics = res,
+ })
+ end
end
end
local passed = os.clock() - clock
@@ -237,18 +245,35 @@ function mt:compileVM(uri)
return obj
end
- self._needDiagnostics[uri] = {
- vm = obj.vm,
- lines = obj.lines,
- uri = uri,
- }
+ self._needDiagnostics[uri] = true
+ self._needRequire[uri] = true
return obj
end
+function mt:_loadRequires()
+ if not self.workspace then
+ return
+ end
+ if not next(self._needRequire) then
+ return
+ end
+ local copy = {}
+ for uri in pairs(self._needRequire) do
+ self._needRequire[uri] = nil
+ copy[uri] = true
+ end
+ for uri in pairs(copy) do
+ local obj = self._file[uri]
+ if obj then
+ obj.vm:loadRequires(self)
+ self._needDiagnostics[uri] = true
+ end
+ end
+end
+
function mt:removeText(uri)
self._file[uri] = nil
- self._needCompile[uri] = nil
end
function mt:onTick()
@@ -265,6 +290,7 @@ function mt:onTick()
end
self:_buildTextCache()
self:_doDiagnostic()
+ self:_loadRequires()
if os.clock() - self._clock >= 600 then
self._clock = os.clock()
@@ -304,6 +330,7 @@ return function ()
local session = setmetatable({
_file = {},
_needCompile = {},
+ _needRequire = {},
_needDiagnostics = {},
_opening = {},
_clock = -100,