summaryrefslogtreecommitdiff
path: root/script/core/rangeformatting.lua
blob: f64e9cda3b2eb2a58797154520e8c5e150dc0f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local codeFormat = require("code_format")
local files = require("files")
local log = require("log")
local converter = require("proto.converter")

return function(uri, range, options)
    local text = files.getOriginText(uri)
    local status, formattedText, startLine, endLine = codeFormat.range_format(
        uri, text, range.start.line, range["end"].line, options)

    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