summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meta/3rd/Jass/config.lua2
-rw-r--r--meta/3rd/example/config.lua2
-rw-r--r--script/library.lua72
-rw-r--r--script/provider/provider.lua1
-rw-r--r--test.lua1
5 files changed, 69 insertions, 9 deletions
diff --git a/meta/3rd/Jass/config.lua b/meta/3rd/Jass/config.lua
index 5e641990..dd37d66c 100644
--- a/meta/3rd/Jass/config.lua
+++ b/meta/3rd/Jass/config.lua
@@ -2,7 +2,7 @@
words = {'jass.common'}
configs = {
{
- name = 'Lua.runtime.version'
+ name = 'Lua.runtime.version',
type = 'set',
value = 'Lua 5.3',
},
diff --git a/meta/3rd/example/config.lua b/meta/3rd/example/config.lua
index 7b964d54..17b6ab06 100644
--- a/meta/3rd/example/config.lua
+++ b/meta/3rd/example/config.lua
@@ -16,7 +16,7 @@ configs = {
}
}
for _, name in ipairs {'global2', 'global3', 'global4'} do
- config[#config+1] = {
+ configs[#configs+1] = {
name = 'Lua.diagnostics.globals',
type = 'add',
value = name,
diff --git a/script/library.lua b/script/library.lua
index a46416c7..6e40fb58 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -6,6 +6,7 @@ local client = require 'client'
local lloader = require 'locale-loader'
local fsu = require 'fs-utility'
local define = require "proto.define"
+local files = require 'files'
local m = {}
@@ -206,6 +207,9 @@ local function initBuiltIn()
end
--log.debug('metaLang:', util.dump(metaLang))
+ if m.metaPath == metaPath:string() then
+ return
+ end
m.metaPath = metaPath:string()
m.metaPaths = {}
fs.create_directories(metaPath)
@@ -229,15 +233,73 @@ local function initBuiltIn()
fsu.fileSync(out, metaPath)
end
-function m.init()
- initBuiltIn()
+local function loadSingle3rdConfig(libraryDir)
+ local configText = fsu.loadFile(libraryDir / 'config.lua')
+ if not configText then
+ return nil
+ end
+
+ local env = setmetatable({}, { __index = _G })
+ assert(load(configText, '@' .. libraryDir:string(), 't', env))
+
+ local cfg = {}
+
+ cfg.name = libraryDir:filename():string()
+
+ local pluginPath = libraryDir / 'plugin.lua'
+ if fs.exists(pluginPath) then
+ cfg.plugin = pluginPath:string()
+ end
+
+ for k, v in pairs(env) do
+ cfg[k] = v
+ end
+
+ return cfg
+end
+
+local function load3rdConfig()
+ local thirdDir = ROOT / 'meta' / '3rd'
+ if not fs.is_directory(thirdDir) then
+ return
+ end
+ local configs = {}
+ for libraryDir in thirdDir:list_directory() do
+ local suc, res = xpcall(loadSingle3rdConfig, log.error, libraryDir)
+ if suc then
+ configs[#configs+1] = res
+ end
+ end
+ return configs
+end
+
+local function check3rdByWords(configs)
+
+end
+
+local thirdConfigs
+local function check3rd(uri)
+ if thirdConfigs == nil then
+ thirdConfigs = load3rdConfig() or false
+ end
+ if not thirdConfigs then
+ return
+ end
+ if files.isLua(uri) then
+ local text = files.getUri(uri)
+ check3rdByWords(text, thirdConfigs)
+ end
end
config.watch(function (key, value, oldValue)
if key:find '^Lua.runtime' then
- if value ~= oldValue then
- initBuiltIn()
- end
+ initBuiltIn()
+ end
+end)
+
+files.watch(function (ev, uri)
+ if ev == 'update' then
+ check3rd(uri)
end
end)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 138ee1b5..16710ff3 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -40,7 +40,6 @@ end
proto.on('initialize', function (params)
client.init(params)
- library.init()
workspace.init(params.rootUri)
return {
capabilities = cap.getIniter(),
diff --git a/test.lua b/test.lua
index a6e00c8f..ae2748e0 100644
--- a/test.lua
+++ b/test.lua
@@ -38,7 +38,6 @@ local function loadDocMetas()
local fsu = require 'fs-utility'
local client = require 'client'
client.client 'vscode'
- library.init()
for _, path in ipairs(library.metaPaths) do
local uri = furi.encode(path)
files.setText(uri, fsu.loadFile(path))