summaryrefslogtreecommitdiff
path: root/script/provider/provider.lua
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2022-01-19 16:10:51 +0800
committerCppCXY <812125110@qq.com>2022-01-19 16:10:51 +0800
commit53b4c03fb2e7aa4969b5a1fd712686bad9548131 (patch)
tree9025b760ab47191bcffee8abfe20aaf2c1d5af60 /script/provider/provider.lua
parent2f984c1a2baf162f72240ca7b7f3f530459a71f4 (diff)
downloadlua-language-server-53b4c03fb2e7aa4969b5a1fd712686bad9548131.zip
提交代码格式化
Diffstat (limited to 'script/provider/provider.lua')
-rw-r--r--script/provider/provider.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 4b22cb47..63450f59 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -101,6 +101,19 @@ m.register 'initialize' {
workspace.create(params.rootUri)
end
+ if params.initializationOptions then
+ if params.initializationOptions.editorConfigFiles then
+ local code_format = require "code_format"
+ for _, config in pairs(params.initializationOptions.editorConfigFiles) do
+ local status, err = code_format.update_config(1, config.workspace, config.path)
+
+ if not status and err ~= nil then
+ log.error(err)
+ end
+ end
+ end
+ end
+
return {
capabilities = cap.getIniter(),
serverInfo = {
@@ -911,6 +924,49 @@ m.register '$/status/click' {
end
}
+m.register 'textDocument/formatting' {
+ abortByFileUpdate = true,
+ ---@async
+ function(params)
+ local uri = files.getRealUri(params.textDocument.uri)
+ workspace.awaitReady(uri)
+ local _<close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
+
+ if not files.exists(uri) then
+ return nil
+ end
+
+ local core = require 'core.formatting'
+ local edits = core(uri)
+ if not edits or #edits == 0 then
+ return nil
+ end
+
+ local results = {}
+ for i, edit in ipairs(edits) do
+ results[i] = {
+ range = converter.packRange(uri, edit.start, edit.finish),
+ newText = edit.text,
+ }
+ end
+
+ return results
+ end
+}
+
+m.register 'config/editorconfig/update' {
+ abortByFileUpdate = true,
+ ---@async
+ function(params)
+ local code_format = require "code_format"
+ local status, err = code_format.update_config(params.type, params.source.workspace, params.source.path)
+
+ if not status and err ~= nil then
+ log.error(err)
+ end
+ end
+}
+
m.register 'textDocument/onTypeFormatting' {
abortByFileUpdate = true,
---@async