diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 15:00:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 15:00:50 +0800 |
commit | 5c9b1b467af1636ea21a9bd3d398e220790eea54 (patch) | |
tree | 8a834bcb5e9c8e6c32f118c23fbeafcaf01630ab /script/proto | |
parent | 0a60aa17c240d4fb080b091891f659a9d74aeffd (diff) | |
download | lua-language-server-5c9b1b467af1636ea21a9bd3d398e220790eea54.zip |
cleanup
Diffstat (limited to 'script/proto')
-rw-r--r-- | script/proto/converter.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/script/proto/converter.lua b/script/proto/converter.lua new file mode 100644 index 00000000..4b4b9f5d --- /dev/null +++ b/script/proto/converter.lua @@ -0,0 +1,50 @@ +local guide = require 'parser.guide' + +local m = {} + + +---@alias position {line: integer, character: integer} + +---@param uri uri +---@param pos integer +---@return position +function m.packPosition(uri, pos) + local row, col = guide.rowColOf(pos) + return { + line = row, + character = col, + } +end + +---@param uri uri +---@param position position +function m.unpackPosition(uri, position) + local pos = guide.positionOf(position.line, position.character) + return pos +end + +---@alias range {start: position, end: position} + +---@param uri uri +---@param start integer +---@param finish integer +---@return range +function m.packRange(uri, start, finish) + local range = { + start = m.packPosition(uri, start), + ['end'] = m.packPosition(uri, finish), + } + return range +end + +---@param uri uri +---@param range range +---@return integer start +---@return integer finish +function m.unpackRange(uri, range) + local start = m.unpackPosition(uri, range.start) + local finish = m.unpackPosition(uri, range['end']) + return start, finish +end + +return m |