diff options
| author | Florian Fischer <gitlab@muhq.space> | 2025-07-27 14:55:37 +0000 |
|---|---|---|
| committer | Florian Fischer <gitlab@muhq.space> | 2025-07-27 14:55:37 +0000 |
| commit | d9c6b0f60dae559eca22b0d0750c2327d11e11ef (patch) | |
| tree | 681d3e2557544e7008dba8644a98f0f37a1f2b37 | |
| parent | bb3b211399ae0738c52acedae202565dacdadb4e (diff) | |
| parent | 6a4755ec3ee4c8214d76bf8b0461534490df47dd (diff) | |
| download | vis-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
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | init.lua | 34 | ||||
| -rw-r--r-- | lspc.lua | 2 | ||||
| -rw-r--r-- | util.lua | 12 |
4 files changed, 33 insertions, 16 deletions
@@ -120,6 +120,7 @@ Available options are: * `autostart = true` - try to start a language server in WIN_OPEN * `menu_cmd = 'fzf' or 'vis-menu'` - program to prompt for user choices * `confirm_cmd = 'vis-menu'` - program to prompt for user confirmation +* `autoconfirm_edits = false` - apply workspaceEdits without user confirmation * `ls_map` - a table mapping `vis` syntax names to language server configurations * `highlight_diagnostics = 'line'` - highlight the `range` or `line`number of available diagnostics * `diagnostic_style_id = nil` - vis style id used to highlight diagnostics, win.STYLE_LEXER_MAX is used by default @@ -487,27 +487,29 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) end end - -- generate change summary - local summary = '--- workspace edit summary ---\n' - for uri, edits in pairs(file_edits) do - local path = uri_to_path(uri) - summary = summary .. path .. ':\n' - for i, edit in ipairs(edits) do - summary = summary .. '\t' .. i .. '.: ' .. lspc.json.encode(edit) .. '\n' + if not lspc.autoconfirm_edits then + -- generate change summary + local summary = '--- workspace edit summary ---\n' + for uri, edits in pairs(file_edits) do + local path = uri_to_path(uri) + summary = summary .. path .. ':\n' + for i, edit in ipairs(edits) do + summary = summary .. '\t' .. i .. '.: ' .. lspc.json.encode(edit) .. '\n' + end end - end - lspc_show_message(summary) - vis:redraw() + lspc_show_message(summary) + vis:redraw() - -- get user confirmation - local confirmation = lspc_confirm('apply changes:') + -- get user confirmation + local confirmation = lspc_confirm('apply changes:') - -- close summary window - lspc_close_message_win() + -- close summary window + lspc_close_message_win() - if not confirmation then - return + if not confirmation then + return + end end -- apply changes to open files @@ -23,6 +23,8 @@ local lspc = { menu_cmd = 'vis-menu -l 10', -- program used to ask the user for confirmation confirm_cmd = 'vis-menu', + -- apply workspaceEdits without confirmation + autoconfirm_edits = false, -- should diagnostics be highlighted if available highlight_diagnostics = 'line', @@ -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 |
