summaryrefslogtreecommitdiff
path: root/script/provider
diff options
context:
space:
mode:
Diffstat (limited to 'script/provider')
-rw-r--r--script/provider/capability.lua1
-rw-r--r--script/provider/provider.lua23
2 files changed, 24 insertions, 0 deletions
diff --git a/script/provider/capability.lua b/script/provider/capability.lua
index 76cadc0d..43464483 100644
--- a/script/provider/capability.lua
+++ b/script/provider/capability.lua
@@ -92,6 +92,7 @@ function m.getIniter()
firstTriggerCharacter = '\n',
moreTriggerCharacter = nil, -- string[]
},
+ documentFormattingProvider = true
--documentOnTypeFormattingProvider = {
-- firstTriggerCharacter = '}',
--},
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index ac16c4e3..42c0af0d 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -801,6 +801,29 @@ proto.on('textDocument/onTypeFormatting', function (params)
return results
end)
+proto.on('textDocument/formatting', function (params)
+ workspace.awaitReady()
+ local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
+ local uri = params.textDocument.uri
+ if not files.exists(uri) then
+ return nil
+ end
+ local core = require 'core.formatting'
+
+ local status, range, formattedText = core(uri)
+ if status then
+ local results = {
+ {
+ range = range,
+ newText = formattedText,
+ }
+ }
+ return results
+ end
+
+ return nil
+end)
+
proto.on('$/cancelRequest', function (params)
proto.close(params.id, define.ErrorCodes.RequestCancelled)
end)