diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-08 15:49:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-08 15:49:10 +0800 |
commit | 4876958951dff23ed234523d89b47a854e88acea (patch) | |
tree | 5166c29516c525de2d69d8ff03a2c40bc5e0ec99 /script | |
parent | 9c21a7a38a6b3f79f8d74cf9ce45ecb431c8ef9a (diff) | |
download | lua-language-server-4876958951dff23ed234523d89b47a854e88acea.zip |
also supports filename
Diffstat (limited to 'script')
-rw-r--r-- | script/files.lua | 5 | ||||
-rw-r--r-- | script/library.lua | 47 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 2 |
3 files changed, 48 insertions, 6 deletions
diff --git a/script/files.lua b/script/files.lua index 1d20a3be..c0e8f707 100644 --- a/script/files.lua +++ b/script/files.lua @@ -400,7 +400,9 @@ end function m.compileState(uri, text) local ws = require 'workspace' - if not m.isOpen(uri) and #text >= config.get 'Lua.workspace.preloadFileSize' * 1000 then + if not m.isOpen(uri) + and not m.isLibrary(uri) + and #text >= config.get 'Lua.workspace.preloadFileSize' * 1000 then if not m.notifyCache['preloadFileSize'] then m.notifyCache['preloadFileSize'] = {} m.notifyCache['skipLargeFileCount'] = 0 @@ -857,6 +859,7 @@ function m.saveDll(uri, content) end m.dllMap[luri] = file + m.onWatch('dll', uri) end --- diff --git a/script/library.lua b/script/library.lua index 49e02d04..21004ab6 100644 --- a/script/library.lua +++ b/script/library.lua @@ -1,4 +1,5 @@ local fs = require 'bee.filesystem' +local plat = require 'bee.platform' local config = require 'config' local util = require 'utility' local lang = require 'language' @@ -325,6 +326,9 @@ local function askFor3rd(cfg) end local function check3rdByWords(text, configs) + if hasAsked then + return + end await.call(function () for _, cfg in ipairs(configs) do if cfg.words then @@ -340,6 +344,36 @@ local function check3rdByWords(text, configs) end) end +local function check3rdByFileName(uri, configs) + if hasAsked then + return + end + local ws = require 'workspace' + local path = ws.getRelativePath(uri) + if not path then + return + end + if plat.OS == 'Windows' then + path = path:lower() + end + await.call(function () + for _, cfg in ipairs(configs) do + if cfg.files then + for _, filename in ipairs(cfg.files) do + await.delay() + if plat.OS == 'Windows' then + filename = filename:lower() + end + if path:match(filename) then + askFor3rd(cfg) + return + end + end + end + end + end) +end + local thirdConfigs local hasCheckedUri = {} local function check3rd(uri) @@ -355,11 +389,13 @@ local function check3rd(uri) if not thirdConfigs then return end - if not hasCheckedUri[uri] - and files.isLua(uri) then + if not hasCheckedUri[uri] then hasCheckedUri[uri] = true - local text = files.getText(uri) - check3rdByWords(text, thirdConfigs) + if files.isLua(uri) then + local text = files.getText(uri) + check3rdByWords(text, thirdConfigs) + end + check3rdByFileName(uri, thirdConfigs) end end @@ -370,7 +406,8 @@ config.watch(function (key, value, oldValue) end) files.watch(function (ev, uri) - if ev == 'update' then + if ev == 'update' + or ev == 'dll' then check3rd(files.asKey(uri)) end end) diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 211c982c..fcfde027 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -466,6 +466,8 @@ function m.getAbsolutePath(path) return path end +---@param uri uri +---@return string function m.getRelativePath(uri) local path = furi.decode(uri) if not m.path then |