Skip to content

Commit d3d0590

Browse files
committed
fix diff generation for new files
Some edits returned by the language server create new files. The URI property points to a path in the filesystem that does not exist yet. As result the function to read a line from such a file will return `nil`. While this has been partially handled within the diff generation it wasn't everywhere. The consequence was an error propagated to the user and a broken menu.
1 parent ca7cea1 commit d3d0590

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lua/code_action_menu/lsp_objects/edits/text_document_edit.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ local function get_list_of_added_lines_in_edit(uri, edit)
7878
local first_original_complete_line = vim.lsp.util.get_line(
7979
uri,
8080
edit.range.start.line
81-
)
81+
) or ''
82+
8283
local text_before_changes = first_original_complete_line:sub(
8384
0,
8485
edit.range.start.character
@@ -88,7 +89,7 @@ local function get_list_of_added_lines_in_edit(uri, edit)
8889
local last_original_complete_line = vim.lsp.util.get_line(
8990
uri,
9091
edit.range['end'].line
91-
)
92+
) or ''
9293

9394
if #last_original_complete_line > edit.range['end'].character then
9495
local text_after_changes = last_original_complete_line:sub(

0 commit comments

Comments
 (0)