summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-23 16:30:37 +0800
committerGitHub <noreply@github.com>2022-07-23 16:30:37 +0800
commit082b0bf826021ecbce94ab126fa1e9f44888d42c (patch)
treebb7b5894f1eb9ac06762c3c122fb48e62c043a3f
parent05a098f7ed731b2a3a6d068d5e9d7dfeacc67be0 (diff)
parentce3b062dd0c6ca5dde0e464ff0d0ac142ba197bf (diff)
downloadlua-language-server-082b0bf826021ecbce94ab126fa1e9f44888d42c.zip
Merge pull request #1376 from Nexela/pluginDev
Plugin enchancements
-rw-r--r--doc/en-us/config.md18
-rw-r--r--doc/pt-br/config.md22
-rw-r--r--doc/zh-cn/config.md22
-rw-r--r--doc/zh-tw/config.md18
-rw-r--r--locale/en-us/setting.lua2
-rw-r--r--locale/pt-br/setting.lua2
-rw-r--r--locale/zh-cn/setting.lua2
-rw-r--r--locale/zh-tw/setting.lua2
-rw-r--r--script/config/template.lua1
-rw-r--r--script/plugin.lua14
10 files changed, 94 insertions, 9 deletions
diff --git a/doc/en-us/config.md b/doc/en-us/config.md
index e854ed51..6ac60483 100644
--- a/doc/en-us/config.md
+++ b/doc/en-us/config.md
@@ -1411,6 +1411,22 @@ string
""
```
+# runtime.pluginArgs
+
+Arguments to pass to to the runtime plug.
+
+## type
+
+```ts
+array<string>
+```
+
+ ## default
+
+```json
+[]
+```
+
# runtime.special
The custom global variables are regarded as some special built-in variables, and the language server will provide special support
@@ -1823,4 +1839,4 @@ Array<string>
```jsonc
[]
-``` \ No newline at end of file
+```
diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md
index 60e04f72..57b6ccc1 100644
--- a/doc/pt-br/config.md
+++ b/doc/pt-br/config.md
@@ -653,7 +653,7 @@ object<string, string>
```jsonc
{
/*
- 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
+ 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
*/
"ambiguity-1": "Any",
"assign-type-mismatch": "Opened",
@@ -789,7 +789,7 @@ object<string, string>
```jsonc
{
/*
- 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
+ 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
*/
"ambiguity-1": "Warning",
"assign-type-mismatch": "Warning",
@@ -1411,6 +1411,22 @@ string
""
```
+# runtime.pluginArgs
+
+Arguments to pass to to the runtime plug.
+
+## type
+
+```ts
+array<string>
+```
+
+ ## default
+
+```json
+[]
+```
+
# runtime.special
The custom global variables are regarded as some special built-in variables, and the language server will provide special support
@@ -1823,4 +1839,4 @@ Array<string>
```jsonc
[]
-``` \ No newline at end of file
+```
diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md
index 177096e5..5c2edf82 100644
--- a/doc/zh-cn/config.md
+++ b/doc/zh-cn/config.md
@@ -653,7 +653,7 @@ object<string, string>
```jsonc
{
/*
- 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
+ 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
*/
"ambiguity-1": "Any",
"assign-type-mismatch": "Opened",
@@ -788,7 +788,7 @@ object<string, string>
```jsonc
{
/*
- 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
+ 优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
*/
"ambiguity-1": "Warning",
"assign-type-mismatch": "Warning",
@@ -1410,6 +1410,22 @@ string
""
```
+# runtime.pluginArgs
+
+Arguments to pass to to the runtime plug.
+
+## type
+
+```ts
+array<string>
+```
+
+ ## default
+
+```json
+[]
+```
+
# runtime.special
将自定义全局变量视为一些特殊的内置变量,语言服务将提供特殊的支持。
@@ -1822,4 +1838,4 @@ Array<string>
```jsonc
[]
-``` \ No newline at end of file
+```
diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md
index acfc9d99..16caa386 100644
--- a/doc/zh-tw/config.md
+++ b/doc/zh-tw/config.md
@@ -1410,6 +1410,22 @@ string
""
```
+# runtime.pluginArgs
+
+Arguments to pass to to the runtime plug.
+
+## type
+
+```ts
+array<string>
+```
+
+ ## default
+
+```json
+[]
+```
+
# runtime.special
將自訂全域變數視為一些特殊的內建變數,語言伺服將提供特殊的支援。
@@ -1822,4 +1838,4 @@ Array<string>
```jsonc
[]
-``` \ No newline at end of file
+```
diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua
index f35edac4..49c79b1c 100644
--- a/locale/en-us/setting.lua
+++ b/locale/en-us/setting.lua
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
"Supports non-standard symbols. Make sure that your runtime environment supports these symbols."
config.runtime.plugin =
"Plugin path. Please read [wiki](https://github.com/sumneko/lua-language-server/wiki/Plugin) to learn more."
+config.runtime.pluginArgs =
+"Additional arguments for the plugin."
config.runtime.fileEncoding =
"File encoding. The `ansi` option is only available under the `Windows` platform."
config.runtime.builtin =
diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua
index b673e90f..71eb57e2 100644
--- a/locale/pt-br/setting.lua
+++ b/locale/pt-br/setting.lua
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol = -- TODO: need translate!
"Supports non-standard symbols. Make sure that your runtime environment supports these symbols."
config.runtime.plugin = -- TODO: need translate!
"Plugin path. Please read [wiki](https://github.com/sumneko/lua-language-server/wiki/Plugin) to learn more."
+config.runtime.pluginArgs = -- TODO: need translate!
+"Additional arguments for the plugin."
config.runtime.fileEncoding = -- TODO: need translate!
"File encoding. The `ansi` option is only available under the `Windows` platform."
config.runtime.builtin = -- TODO: need translate!
diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua
index 5fa4bf8b..ea83567a 100644
--- a/locale/zh-cn/setting.lua
+++ b/locale/zh-cn/setting.lua
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
"支持非标准的符号。请务必确认你的运行环境支持这些符号。"
config.runtime.plugin =
"插件路径,请查阅[文档](https://github.com/sumneko/lua-language-server/wiki/Plugin)了解用法。"
+config.runtime.pluginArgs = -- TODO: need translate!
+"Additional arguments for the plugin."
config.runtime.fileEncoding =
"文件编码,`ansi` 选项只在 `Windows` 平台下有效。"
config.runtime.builtin =
diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua
index 9ff8e1a7..60bf52b5 100644
--- a/locale/zh-tw/setting.lua
+++ b/locale/zh-tw/setting.lua
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
"支援非標準的符號。請務必確認你的執行環境支援這些符號。"
config.runtime.plugin =
"延伸模組路徑,請查閱[文件](https://github.com/sumneko/lua-language-server/wiki/Plugin)瞭解用法。"
+config.runtime.pluginArgs = -- TODO: need translate!
+"Additional arguments for the plugin."
config.runtime.fileEncoding =
"檔案編碼,選項 `ansi` 只在 `Windows` 平台下有效。"
config.runtime.builtin =
diff --git a/script/config/template.lua b/script/config/template.lua
index 6a009a66..60f3dbca 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -222,6 +222,7 @@ local template = {
'continue',
}),
['Lua.runtime.plugin'] = Type.String,
+ ['Lua.runtime.pluginArgs'] = Type.Array(Type.String),
['Lua.runtime.fileEncoding'] = Type.String >> 'utf8' << {
'utf8',
'ansi',
diff --git a/script/plugin.lua b/script/plugin.lua
index 2a5ee27f..81e17d8b 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -5,6 +5,7 @@ local lang = require 'language'
local await = require 'await'
local scope = require 'workspace.scope'
local ws = require 'workspace'
+local fs = require 'bee.filesystem'
---@class plugin
local m = {}
@@ -86,8 +87,19 @@ local function initPlugin(uri)
if not pluginPath then
return
end
+
+ --Adding the plugins path to package.path allows for requires in files
+ --to find files relative to itself.
+ local oldPath = package.path
+ local path = fs.path(pluginPath):parent_path() / '?.lua'
+ if not package.path:find(path:string(), 1, true) then
+ package.path = package.path .. ';' .. path:string()
+ end
+
local pluginLua = util.loadFile(pluginPath)
if not pluginLua then
+ log.warn('plugin not found:', pluginPath)
+ package.path = oldPath
return
end
@@ -103,7 +115,7 @@ local function initPlugin(uri)
if not client.isVSCode() and not checkTrustLoad(scp) then
return
end
- local suc, err = xpcall(f, log.error, f)
+ local suc, err = xpcall(f, log.error, f, config.get(scp.uri, 'Lua.runtime.pluginArgs'))
if not suc then
m.showError(scp, err)
return