diff options
author | Nicholas Dunn <nexela@gmail.com> | 2022-07-23 02:45:09 -0400 |
---|---|---|
committer | Nicholas Dunn <nexela@gmail.com> | 2022-07-23 02:45:09 -0400 |
commit | ce3b062dd0c6ca5dde0e464ff0d0ac142ba197bf (patch) | |
tree | bb7b5894f1eb9ac06762c3c122fb48e62c043a3f /script | |
parent | 05a098f7ed731b2a3a6d068d5e9d7dfeacc67be0 (diff) | |
download | lua-language-server-ce3b062dd0c6ca5dde0e464ff0d0ac142ba197bf.zip |
Plugin enchancements
Adds config.runtime.plugingArgs
Adds pluginPath to package.path. Closes #1297
Adds log.warn() when specified plugin can't be found
Possible Changelog entry:
```txt
* `NEW` `Lua.runtime.pluginArgs`
* `CHG` add plugin path in package.path
```
Diffstat (limited to 'script')
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | script/plugin.lua | 14 |
2 files changed, 14 insertions, 1 deletions
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 |