Skip to content

Commit 082b0bf

Browse files
authored
Merge pull request #1376 from Nexela/pluginDev
Plugin enchancements
2 parents 05a098f + ce3b062 commit 082b0bf

File tree

10 files changed

+94
-9
lines changed

10 files changed

+94
-9
lines changed

doc/en-us/config.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,22 @@ string
14111411
""
14121412
```
14131413

1414+
# runtime.pluginArgs
1415+
1416+
Arguments to pass to to the runtime plug.
1417+
1418+
## type
1419+
1420+
```ts
1421+
array<string>
1422+
```
1423+
1424+
## default
1425+
1426+
```json
1427+
[]
1428+
```
1429+
14141430
# runtime.special
14151431

14161432
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>
18231839

18241840
```jsonc
18251841
[]
1826-
```
1842+
```

doc/pt-br/config.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ object<string, string>
653653
```jsonc
654654
{
655655
/*
656-
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
656+
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
657657
*/
658658
"ambiguity-1": "Any",
659659
"assign-type-mismatch": "Opened",
@@ -789,7 +789,7 @@ object<string, string>
789789
```jsonc
790790
{
791791
/*
792-
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
792+
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
793793
*/
794794
"ambiguity-1": "Warning",
795795
"assign-type-mismatch": "Warning",
@@ -1411,6 +1411,22 @@ string
14111411
""
14121412
```
14131413

1414+
# runtime.pluginArgs
1415+
1416+
Arguments to pass to to the runtime plug.
1417+
1418+
## type
1419+
1420+
```ts
1421+
array<string>
1422+
```
1423+
1424+
## default
1425+
1426+
```json
1427+
[]
1428+
```
1429+
14141430
# runtime.special
14151431

14161432
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>
18231839

18241840
```jsonc
18251841
[]
1826-
```
1842+
```

doc/zh-cn/config.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ object<string, string>
653653
```jsonc
654654
{
655655
/*
656-
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
656+
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
657657
*/
658658
"ambiguity-1": "Any",
659659
"assign-type-mismatch": "Opened",
@@ -788,7 +788,7 @@ object<string, string>
788788
```jsonc
789789
{
790790
/*
791-
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
791+
优先级歧义,如:`num or 0 + 1`,推测用户的实际期望为 `(num or 0) + 1`
792792
*/
793793
"ambiguity-1": "Warning",
794794
"assign-type-mismatch": "Warning",
@@ -1410,6 +1410,22 @@ string
14101410
""
14111411
```
14121412

1413+
# runtime.pluginArgs
1414+
1415+
Arguments to pass to to the runtime plug.
1416+
1417+
## type
1418+
1419+
```ts
1420+
array<string>
1421+
```
1422+
1423+
## default
1424+
1425+
```json
1426+
[]
1427+
```
1428+
14131429
# runtime.special
14141430

14151431
将自定义全局变量视为一些特殊的内置变量,语言服务将提供特殊的支持。
@@ -1822,4 +1838,4 @@ Array<string>
18221838

18231839
```jsonc
18241840
[]
1825-
```
1841+
```

doc/zh-tw/config.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,22 @@ string
14101410
""
14111411
```
14121412

1413+
# runtime.pluginArgs
1414+
1415+
Arguments to pass to to the runtime plug.
1416+
1417+
## type
1418+
1419+
```ts
1420+
array<string>
1421+
```
1422+
1423+
## default
1424+
1425+
```json
1426+
[]
1427+
```
1428+
14131429
# runtime.special
14141430

14151431
將自訂全域變數視為一些特殊的內建變數,語言伺服將提供特殊的支援。
@@ -1822,4 +1838,4 @@ Array<string>
18221838

18231839
```jsonc
18241840
[]
1825-
```
1841+
```

locale/en-us/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
2626
"Supports non-standard symbols. Make sure that your runtime environment supports these symbols."
2727
config.runtime.plugin =
2828
"Plugin path. Please read [wiki](https://github.com/sumneko/lua-language-server/wiki/Plugin) to learn more."
29+
config.runtime.pluginArgs =
30+
"Additional arguments for the plugin."
2931
config.runtime.fileEncoding =
3032
"File encoding. The `ansi` option is only available under the `Windows` platform."
3133
config.runtime.builtin =

locale/pt-br/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol = -- TODO: need translate!
2626
"Supports non-standard symbols. Make sure that your runtime environment supports these symbols."
2727
config.runtime.plugin = -- TODO: need translate!
2828
"Plugin path. Please read [wiki](https://github.com/sumneko/lua-language-server/wiki/Plugin) to learn more."
29+
config.runtime.pluginArgs = -- TODO: need translate!
30+
"Additional arguments for the plugin."
2931
config.runtime.fileEncoding = -- TODO: need translate!
3032
"File encoding. The `ansi` option is only available under the `Windows` platform."
3133
config.runtime.builtin = -- TODO: need translate!

locale/zh-cn/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
2626
"支持非标准的符号。请务必确认你的运行环境支持这些符号。"
2727
config.runtime.plugin =
2828
"插件路径,请查阅[文档](https://github.com/sumneko/lua-language-server/wiki/Plugin)了解用法。"
29+
config.runtime.pluginArgs = -- TODO: need translate!
30+
"Additional arguments for the plugin."
2931
config.runtime.fileEncoding =
3032
"文件编码,`ansi` 选项只在 `Windows` 平台下有效。"
3133
config.runtime.builtin =

locale/zh-tw/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ config.runtime.nonstandardSymbol =
2626
"支援非標準的符號。請務必確認你的執行環境支援這些符號。"
2727
config.runtime.plugin =
2828
"延伸模組路徑,請查閱[文件](https://github.com/sumneko/lua-language-server/wiki/Plugin)瞭解用法。"
29+
config.runtime.pluginArgs = -- TODO: need translate!
30+
"Additional arguments for the plugin."
2931
config.runtime.fileEncoding =
3032
"檔案編碼,選項 `ansi` 只在 `Windows` 平台下有效。"
3133
config.runtime.builtin =

script/config/template.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ local template = {
222222
'continue',
223223
}),
224224
['Lua.runtime.plugin'] = Type.String,
225+
['Lua.runtime.pluginArgs'] = Type.Array(Type.String),
225226
['Lua.runtime.fileEncoding'] = Type.String >> 'utf8' << {
226227
'utf8',
227228
'ansi',

script/plugin.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local lang = require 'language'
55
local await = require 'await'
66
local scope = require 'workspace.scope'
77
local ws = require 'workspace'
8+
local fs = require 'bee.filesystem'
89

910
---@class plugin
1011
local m = {}
@@ -86,8 +87,19 @@ local function initPlugin(uri)
8687
if not pluginPath then
8788
return
8889
end
90+
91+
--Adding the plugins path to package.path allows for requires in files
92+
--to find files relative to itself.
93+
local oldPath = package.path
94+
local path = fs.path(pluginPath):parent_path() / '?.lua'
95+
if not package.path:find(path:string(), 1, true) then
96+
package.path = package.path .. ';' .. path:string()
97+
end
98+
8999
local pluginLua = util.loadFile(pluginPath)
90100
if not pluginLua then
101+
log.warn('plugin not found:', pluginPath)
102+
package.path = oldPath
91103
return
92104
end
93105

@@ -103,7 +115,7 @@ local function initPlugin(uri)
103115
if not client.isVSCode() and not checkTrustLoad(scp) then
104116
return
105117
end
106-
local suc, err = xpcall(f, log.error, f)
118+
local suc, err = xpcall(f, log.error, f, config.get(scp.uri, 'Lua.runtime.pluginArgs'))
107119
if not suc then
108120
m.showError(scp, err)
109121
return

0 commit comments

Comments
 (0)