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

return function(uri)
    local text = files.getText(uri)
    local ast = files.getState(uri)
    local status, formattedText = code_format.format(uri, text)

    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