From 88d38d4f360346e7d3cb4bb2687d01b1adac7a7e Mon Sep 17 00:00:00 2001 From: sumneko Date: Sat, 16 Oct 2021 16:48:50 +0800 Subject: fix `json to lua` --- script/core/command/jsonToLua.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/script/core/command/jsonToLua.lua b/script/core/command/jsonToLua.lua index 8a493b5e..6aecee2c 100644 --- a/script/core/command/jsonToLua.lua +++ b/script/core/command/jsonToLua.lua @@ -5,13 +5,17 @@ local proto = require 'proto' local define = require 'proto.define' local lang = require 'language' local converter = require 'proto.converter' +local guide = require 'parser.guide' return function (data) - local text = files.getText(data.uri) + local state = files.getState(data.uri) + local text = files.getText(data.uri) if not text then return end - local jsonStr = text:sub(data.start, data.finish) + local start = guide.positionToOffset(state, data.start) + local finish = guide.positionToOffset(state, data.finish) + local jsonStr = text:sub(start + 1, finish) local suc, res = pcall(json.decode, jsonStr) if not suc then proto.notify('window/showMessage', { -- cgit v1.2.3