summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-23 19:52:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-23 19:52:57 +0800
commitd86c2c46e8985da8899ae77d4c6f54f5b902cd71 (patch)
tree7d4adab36450f59cd3e9456086614120176731fc
parentb18329cea47f2de9c50abefecaccf248c16aa398 (diff)
downloadlua-language-server-d86c2c46e8985da8899ae77d4c6f54f5b902cd71.zip
change `config.lua` to `config,json`
#1607
-rw-r--r--main.lua3
-rw-r--r--meta/3rd/Cocos4.0/config.json7
-rw-r--r--meta/3rd/Cocos4.0/config.lua5
-rw-r--r--meta/3rd/Defold/config.json22
-rw-r--r--meta/3rd/Defold/config.lua20
-rw-r--r--meta/3rd/Jass/config.json6
-rw-r--r--meta/3rd/Jass/config.lua4
-rw-r--r--meta/3rd/OpenResty/config.json19
-rw-r--r--meta/3rd/OpenResty/config.lua19
-rw-r--r--meta/3rd/busted/config.json7
-rw-r--r--meta/3rd/busted/config.lua5
-rw-r--r--meta/3rd/example/config.json22
-rw-r--r--meta/3rd/example/config.lua20
-rw-r--r--meta/3rd/lfs/config.json9
-rw-r--r--meta/3rd/lfs/config.lua7
-rw-r--r--meta/3rd/love2d/config.json7
-rw-r--r--meta/3rd/love2d/config.lua5
-rw-r--r--meta/3rd/lovr/config.json7
-rw-r--r--meta/3rd/lovr/config.lua5
-rw-r--r--meta/3rd/luaecs/config.json4
-rw-r--r--meta/3rd/luaecs/config.lua2
-rw-r--r--meta/3rd/luassert/config.json3
-rw-r--r--meta/3rd/luassert/config.lua1
-rw-r--r--meta/3rd/skynet/config.json4
-rw-r--r--meta/3rd/skynet/config.lua2
-rw-r--r--script/library.lua18
-rw-r--r--script/meta/bee/filesystem.lua8
27 files changed, 134 insertions, 107 deletions
diff --git a/main.lua b/main.lua
index e26b6cbf..b724264b 100644
--- a/main.lua
+++ b/main.lua
@@ -16,9 +16,10 @@ local function getValue(value)
end
local function loadArgs()
+ ---@type string?
local lastKey
for _, v in ipairs(arg) do
- ---@type string
+ ---@type string?
local key, tail = v:match '^%-%-([%w_]+)(.*)$'
local value
if key then
diff --git a/meta/3rd/Cocos4.0/config.json b/meta/3rd/Cocos4.0/config.json
new file mode 100644
index 00000000..6330efb7
--- /dev/null
+++ b/meta/3rd/Cocos4.0/config.json
@@ -0,0 +1,7 @@
+{
+ "name": "Cocos",
+ "files": ["cocos"],
+ "config": {
+ "Lua.runtime.version": "LuaJIT"
+ }
+}
diff --git a/meta/3rd/Cocos4.0/config.lua b/meta/3rd/Cocos4.0/config.lua
deleted file mode 100644
index 85c24a08..00000000
--- a/meta/3rd/Cocos4.0/config.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-name = 'Cocos'
-files = {'cocos'}
-config = {
- ["Lua.runtime.version"] = "LuaJIT",
-}
diff --git a/meta/3rd/Defold/config.json b/meta/3rd/Defold/config.json
new file mode 100644
index 00000000..5e0ea371
--- /dev/null
+++ b/meta/3rd/Defold/config.json
@@ -0,0 +1,22 @@
+{
+ "name" : "Defold",
+ "files" : ["game.project", "*%.script", "*%.gui_script"],
+ "config" : {
+ "Lua.runtime.version" : "Lua 5.1",
+ "Lua.workspace.library" : [".internal"],
+ "Lua.workspace.ignoreDir" : [".internal"],
+ "Lua.diagnostics.globals" : [
+ "on_input",
+ "on_message",
+ "init",
+ "update",
+ "final"
+ ],
+ "files.associations" : {
+ "*.script" : "lua",
+ "*.gui_script" : "lua",
+ "*.render_script" : "lua",
+ "*.editor_script" : "lua"
+ }
+ }
+}
diff --git a/meta/3rd/Defold/config.lua b/meta/3rd/Defold/config.lua
deleted file mode 100644
index 9c457938..00000000
--- a/meta/3rd/Defold/config.lua
+++ /dev/null
@@ -1,20 +0,0 @@
-name = 'Defold'
-files = {'game.project', '*%.script', '*%.gui_script'}
-config = {
- ["Lua.runtime.version"] = "Lua 5.1",
- ["Lua.workspace.library"] = {".internal"},
- ["Lua.workspace.ignoreDir"] = {".internal"},
- ["Lua.diagnostics.globals"] = {
- "on_input",
- "on_message",
- "init",
- "update",
- "final",
- },
- ["files.associations"] = {
- ["*.script"] = "lua",
- ["*.gui_script"] = "lua",
- ["*.render_script"] = "lua",
- ["*.editor_script"] = "lua",
- }
-}
diff --git a/meta/3rd/Jass/config.json b/meta/3rd/Jass/config.json
new file mode 100644
index 00000000..512713f9
--- /dev/null
+++ b/meta/3rd/Jass/config.json
@@ -0,0 +1,6 @@
+{
+ "words" : ["jass%.common"],
+ "config" : {
+ "Lua.runtime.version": "Lua 5.3"
+ }
+}
diff --git a/meta/3rd/Jass/config.lua b/meta/3rd/Jass/config.lua
deleted file mode 100644
index 0ae56f49..00000000
--- a/meta/3rd/Jass/config.lua
+++ /dev/null
@@ -1,4 +0,0 @@
-words = {'jass%.common'}
-config = {
- ["Lua.runtime.version"] = "Lua 5.3",
-}
diff --git a/meta/3rd/OpenResty/config.json b/meta/3rd/OpenResty/config.json
new file mode 100644
index 00000000..91717cc9
--- /dev/null
+++ b/meta/3rd/OpenResty/config.json
@@ -0,0 +1,19 @@
+{
+ "files" : [
+ "resty/redis%.lua",
+ "lib/resty/.*%.lua",
+ "src/resty/.*%.lua",
+ "lib/ngx.*/.*%.lua",
+ "src/ngx.*/.*%.lua"
+ ],
+ "words" : [
+ "resty%.%w+",
+ "ngx%.%w+"
+ ],
+ "config" : {
+ "Lua.runtime.version" : "LuaJIT",
+ "Lua.diagnostics.globals" : [
+ "ngx"
+ ]
+ }
+}
diff --git a/meta/3rd/OpenResty/config.lua b/meta/3rd/OpenResty/config.lua
deleted file mode 100644
index 8ca0382f..00000000
--- a/meta/3rd/OpenResty/config.lua
+++ /dev/null
@@ -1,19 +0,0 @@
-files = {
- 'resty/redis%.lua',
- 'lib/resty/.*%.lua',
- 'src/resty/.*%.lua',
- 'lib/ngx.*/.*%.lua',
- 'src/ngx.*/.*%.lua',
-}
-
-words = {
- 'resty%.%w+',
- 'ngx%.%w+',
-}
-
-config = {
- ["Lua.runtime.version"] = "LuaJIT",
- ["Lua.diagnostics.globals"] = {
- "ngx",
- },
-}
diff --git a/meta/3rd/busted/config.json b/meta/3rd/busted/config.json
new file mode 100644
index 00000000..e547d0bd
--- /dev/null
+++ b/meta/3rd/busted/config.json
@@ -0,0 +1,7 @@
+{
+ "config": {
+ "Lua.workspace.library": [
+ "${3rd}/luassert/library"
+ ]
+ }
+}
diff --git a/meta/3rd/busted/config.lua b/meta/3rd/busted/config.lua
deleted file mode 100644
index a525a626..00000000
--- a/meta/3rd/busted/config.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-config = {
- ["Lua.workspace.library"] = {
- "${3rd}/luassert/library"
- }
-}
diff --git a/meta/3rd/example/config.json b/meta/3rd/example/config.json
new file mode 100644
index 00000000..415b92b2
--- /dev/null
+++ b/meta/3rd/example/config.json
@@ -0,0 +1,22 @@
+{
+ // if not set, the folder name will be used
+ "name" : "Example",
+ // list of matched words
+ "words" : ["thisIsAnExampleWord%.ifItExistsInFile%.thenTryLoadThisLibrary"],
+ // list or matched file names. `.lua`, `.dll` and `.so` only
+ "files" : ["thisIsAnExampleFile%.ifItExistsInWorkSpace%.thenTryLoadThisLibrary%.lua"],
+ // lsit of settings to be changed
+ "config" : {
+ "Lua.runtime.version" : "LuaJIT",
+ "Lua.diagnostics.globals" : [
+ "global1",
+ "global2"
+ ],
+ "Lua.runtime.special" : {
+ "include" : "require"
+ },
+ "Lua.runtime.builtin" : {
+ "io" : "disable"
+ }
+ }
+}
diff --git a/meta/3rd/example/config.lua b/meta/3rd/example/config.lua
deleted file mode 100644
index 20bae0f3..00000000
--- a/meta/3rd/example/config.lua
+++ /dev/null
@@ -1,20 +0,0 @@
--- if not set, the folder name will be used
-name = 'Example'
--- list of matched words
-words = {'thisIsAnExampleWord%.ifItExistsInFile%.thenTryLoadThisLibrary'}
--- list or matched file names. `.lua`, `.dll` and `.so` only
-files = {'thisIsAnExampleFile%.ifItExistsInWorkSpace%.thenTryLoadThisLibrary%.lua'}
--- lsit of settings to be changed
-config = {
- ["Lua.runtime.version"] = "LuaJIT",
- ["Lua.diagnostics.globals"] = {
- "global1",
- "global2",
- },
- ["Lua.runtime.special"] = {
- ["include"] = "require",
- },
- ["Lua.runtime.builtin"] = {
- ["io"] = "disable",
- },
-}
diff --git a/meta/3rd/lfs/config.json b/meta/3rd/lfs/config.json
new file mode 100644
index 00000000..3784f0c9
--- /dev/null
+++ b/meta/3rd/lfs/config.json
@@ -0,0 +1,9 @@
+{
+ "name" : "luafilesystem",
+ "words" : [ "require[%s%(\"']+lfs[%)\"']" ],
+ "config" : {
+ "Lua.diagnostics.globals" : [
+ "lfs"
+ ]
+ }
+}
diff --git a/meta/3rd/lfs/config.lua b/meta/3rd/lfs/config.lua
deleted file mode 100644
index b9e32610..00000000
--- a/meta/3rd/lfs/config.lua
+++ /dev/null
@@ -1,7 +0,0 @@
-name = 'luafilesystem'
-words = { 'require[%s%(\"\']+lfs[%)\"\']' }
-config = {
- ["Lua.diagnostics.globals"] = {
- "lfs",
- },
-}
diff --git a/meta/3rd/love2d/config.json b/meta/3rd/love2d/config.json
new file mode 100644
index 00000000..30862a97
--- /dev/null
+++ b/meta/3rd/love2d/config.json
@@ -0,0 +1,7 @@
+{
+ "name" : "LÖVE",
+ "words" : ["love%.%w+"],
+ "config" : {
+ "Lua.runtime.version" : "LuaJIT"
+ }
+}
diff --git a/meta/3rd/love2d/config.lua b/meta/3rd/love2d/config.lua
deleted file mode 100644
index 3ece274e..00000000
--- a/meta/3rd/love2d/config.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-name = 'LÖVE'
-words = {'love%.%w+'}
-config = {
- ["Lua.runtime.version"] = "LuaJIT",
-}
diff --git a/meta/3rd/lovr/config.json b/meta/3rd/lovr/config.json
new file mode 100644
index 00000000..d28e6bf9
--- /dev/null
+++ b/meta/3rd/lovr/config.json
@@ -0,0 +1,7 @@
+{
+ "name" : "LÖVR",
+ "words" : ["lovr%.%w+"],
+ "config" : {
+ "Lua.runtime.version" : "LuaJIT"
+ }
+}
diff --git a/meta/3rd/lovr/config.lua b/meta/3rd/lovr/config.lua
deleted file mode 100644
index 039bd0a0..00000000
--- a/meta/3rd/lovr/config.lua
+++ /dev/null
@@ -1,5 +0,0 @@
-name = 'LÖVR'
-words = {'lovr%.%w+'}
-config = {
- ["Lua.runtime.version"] = "LuaJIT",
-}
diff --git a/meta/3rd/luaecs/config.json b/meta/3rd/luaecs/config.json
new file mode 100644
index 00000000..21d5453c
--- /dev/null
+++ b/meta/3rd/luaecs/config.json
@@ -0,0 +1,4 @@
+{
+ "name" : "luaecs",
+ "words" : [ "ecs%.world()" ]
+}
diff --git a/meta/3rd/luaecs/config.lua b/meta/3rd/luaecs/config.lua
deleted file mode 100644
index 0f79fabf..00000000
--- a/meta/3rd/luaecs/config.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-name = "luaecs"
-words = { "ecs%.world()" }
diff --git a/meta/3rd/luassert/config.json b/meta/3rd/luassert/config.json
new file mode 100644
index 00000000..71e12fc6
--- /dev/null
+++ b/meta/3rd/luassert/config.json
@@ -0,0 +1,3 @@
+{
+ "words" : [ "require[%s%(\"']+luassert[%)\"']" ]
+}
diff --git a/meta/3rd/luassert/config.lua b/meta/3rd/luassert/config.lua
deleted file mode 100644
index f88cb12e..00000000
--- a/meta/3rd/luassert/config.lua
+++ /dev/null
@@ -1 +0,0 @@
-words = { "require[%s%(\"\']+luassert[%)\"\']" }
diff --git a/meta/3rd/skynet/config.json b/meta/3rd/skynet/config.json
new file mode 100644
index 00000000..17210c43
--- /dev/null
+++ b/meta/3rd/skynet/config.json
@@ -0,0 +1,4 @@
+{
+ "name" : "skynet",
+ "words" : [ "skynet.start" ]
+}
diff --git a/meta/3rd/skynet/config.lua b/meta/3rd/skynet/config.lua
deleted file mode 100644
index 79b0871b..00000000
--- a/meta/3rd/skynet/config.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-name = "skynet"
-words = { "skynet.start" }
diff --git a/script/library.lua b/script/library.lua
index aa686887..cddc8834 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -14,6 +14,7 @@ local encoder = require 'encoder'
local ws = require 'workspace.workspace'
local scope = require 'workspace.scope'
local inspect = require 'inspect'
+local jsonc = require 'jsonc'
local m = {}
@@ -275,15 +276,18 @@ end
---@param libraryDir fs.path
local function loadSingle3rdConfig(libraryDir)
- local configText = fsu.loadFile(libraryDir / 'config.lua')
+ local path = libraryDir / 'config.json'
+ local configText = fsu.loadFile(path)
if not configText then
return nil
end
- local env = setmetatable({}, { __index = _G })
- assert(load(configText, '@' .. libraryDir:string(), 't', env))()
-
- local cfg = {}
+ local suc, cfg = xpcall(jsonc.decode, function (err)
+ log.error('Decode config.json failed at:', libraryDir:string(), err)
+ end, configText)
+ if not suc then
+ return nil
+ end
cfg.path = libraryDir:filename():string()
cfg.name = cfg.name or cfg.path
@@ -292,10 +296,6 @@ local function loadSingle3rdConfig(libraryDir)
cfg.plugin = true
end
- for k, v in pairs(env) do
- cfg[k] = v
- end
-
if cfg.words then
for i, word in ipairs(cfg.words) do
cfg.words[i] = '()' .. word .. '()'
diff --git a/script/meta/bee/filesystem.lua b/script/meta/bee/filesystem.lua
index 1f62e78c..6190dac7 100644
--- a/script/meta/bee/filesystem.lua
+++ b/script/meta/bee/filesystem.lua
@@ -44,7 +44,7 @@ local copy_options
fs.copy_options = copy_options
----@param path string
+---@param path string|fs.path
---@return fs.path
function fs.path(path)
end
@@ -99,7 +99,7 @@ end
---@param source fs.path
---@param target fs.path
----@param options? `fs.copy_options.overwrite_existing`
+---@param options? integer | `fs.copy_options.overwrite_existing`
function fs.copy_file(source, target, options)
end
@@ -108,4 +108,8 @@ end
function fs.rename(oldPath, newPath)
end
+---@return fs.path
+function fs.current_path()
+end
+
return fs