summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-18 17:03:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-18 17:03:05 +0800
commitc6cac231b097f0a0aaea76e03bb50bdbdd363809 (patch)
treee51ba03f013fcb40b994737f48ed60f10622b1ce /script
parent2f984c1a2baf162f72240ca7b7f3f530459a71f4 (diff)
parent9e8901c5d09b4537a5741fd20dc5cc77c5a23dce (diff)
downloadlua-language-server-c6cac231b097f0a0aaea76e03bb50bdbdd363809.zip
Merge branch 'client-test'
Diffstat (limited to 'script')
-rw-r--r--script/client.lua1
-rw-r--r--script/files.lua22
-rw-r--r--script/library.lua7
-rw-r--r--script/proto/proto.lua40
-rw-r--r--script/provider/completion.lua2
-rw-r--r--script/workspace/loading.lua77
-rw-r--r--script/workspace/workspace.lua4
7 files changed, 91 insertions, 62 deletions
diff --git a/script/client.lua b/script/client.lua
index 8dec85be..4f7658e8 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -241,7 +241,6 @@ local function tryModifyRC(uri, finalChanges, create)
return false
end
local workspace = require 'workspace'
- local loader = require 'config.loader'
local path = workspace.getAbsolutePath(uri, '.luarc.json')
if not path then
return false
diff --git a/script/files.lua b/script/files.lua
index 3ec942cb..009beba4 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -12,6 +12,7 @@ local guide = require 'parser.guide'
local smerger = require 'string-merger'
local progress = require "progress"
local encoder = require 'encoder'
+local scope = require 'workspace.scope'
---@class files
local m = {}
@@ -23,7 +24,6 @@ m.assocMatcher = nil
function m.reset()
m.openMap = {}
- m.libraryMap = {}
m.fileMap = {}
m.dllMap = {}
m.visible = {}
@@ -110,12 +110,28 @@ end
--- 是否是库文件
function m.isLibrary(uri)
- return m.libraryMap[uri] ~= nil
+ for _, scp in ipairs(scope.folders) do
+ local map = scp:get 'libraryMap'
+ if map and map[uri] ~= nil then
+ return true
+ end
+ end
+ local map = scope.fallback:get 'libraryMap'
+ if map and map[uri] ~= nil then
+ return true
+ end
+ return false
end
--- 获取库文件的根目录
function m.getLibraryPath(uri)
- return m.libraryMap[uri]
+ for _, scp in ipairs(scope.folders) do
+ local map = scp:get 'libraryMap'
+ if map and map[uri] ~= nil then
+ return scp.uri
+ end
+ end
+ return nil
end
---@param scp scope
diff --git a/script/library.lua b/script/library.lua
index 1f2e920e..7925d414 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -323,7 +323,12 @@ local function apply3rd(uri, cfg, onlyMemory)
local changes = {}
if cfg.configs then
for _, change in ipairs(cfg.configs) do
- changes[#changes+1] = change
+ changes[#changes+1] = {
+ key = change.key,
+ action = change.action,
+ value = change.value,
+ uri = uri,
+ }
end
end
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 2b9a6963..4ba99b88 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -92,7 +92,12 @@ function m.awaitRequest(name, params)
params = params,
}
local result, error = await.wait(function (resume)
- m.waiting[id] = resume
+ m.waiting[id] = {
+ id = id,
+ method = name,
+ params = params,
+ resume = resume,
+ }
end)
if error then
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
@@ -110,14 +115,19 @@ function m.request(name, params, callback)
--log.debug('Request', name, #buf)
logSend(buf)
io.write(buf)
- m.waiting[id] = function (result, error)
- if error then
- log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
- end
- if callback then
- callback(result)
+ m.waiting[id] = {
+ id = id,
+ method = name,
+ params = params,
+ resume = function (result, error)
+ if error then
+ log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
+ end
+ if callback then
+ callback(result)
+ end
end
- end
+ }
end
local secretOption = {
@@ -137,6 +147,9 @@ function m.doMethod(proto)
logRecieve(proto)
local method, optional = m.getMethodName(proto)
local abil = m.ability[method]
+ if proto.id then
+ m.holdon[proto.id] = proto
+ end
if not abil then
if not optional then
log.warn('Recieved unknown proto: ' .. method)
@@ -146,9 +159,6 @@ function m.doMethod(proto)
end
return
end
- if proto.id then
- m.holdon[proto.id] = proto
- end
await.call(function () ---@async
--log.debug('Start method:', method)
if proto.id then
@@ -192,17 +202,17 @@ end
function m.doResponse(proto)
logRecieve(proto)
local id = proto.id
- local resume = m.waiting[id]
- if not resume then
+ local waiting = m.waiting[id]
+ if not waiting then
log.warn('Response id not found: ' .. util.dump(proto))
return
end
m.waiting[id] = nil
if proto.error then
- resume(nil, proto.error)
+ waiting.resume(nil, proto.error)
return
end
- resume(proto.result)
+ waiting.resume(proto.result)
end
function m.listen()
diff --git a/script/provider/completion.lua b/script/provider/completion.lua
index 9bcccc66..3c0c82d7 100644
--- a/script/provider/completion.lua
+++ b/script/provider/completion.lua
@@ -30,6 +30,7 @@ local function enable(uri)
end
nonil.enable()
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
+ nonil.disable()
return
end
nonil.disable()
@@ -55,6 +56,7 @@ local function disable(uri)
end
nonil.enable()
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
+ nonil.disable()
return
end
nonil.disable()
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 50a48038..19fe0728 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -4,7 +4,8 @@ local await = require 'await'
local files = require 'files'
local config = require 'config.config'
local client = require 'client'
-local pub = require 'pub.pub'
+local util = require 'utility'
+local furi = require 'file-uri'
---@class workspace.loading
---@field scp scope
@@ -69,50 +70,48 @@ function mt:loadFile(uri, libraryUri)
end
self.max = self.max + 1
self:update()
- pub.task('loadFile', uri, function (content)
- self._stash[#self._stash+1] = function ()
- self.read = self.read + 1
- self:update()
- if not content then
- return
- end
- if self._cache[uri] then
- return
- end
- log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
- self._cache[uri] = true
- files.setText(uri, content, false)
- files.addRef(uri)
- if libraryUri then
- log.info('++++As library of:', libraryUri)
- files.setLibraryUri(self.scp, uri, libraryUri)
- end
+ self._stash[#self._stash+1] = function ()
+ local content = util.loadFile(furi.decode(uri))
+ self.read = self.read + 1
+ self:update()
+ if not content then
+ return
+ end
+ if self._cache[uri] then
+ return
end
- end)
+ log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
+ self._cache[uri] = true
+ files.setText(uri, content, false)
+ files.addRef(uri)
+ if libraryUri then
+ log.info('++++As library of:', libraryUri)
+ files.setLibraryUri(self.scp, uri, libraryUri)
+ end
+ end
elseif files.isDll(uri) then
self.max = self.max + 1
self:update()
- pub.task('loadFile', uri, function (content)
- self._stash[#self._stash+1] = function ()
- self.read = self.read + 1
- self:update()
- if not content then
- return
- end
- if self._cache[uri] then
- return
- end
- log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
- self._cache[uri] = true
- files.saveDll(uri, content)
- files.addRef(uri)
- if libraryUri then
- log.info('++++As library of:', libraryUri)
- end
+ self._stash[#self._stash+1] = function ()
+ local content = util.loadFile(furi.decode(uri))
+ self.read = self.read + 1
+ self:update()
+ if not content then
+ return
+ end
+ if self._cache[uri] then
+ return
end
- end)
- await.delay()
+ log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
+ self._cache[uri] = true
+ files.saveDll(uri, content)
+ files.addRef(uri)
+ if libraryUri then
+ log.info('++++As library of:', libraryUri)
+ end
+ end
end
+ await.delay()
end
function mt:loadStashed()
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index c11d3e78..159f397b 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -55,6 +55,7 @@ function m.reset()
---@type scope[]
m.folders = {}
m.rootUri = nil
+ m.inited = false
end
m.reset()
@@ -385,9 +386,6 @@ function m.reload(scp)
if not m.inited then
return
end
- if TEST then
- return
- end
---@async
await.call(function ()
m.awaitReload(scp)