Skip to content

Plugin enchancements #1376

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion doc/en-us/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1823,4 +1839,4 @@ Array<string>

```jsonc
[]
```
```
22 changes: 19 additions & 3 deletions doc/pt-br/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1823,4 +1839,4 @@ Array<string>

```jsonc
[]
```
```
22 changes: 19 additions & 3 deletions doc/zh-cn/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1410,6 +1410,22 @@ string
""
```

# runtime.pluginArgs

Arguments to pass to to the runtime plug.

## type

```ts
array<string>
```

## default

```json
[]
```

# runtime.special

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

```jsonc
[]
```
```
18 changes: 17 additions & 1 deletion doc/zh-tw/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,22 @@ string
""
```

# runtime.pluginArgs

Arguments to pass to to the runtime plug.

## type

```ts
array<string>
```

## default

```json
[]
```

# runtime.special

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

```jsonc
[]
```
```
2 changes: 2 additions & 0 deletions locale/en-us/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-br/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-cn/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-tw/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 13 additions & 1 deletion script/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down