aboutsummaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
authorFlorian Fischer <gitlab@muhq.space>2025-07-27 14:55:37 +0000
committerFlorian Fischer <gitlab@muhq.space>2025-07-27 14:55:37 +0000
commitd9c6b0f60dae559eca22b0d0750c2327d11e11ef (patch)
tree681d3e2557544e7008dba8644a98f0f37a1f2b37 /util.lua
parentbb3b211399ae0738c52acedae202565dacdadb4e (diff)
parent6a4755ec3ee4c8214d76bf8b0461534490df47dd (diff)
downloadvis-lspc-d9c6b0f60dae559eca22b0d0750c2327d11e11ef.tar.gz
vis-lspc-d9c6b0f60dae559eca22b0d0750c2327d11e11ef.zip
Merge branch 'fix_last_char_range' into 'main'
fix conversion of last newline selections Closes #52 See merge request muhq/vis-lspc!63
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util.lua b/util.lua
index 2b090b2..3d10e95 100644
--- a/util.lua
+++ b/util.lua
@@ -242,6 +242,18 @@ function util.vis_sorted_selections_to_pos(file, sorted_selections)
pos = pos + #line + 1
end
+
+ -- Some language servers (pylsp) send ranges including the first character after the last line.
+ -- e.g. [{"line":1, "col":1}, {"line":#lines+1, "col":1}]
+ -- But this selection can not be handled by iterating all lines.
+ -- Special case ranges ensing after the last line.
+ -- Additionaly the start and end can overlap.
+ -- Gopls sends the range [{"line":1, "col":1}, {"line":1, "col":1}] when editing an empty file.
+ while sel and sel.line == line_count + 1 and sel.col == 1 do
+ table.insert(positions, pos)
+ sel_i = sel_i + 1
+ sel = sorted_selections[sel_i]
+ end
return positions
end