summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/semantic-tokens.lua6
-rw-r--r--script/files.lua13
-rw-r--r--script/provider/provider.lua4
3 files changed, 13 insertions, 10 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index f310e3f1..47907d4d 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -188,10 +188,10 @@ local function buildTokens(uri, results)
local lastLine = 0
local lastStartChar = 0
for i, source in ipairs(results) do
- local startPos = files.position(uri, source.start)
- local finishPos = files.position(uri, source.finish)
+ local startPos = files.position(uri, source.start, 'left')
+ local finishPos = files.position(uri, source.finish, 'right')
local line = startPos.line
- local startChar = startPos.character - 1
+ local startChar = startPos.character
local deltaLine = line - lastLine
local deltaStartChar
if deltaLine == 0 then
diff --git a/script/files.lua b/script/files.lua
index c09cef37..da4b3b70 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -669,9 +669,9 @@ end
--- 将光标位置转化为 position
---@param uri uri
---@param offset integer
----@param isFinish? boolean
+---@param leftOrRight? '"left"'|'"right"'
---@return position
-function m.position(uri, offset, isFinish)
+function m.position(uri, offset, leftOrRight)
local file = m.getFile(uri)
local lines = m.getLines(uri)
local text = m.getText(uri)
@@ -683,7 +683,7 @@ function m.position(uri, offset, isFinish)
end
if file._diffInfo then
local start, finish = smerger.getOffsetBack(file._diffInfo, offset)
- if isFinish then
+ if leftOrRight == 'right' then
offset = finish
else
offset = start
@@ -701,6 +701,9 @@ function m.position(uri, offset, isFinish)
if row < 1 then
row = 1
end
+ if leftOrRight == 'left' then
+ ucol = ucol - 1
+ end
return {
line = row - 1,
character = ucol,
@@ -725,8 +728,8 @@ end
---@param offset2 integer
function m.range(uri, offset1, offset2)
local range = {
- start = m.position(uri, offset1 - 1, false),
- ['end'] = m.position(uri, offset2, true),
+ start = m.position(uri, offset1, 'left'),
+ ['end'] = m.position(uri, offset2, 'right'),
}
return range
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index e7c27d2c..b90e5a13 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -806,8 +806,8 @@ proto.on('textDocument/foldingRange', function (params)
local results = {}
for _, region in ipairs(regions) do
- local startLine = files.position(uri, region.start).line
- local endLine = files.position(uri, region.finish).line
+ local startLine = files.position(uri, region.start, 'left').line
+ local endLine = files.position(uri, region.finish, 'right').line
if not region.hideLastLine then
endLine = endLine - 1
end