summaryrefslogtreecommitdiff
path: root/script/core/formatting.lua
blob: b52854a43583c6583e9fe439fa2464a4ccc6bba0 (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
local codeFormat = require("code_format")
local files      = require("files")
local log        = require("log")

return function(uri, options)
    local text = files.getOriginText(uri)
    local ast = files.getState(uri)
    local status, formattedText = codeFormat.format(uri, text, options)

    if not status then
        if formattedText ~= nil then
            log.error(formattedText)
        end

        return
    end

    return {
        {
            start = ast.ast.start,
            finish = ast.ast.finish,
            text = formattedText,
        }
    }
end