diff options
Diffstat (limited to 'script/core/rangeformatting.lua')
-rw-r--r-- | script/core/rangeformatting.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/script/core/rangeformatting.lua b/script/core/rangeformatting.lua index 04a61bd9..7c3953e6 100644 --- a/script/core/rangeformatting.lua +++ b/script/core/rangeformatting.lua @@ -3,11 +3,15 @@ local log = require("log") local converter = require("proto.converter") return function(uri, range, options) + local state = files.getState(uri) + if not state then + return + end local suc, codeFormat = pcall(require, "code_format") if not suc then return end - local text = files.getOriginText(uri) + local text = state.originText local status, formattedText, startLine, endLine = codeFormat.range_format( uri, text, range.start.line, range["end"].line, options) @@ -21,8 +25,8 @@ return function(uri, range, options) return { { - start = converter.unpackPosition(uri, { line = startLine, character = 0 }), - finish = converter.unpackPosition(uri, { line = endLine + 1, character = 0 }), + start = converter.unpackPosition(state, { line = startLine, character = 0 }), + finish = converter.unpackPosition(state, { line = endLine + 1, character = 0 }), text = formattedText, } } |