summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/compile.lua2
-rw-r--r--server/test/compile/init.lua22
-rw-r--r--server/test/main.lua1
3 files changed, 24 insertions, 1 deletions
diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua
index 7b29f188..b9bd4b6d 100644
--- a/server/src/matcher/compile.lua
+++ b/server/src/matcher/compile.lua
@@ -8,7 +8,7 @@ function mt:getVar(key, source)
end
local var = self.env.var[key]
or self:getField(self.env.var._ENV, key, source) -- 这里不需要用getVar来递归获取_ENV
- if not var then
+ if not var and source then
var = self:addField(self:getVar '_ENV', key, source)
end
if var and var.meta then
diff --git a/server/test/compile/init.lua b/server/test/compile/init.lua
new file mode 100644
index 00000000..265388d2
--- /dev/null
+++ b/server/test/compile/init.lua
@@ -0,0 +1,22 @@
+local parser = require 'parser'
+local matcher = require 'matcher'
+
+rawset(_G, 'TEST', true)
+
+function TEST(buf)
+ local ast = parser:ast(buf)
+ assert(ast)
+ local results = matcher.compile(ast)
+ assert(results)
+end
+
+TEST [[
+obj.lines:
+
+self._needDiagnostics[uri] = {
+ ast = ast,
+ results = obj.results,
+ lines = obj.lines,
+ uri = uri,
+}
+]]
diff --git a/server/test/main.lua b/server/test/main.lua
index fc9c99a5..05cc7ee6 100644
--- a/server/test/main.lua
+++ b/server/test/main.lua
@@ -23,6 +23,7 @@ local function main()
print(('测试[%s]用时[%.3f]'):format(name, os.clock() - clock))
end
+ test 'compile'
test 'definition'
test 'find_lib'