summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-08 15:49:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-08 15:49:10 +0800
commit4876958951dff23ed234523d89b47a854e88acea (patch)
tree5166c29516c525de2d69d8ff03a2c40bc5e0ec99
parent9c21a7a38a6b3f79f8d74cf9ce45ecb431c8ef9a (diff)
downloadlua-language-server-4876958951dff23ed234523d89b47a854e88acea.zip
also supports filename
-rw-r--r--meta/3rd/OpenResty/config.lua24
-rw-r--r--meta/3rd/example/config.lua4
-rw-r--r--script/files.lua5
-rw-r--r--script/library.lua47
-rw-r--r--script/workspace/workspace.lua2
5 files changed, 74 insertions, 8 deletions
diff --git a/meta/3rd/OpenResty/config.lua b/meta/3rd/OpenResty/config.lua
new file mode 100644
index 00000000..6cf1d8df
--- /dev/null
+++ b/meta/3rd/OpenResty/config.lua
@@ -0,0 +1,24 @@
+-- list of matched words
+words = {}
+-- list or matched file names
+files = {}
+-- lsit of settings to be changed
+configs = {
+ {
+ key = 'Lua.runtime.version',
+ action = 'set',
+ value = 'LuaJIT',
+ },
+ {
+ key = 'Lua.diagnostics.globals',
+ action = 'add',
+ value = 'global1',
+ }
+}
+for _, name in ipairs {'global2', 'global3', 'global4'} do
+ configs[#configs+1] = {
+ key = 'Lua.diagnostics.globals',
+ action = 'add',
+ value = name,
+ }
+end
diff --git a/meta/3rd/example/config.lua b/meta/3rd/example/config.lua
index 7bf8e04a..d19edd66 100644
--- a/meta/3rd/example/config.lua
+++ b/meta/3rd/example/config.lua
@@ -1,7 +1,7 @@
-- list of matched words
words = {'thisIsAnExampleWord%.ifItExistsInFile%.thenTryLoadThisLibrary'}
--- list or matched file names
-files = {'thisIsAnExampleFile%.ifItExistsInWorkSpace%.thenTryLoadThisLibrary'}
+-- list or matched file names. `.lua`, `.dll` and `.so` only
+files = {'thisIsAnExampleFile%.ifItExistsInWorkSpace%.thenTryLoadThisLibrary%.lua'}
-- lsit of settings to be changed
configs = {
{
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