summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-26 13:14:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-26 13:14:44 +0800
commit097e9c06c9a78d3ae845a7eec694a2dbe99161b0 (patch)
treed25835e3e6d7ddd79fff66bd011a8f3e6af230f9 /server
parent2304c9722132da29ff98c01de18db7daef5e8aac (diff)
downloadlua-language-server-097e9c06c9a78d3ae845a7eec694a2dbe99161b0.zip
整理一下代码
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/vm.lua31
-rw-r--r--server/src/workspace.lua5
2 files changed, 25 insertions, 11 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 4f6b4952..1b098785 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -508,11 +508,6 @@ function mt:getRequire(strValue, destVM)
mainValue.uri = destVM.uri
end
- -- 支持 require 'xxx' 的转到定义
- local strSource = strValue.source
- self.results.sources[strSource] = strValue
- strValue.uri = destVM.uri
-
return mainValue
end
@@ -522,11 +517,6 @@ function mt:getLoadFile(strValue, destVM)
-- loadfile 的返回值就是对方的主函数
local mainValue = readOnly(main)
- -- 支持 loadfile 'xxx.lua' 的转到定义
- local strSource = strValue.source
- self.results.sources[strSource] = strValue
- strValue.uri = destVM.uri
-
return mainValue
end
@@ -536,6 +526,11 @@ function mt:tryRequireOne(strValue, mode)
end
local str = strValue.value
if type(str) == 'string' then
+ -- 支持 require 'xxx' 的转到定义
+ local strSource = strValue.source
+ self.results.sources[strSource] = strValue
+ strValue.isRequire = true
+
local uri
if mode == 'require' then
uri = self.lsp.workspace:searchPath(self.uri, str)
@@ -547,6 +542,8 @@ function mt:tryRequireOne(strValue, mode)
if not uri then
return nil
end
+
+ strValue.uri = uri
-- 如果取不到VM(不编译),则做个标记,之后再取一次
local destVM = self.lsp:getVM(uri)
self.lsp:compileChain(self.uri, uri)
@@ -577,7 +574,11 @@ function mt:callRequire(func, values)
self:setFunctionReturn(func, 1, value)
return
else
- local requireValue = self:tryRequireOne(values[1], 'require') or self:createValue('boolean')
+ local requireValue = self:tryRequireOne(values[1], 'require')
+ if not requireValue then
+ requireValue = self:createValue('boolean')
+ requireValue.isRequire = true
+ end
self:setFunctionReturn(func, 1, requireValue)
end
end
@@ -591,6 +592,10 @@ function mt:callLoadFile(func, values)
return
end
local requireValue = self:tryRequireOne(values[1], 'loadfile')
+ if not requireValue then
+ requireValue = self:createValue('any')
+ requireValue.isRequire = true
+ end
self:setFunctionReturn(func, 1, requireValue)
end
@@ -603,6 +608,10 @@ function mt:callDoFile(func, values)
return
end
local requireValue = self:tryRequireOne(values[1], 'dofile')
+ if not requireValue then
+ requireValue = self:createValue('any')
+ requireValue.isRequire = true
+ end
self:setFunctionReturn(func, 1, requireValue)
end
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index ba324aad..9e9c03d2 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -97,9 +97,14 @@ function mt:init(rootUri)
self.files[name] = self:uriEncode(path)
end
self:reset()
+ self._complete = true
end)
end
+function mt:isComplete()
+ return not not self._complete
+end
+
function mt:addFile(uri)
if uri:sub(-4) == '.lua' then
local name = self:uriDecode(uri):string():lower()