summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2022-01-20 01:48:41 +0800
committerCppCXY <812125110@qq.com>2022-01-20 01:48:41 +0800
commit5888272ccf7fc0b542edf88d4d8a38636351b42b (patch)
tree70458098581c4fe9964ef154f9922d1aa3aff536 /script/core
parent8e41ce1b39044742a6aaadfd16976654666d67ca (diff)
downloadlua-language-server-5888272ccf7fc0b542edf88d4d8a38636351b42b.zip
提供范围格式化
Diffstat (limited to 'script/core')
-rw-r--r--script/core/rangeformatting.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/script/core/rangeformatting.lua b/script/core/rangeformatting.lua
new file mode 100644
index 00000000..b66f0fbd
--- /dev/null
+++ b/script/core/rangeformatting.lua
@@ -0,0 +1,26 @@
+local code_format = require "code_format"
+local files = require("files")
+local log = require("log")
+local converter = require("proto.converter")
+
+return function(uri, range)
+ local text = files.getText(uri)
+ local status, formattedText, startLine, endLine = code_format.range_format(
+ uri, text, range.start.line, range["end"].line)
+
+ if not status then
+ if formattedText ~= nil then
+ log.error(formattedText)
+ end
+
+ return
+ end
+
+ return {
+ {
+ start = converter.unpackPosition(uri, { line = startLine, character = 0 }),
+ finish = converter.unpackPosition(uri, { line = endLine + 1, character = 0 }),
+ text = formattedText,
+ }
+ }
+end