diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-09 14:20:16 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-09 14:20:16 +0800 |
commit | 3858df0c6ff9811d112757efbf2de31e06b77dc8 (patch) | |
tree | 7d581838e504684f8e99202fe9d8d401fa0a6591 /server | |
parent | 264e332acd1dbfb91c3f6633f6b48f3e4119f832 (diff) | |
download | lua-language-server-3858df0c6ff9811d112757efbf2de31e06b77dc8.zip |
默认不加载自定义库中的全局变量
Diffstat (limited to 'server')
-rw-r--r-- | server/locale/en-US/libs/@lua/package.lni | 2 | ||||
-rw-r--r-- | server/locale/en-US/script.lni | 2 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 2 | ||||
-rw-r--r-- | server/src/config.lua | 1 | ||||
-rw-r--r-- | server/src/core/library.lua | 8 | ||||
-rw-r--r-- | server/src/method/textDocument/codeAction.lua | 26 |
6 files changed, 38 insertions, 3 deletions
diff --git a/server/locale/en-US/libs/@lua/package.lni b/server/locale/en-US/libs/@lua/package.lni index 3b482ae9..1c8b633a 100644 --- a/server/locale/en-US/libs/@lua/package.lni +++ b/server/locale/en-US/libs/@lua/package.lni @@ -26,4 +26,4 @@ description = 'A table used by `require` to control how to load modules.' description = 'Searches for the given `name` in the given `path`.' [seeall] -describing = 'Sets a metatable for `module` with its `__index` field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function `module` . +describing = 'Sets a metatable for `module` with its `__index` field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function `module` .' diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index 38f571c3..d70492c8 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -54,12 +54,14 @@ ACTION_REMOVE_SPACE = 'Clear all postemptive spaces.' ACTION_ADD_SEMICOLON = 'Add `;` .' ACTION_ADD_BRACKETS = 'Add brackets.' ACTION_RUNTIME_VERSION = 'Change runtime version to {} .' +ACTION_OPEN_LIBRARY = 'Load globals from {} .' COMMAND_DISABLE_DIAG = 'Disable diagnostics' COMMAND_MARK_GLOBAL = 'Mark defined global' COMMAND_REMOVE_SPACE = 'Clear all postemptive spaces' COMMAND_ADD_BRACKETS = 'Add brackets' COMMAND_RUNTIME_VERSION = 'Change runtime version' +COMMAND_OPEN_LIBRARY = 'Load globals from 3rd library' DEBUG_MEMORY_LEAK = "{} I'm sorry for the serious memory leak. The language service will be restarted soon." DEBUG_RESTART_NOW = 'Restart now' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index a5b61475..bac2a238 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -54,12 +54,14 @@ ACTION_REMOVE_SPACE = '清除所有后置空格。' ACTION_ADD_SEMICOLON = '添加 `;` 。' ACTION_ADD_BRACKETS = '添加括号。' ACTION_RUNTIME_VERSION = '修改运行版本为 {} 。' +ACTION_OPEN_LIBRARY = '加载 {} 中的全局变量。' COMMAND_DISABLE_DIAG = '禁用诊断' COMMAND_MARK_GLOBAL = '标记全局变量' COMMAND_REMOVE_SPACE = '清除所有后置空格' COMMAND_ADD_BRACKETS = '添加括号' COMMAND_RUNTIME_VERSION = '修改运行版本' +COMMAND_OPEN_LIBRARY = '加载第三方库中的全局变量' DEBUG_MEMORY_LEAK = '{} 很抱歉发生了严重的内存泄漏,语言服务即将重启。' DEBUG_RESTART_NOW = '立即重启' diff --git a/server/src/config.lua b/server/src/config.lua index 0979289c..79a7d98d 100644 --- a/server/src/config.lua +++ b/server/src/config.lua @@ -41,6 +41,7 @@ end local Template = { runtime = { version = {'Lua 5.3', String}, + library = {{}, Str2Hash ';'}, }, diagnostics = { globals = {{}, Str2Hash ';'}, diff --git a/server/src/core/library.lua b/server/src/core/library.lua index d9ac969a..be1d74b8 100644 --- a/server/src/core/library.lua +++ b/server/src/core/library.lua @@ -117,7 +117,13 @@ local function insertCustom(tbl, key, value, libName) end local function isEnableGlobal(libName) - return libName:sub(1, 1) == '@' + if config.config.runtime.library[libName] then + return true + end + if libName:sub(1, 1) == '@' then + return true + end + return false end local function mergeSource(alllibs, name, lib, libName) diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua index 36b8d90f..1d85235a 100644 --- a/server/src/method/textDocument/codeAction.lua +++ b/server/src/method/textDocument/codeAction.lua @@ -37,7 +37,6 @@ local function addGlobal(name, callback) } end - local function changeVersion(version, callback) callback { title = lang.script('ACTION_RUNTIME_VERSION', version), @@ -56,6 +55,24 @@ local function changeVersion(version, callback) } end +local function openCustomLibrary(libName, callback) + callback { + title = lang.script('ACTION_OPEN_LIBRARY', libName), + kind = 'quickfix', + command = { + title = lang.script.COMMAND_OPEN_LIBRARY, + command = 'config', + arguments = { + { + key = {'runtime', 'library'}, + action = 'add', + value = libName, + } + } + }, + } +end + local function solveUndefinedGlobal(lsp, uri, data, callback) local vm, lines, text = lsp:getVM(uri) if not vm then @@ -74,6 +91,13 @@ local function solveUndefinedGlobal(lsp, uri, data, callback) changeVersion(version, callback) end end + + local customLibrary = library.custom[name] + if customLibrary then + for _, libName in ipairs(customLibrary) do + openCustomLibrary(libName, callback) + end + end end local function solveLowercaseGlobal(lsp, uri, data, callback) |