summaryrefslogtreecommitdiff
path: root/script/provider
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2021-10-28 14:32:06 +0800
committerCppCXY <812125110@qq.com>2021-10-28 14:32:06 +0800
commit1aa5d27dc035e8281127288b2edc7740f7f9229f (patch)
tree05a1f4bb2feb80eb4a3432ba76755986e4ba6f0c /script/provider
parent594b502c7cbfb9d354e204a182c96bea1bf287c5 (diff)
downloadlua-language-server-1aa5d27dc035e8281127288b2edc7740f7f9229f.zip
格式化相关
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)