summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2022-01-20 10:58:49 +0800
committerCppCXY <812125110@qq.com>2022-01-20 10:58:49 +0800
commit4a1314d098a18b7a525b59e76f5c0055c2f2905f (patch)
treecf094cd5f997cb7651cf83ca130c37e98cf3e7a2 /script/core
parent53d65c5783ca01a6e8b7bbf33804a154922cf6db (diff)
downloadlua-language-server-4a1314d098a18b7a525b59e76f5c0055c2f2905f.zip
不改type-formatting了
Diffstat (limited to 'script/core')
-rw-r--r--script/core/type-formatting.lua77
1 files changed, 26 insertions, 51 deletions
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua
index af27fe06..cc305982 100644
--- a/script/core/type-formatting.lua
+++ b/script/core/type-formatting.lua
@@ -1,9 +1,6 @@
local files = require 'files'
local lookBackward = require 'core.look-backward'
local guide = require "parser.guide"
-local code_format = require "code_format"
-local log = require "log"
-local converter = require "proto.converter"
local function insertIndentation(uri, position, edits)
local text = files.getText(uri)
@@ -50,56 +47,34 @@ local function checkSplitOneLine(results, uri, position, ch)
return
end
- -- local fPosition, fSymbol = findForward(uri, position, 'end', '}')
- -- if not fPosition then
- -- return
- -- end
- -- local bPosition = findBackward(uri, position, 'then', 'do', ')', '{')
- -- if not bPosition then
- -- return
- -- end
- -- local edits = {}
- -- edits[#edits+1] = {
- -- start = bPosition,
- -- finish = position,
- -- text = '\n\t',
- -- }
- -- edits[#edits+1] = {
- -- start = position,
- -- finish = fPosition + 1,
- -- text = '',
- -- }
- -- edits[#edits+1] = {
- -- start = fPosition + 1,
- -- finish = fPosition + 1,
- -- text = '\n' .. fSymbol:sub(1, 1)
- -- }
- -- insertIndentation(uri, bPosition, edits)
- -- for _, edit in ipairs(edits) do
- -- results[#results+1] = edit
- -- end
- local pos = converter.packPosition(uri, position)
- local text = files.getText(uri)
- local status, formattedText, startLine, endLine = code_format.range_format(
- uri, text, pos.line - 1, pos.line)
-
- if not status then
- if formattedText ~= nil then
- log.error(formattedText)
- end
-
+ local fPosition, fSymbol = findForward(uri, position, 'end', '}')
+ if not fPosition then
return
end
-
- table.insert(results, {
- {
- start = converter.unpackPosition(uri, { line = startLine, character = 0 }),
- finish = converter.unpackPosition(uri, { line = endLine + 1, character = 0 }),
- text = formattedText,
- }
- })
-
-
+ local bPosition = findBackward(uri, position, 'then', 'do', ')', '{')
+ if not bPosition then
+ return
+ end
+ local edits = {}
+ edits[#edits+1] = {
+ start = bPosition,
+ finish = position,
+ text = '\n\t',
+ }
+ edits[#edits+1] = {
+ start = position,
+ finish = fPosition + 1,
+ text = '',
+ }
+ edits[#edits+1] = {
+ start = fPosition + 1,
+ finish = fPosition + 1,
+ text = '\n' .. fSymbol:sub(1, 1)
+ }
+ insertIndentation(uri, bPosition, edits)
+ for _, edit in ipairs(edits) do
+ results[#results+1] = edit
+ end
end
return function (uri, position, ch)