diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 13:55:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-21 13:55:13 +0800 |
commit | e50a8947ab1c6016e3763e76e0c3bedfa1b9c002 (patch) | |
tree | ce7c6b45bec0118ff9b5ea918d8995695d8868bc /server/src/workspace.lua | |
parent | dba3476884f6ff53e0b0843fb77b42e5205161e1 (diff) | |
download | lua-language-server-e50a8947ab1c6016e3763e76e0c3bedfa1b9c002.zip |
支持dofile和loadfile
Diffstat (limited to 'server/src/workspace.lua')
-rw-r--r-- | server/src/workspace.lua | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 76b5af51..c2478e40 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -112,16 +112,7 @@ function mt:removeFile(uri) self.files[name] = nil end -function mt:searchPath(baseUri, str) - if self.loaded[str] then - return self.loaded[str] - end - str = str:gsub('%.', '/') - local searchers = {} - for i, luapath in ipairs(self.luapath) do - searchers[i] = luapath:gsub('%?', str):lower() - end - +function mt:findPath(baseUri, searchers) local results = {} for filename, uri in pairs(self.files) do for _, searcher in ipairs(searchers) do @@ -143,13 +134,44 @@ function mt:searchPath(baseUri, str) end) uri = results[1] end - self.loaded[str] = uri self.lsp:readText(uri, uriDecode(uri)) return uri end +function mt:searchPath(baseUri, str) + if self.searched[str] then + return self.searched[str] + end + str = str:gsub('%.', '/') + local searchers = {} + for i, luapath in ipairs(self.luapath) do + searchers[i] = luapath:gsub('%?', str):lower() + end + + local uri = self:findPath(baseUri, searchers) + if uri then + self.searched[str] = uri + end + return uri +end + +function mt:loadPath(baseUri, str) + if self.loaded[str] then + return self.loaded[str] + end + + local searchers = { str } + + local uri = self:findPath(baseUri, searchers) + if uri then + self.loaded[str] = uri + end + return uri +end + function mt:reset() - self.laoded = {} + self.searched = {} + self.loaded = {} self.lsp:reCompile() end @@ -158,6 +180,7 @@ return function (lsp, name, uri) lsp = lsp, name = name, files = {}, + searched = {}, loaded = {}, luapath = { '?.lua', |