diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-01 23:06:56 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-02 13:39:30 -0400 |
| commit | bee42bc87a249bddcd7d13a7a7c257f0c7f78072 (patch) | |
| tree | 2cd547e34cb183e141cdd70026060bd90057db38 | |
| parent | bb3b211399ae0738c52acedae202565dacdadb4e (diff) | |
| download | vis-lspc-bee42bc87a249bddcd7d13a7a7c257f0c7f78072.tar.gz vis-lspc-bee42bc87a249bddcd7d13a7a7c257f0c7f78072.zip | |
fix conversion of last byte selections
If a language server sends a selection including the last byte, the line number will be one greater than the actual number of lines.
Those selections are not converted by our algorithm iterating all lines.
Add a special case to still convert them.
Fixes: f5c2043
| -rw-r--r-- | util.lua | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -242,6 +242,14 @@ function util.vis_sorted_selections_to_pos(file, sorted_selections) pos = pos + #line + 1 end + + -- Some language servers (pylsp) sends a range 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. + -- Add a special case for the selection of the first char after the last line. + if sel.line == line_count + 1 and sel.col == 1 then + table.insert(positions, pos) + end return positions end |
