summaryrefslogtreecommitdiff
path: root/script/plugin.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-07 20:32:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-07 20:32:44 +0800
commit428d32055f1b7b5bce8a0fd75eeedf4114f8a7ec (patch)
tree228cebacdc651b297be60b48a7fe6555021101a3 /script/plugin.lua
parentf1b5ad2ee92ea9d1656a82fb4dbd0be32cb91ea8 (diff)
downloadlua-language-server-428d32055f1b7b5bce8a0fd75eeedf4114f8a7ec.zip
cleanup
Diffstat (limited to 'script/plugin.lua')
-rw-r--r--script/plugin.lua41
1 files changed, 12 insertions, 29 deletions
diff --git a/script/plugin.lua b/script/plugin.lua
index af86cea5..15c7c311 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -1,11 +1,8 @@
local config = require 'config'
-local fs = require 'bee.filesystem'
-local fsu = require 'fs-utility'
-local await = require "await"
+local util = require 'utility'
---@class plugin
local m = {}
-m.waitingReady = {}
function m.dispatch(event, ...)
if not m.interface then
@@ -28,49 +25,35 @@ function m.isReady()
return m.interface ~= nil
end
-function m.awaitReady()
- if m.isReady() then
- return
+local function resetFiles()
+ local files = require 'files'
+ for uri in files.eachFile() do
+ files.resetText(uri)
end
- await.wait(function (waker)
- m.waitingReady[#m.waitingReady+1] = waker
- end)
end
function m.init()
local ws = require 'workspace'
m.interface = {}
- local _ <close> = function ()
- local waiting = m.waitingReady
- m.waitingReady = {}
- for _, waker in ipairs(waiting) do
- waker()
- end
- end
-
- if not config.get 'Lua.runtime.plugin' or config.get 'Lua.runtime.plugin' == '' then
+ local pluginPath = ws.getAbsolutePath(config.get 'Lua.runtime.plugin')
+ log.info('plugin path:', pluginPath)
+ if not pluginPath then
return
end
-
- local pluginPath = fs.path(config.get 'Lua.runtime.plugin')
- if pluginPath:is_relative() then
- if not ws.path then
- return
- end
- pluginPath = fs.path(ws.path) / pluginPath
- end
- local pluginLua = fsu.loadFile(pluginPath)
+ local pluginLua = util.loadFile(pluginPath)
if not pluginLua then
return
end
local env = setmetatable(m.interface, { __index = _ENV })
- local f, err = load(pluginLua, '@'..pluginPath:string(), "t", env)
+ local f, err = load(pluginLua, '@'..pluginPath, "t", env)
if not f then
log.error(err)
return
end
xpcall(f, log.error, f)
+
+ resetFiles()
end
return m