summaryrefslogtreecommitdiff
path: root/script/method/initialized.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/method/initialized.lua')
-rw-r--r--script/method/initialized.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/script/method/initialized.lua b/script/method/initialized.lua
new file mode 100644
index 00000000..d84a2159
--- /dev/null
+++ b/script/method/initialized.lua
@@ -0,0 +1,69 @@
+local rpc = require 'rpc'
+local workspace = require 'workspace'
+
+local function initAfterConfig(lsp, firstScope)
+ if firstScope then
+ lsp.workspace = workspace(lsp, firstScope.name)
+ lsp.workspace:init(firstScope.uri)
+ end
+ -- 必须动态注册的事件:
+ rpc:request('client/registerCapability', {
+ registrations = {
+ -- 监视文件变化
+ {
+ id = '0',
+ method = 'workspace/didChangeWatchedFiles',
+ registerOptions = {
+ watchers = {
+ {
+ globPattern = '**/',
+ kind = 1 | 2 | 4,
+ }
+ },
+ },
+ },
+ -- 配置变化
+ {
+ id = '1',
+ method = 'workspace/didChangeConfiguration',
+ }
+ }
+ }, function ()
+ log.debug('client/registerCapability Success!')
+ end)
+end
+
+return function (lsp)
+ -- 请求工作目录
+ rpc:request('workspace/workspaceFolders', nil, function (folders)
+ local firstScope
+ if folders then
+ firstScope = folders[1]
+ end
+ local uri = firstScope and firstScope.uri
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ scopeUri = uri,
+ section = 'Lua',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.associations',
+ },
+ {
+ scopeUri = uri,
+ section = 'files.exclude',
+ }
+ },
+ }, function (configs)
+ lsp:onUpdateConfig(configs[1], {
+ associations = configs[2],
+ exclude = configs[3],
+ })
+ initAfterConfig(lsp, firstScope)
+ end)
+ end)
+ return true
+end