Skip to content

Commit 1fc9a70

Browse files
committed
refactor: rename option name to show_source_command_hint.
1 parent 47cd732 commit 1fc9a70

1 file changed

Lines changed: 16 additions & 36 deletions

File tree

lua/yarepl/init.lua

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ local default_config = function()
2828
source_syntax = 'bash',
2929
},
3030
zsh = { cmd = 'zsh', formatter = 'bracketed_pasting', source_syntax = 'bash' },
31-
-- Example of enabling virtual text for a specific REPL:
32-
-- mylua = {
33-
-- cmd = 'lua',
34-
-- formatter = 'trim_empty_lines',
35-
-- source_syntax = 'lua',
36-
-- virtual_text_when_source_content = { -- Per-REPL override for virtual text settings
37-
-- enabled = true,
38-
-- hl_group = 'MoreMsg',
39-
-- -- delay_ms can also be overridden if desired, though typically global
40-
-- }
41-
-- },
4231
},
4332
close_on_exit = true,
4433
scroll_to_bottom_after_sending = true,
@@ -49,10 +38,11 @@ local default_config = function()
4938
send_delayed_cr_after_sending = true,
5039
},
5140
},
52-
virtual_text_when_source_content = {
53-
enabled_default = false, -- Global default for enabling virtual text on source
54-
hl_group_default = 'Comment', -- Default highlight group for YAREPL virtual text
55-
delay_ms = 200, -- Delay in milliseconds to wait for REPL to echo command
41+
-- Display the first line as virtual text to indicate the actual
42+
-- command sent to the REPL.
43+
source_command_hint = {
44+
enabled = false,
45+
hl_group = 'Comment',
5646
},
5747
}
5848
end
@@ -430,8 +420,8 @@ M.formatter.bracketed_pasting_no_final_new_line = M.formatter.factory {
430420

431421
--- Displays the source comment as virtual text in the REPL buffer.
432422
---@param repl table The REPL object.
433-
---@param original_content string[] The original strings/code block sent by the user.
434-
---@param source_command string The first line of the command sent to REPL, used for anchoring.
423+
---@param original_content? string[] The original strings/code block sent by the user.
424+
---@param source_command? string The first line of the command sent to REPL, used for anchoring.
435425
local function show_source_command_hint(repl, original_content, source_command)
436426
if not repl_is_valid(repl) then
437427
return
@@ -440,8 +430,10 @@ local function show_source_command_hint(repl, original_content, source_command)
440430
return
441431
end
442432

433+
source_command = source_command:match '^([^\n]*)'
434+
443435
local meta = M._config.metas[repl.name]
444-
local config = meta.virtual_text_when_source_content
436+
local config = meta.source_command_hint
445437

446438
local code_part_for_display = ''
447439
if original_content and #original_content > 0 then
@@ -458,7 +450,7 @@ local function show_source_command_hint(repl, original_content, source_command)
458450
return
459451
end
460452

461-
local comment_text = string.format('%s - %s', os.date '%H:%M:%S', code_part_for_display)
453+
local comment_text = string.format(' %s - %s', os.date '%H:%M:%S', code_part_for_display)
462454

463455
local delay_ms = 400
464456

@@ -481,7 +473,7 @@ local function show_source_command_hint(repl, original_content, source_command)
481473
if matched_line then
482474
local hl_group = config.hl_group
483475
local virt_lines_opts = {
484-
virt_text = { { ' ' .. comment_text, hl_group } },
476+
virt_text = { { comment_text, hl_group } },
485477
virt_text_pos = 'eol',
486478
}
487479
api.nvim_buf_set_extmark(buf, M._virt_text_ns_id, matched_line, 0, virt_lines_opts)
@@ -536,9 +528,8 @@ M._send_strings = function(id, name, bufnr, strings, use_formatter, source_conte
536528
end
537529

538530
if source_command_sent_to_repl and source_command_sent_to_repl ~= '' then
539-
if meta.virtual_text_when_source_content and meta.virtual_text_when_source_content.enabled then
540-
local command_to_match_in_repl = vim.split(source_command_sent_to_repl, '\n')[1]
541-
show_source_command_hint(repl, strings, command_to_match_in_repl)
531+
if meta.source_command_hint.enabled then
532+
show_source_command_hint(repl, strings, source_command_sent_to_repl)
542533
end
543534
strings = vim.split(source_command_sent_to_repl, '\n')
544535
end
@@ -1058,19 +1049,8 @@ M.setup = function(opts)
10581049
meta.formatter = get_formatter(meta.formatter)
10591050
end
10601051

1061-
meta.virtual_text_when_source_content = meta.virtual_text_when_source_content or {}
1062-
1063-
if meta.virtual_text_when_source_content.enabled == nil then
1064-
meta.virtual_text_when_source_content.enabled =
1065-
M._config.virtual_text_when_source_content.enabled_default
1066-
end
1067-
if meta.virtual_text_when_source_content.hl_group == nil then
1068-
meta.virtual_text_when_source_content.hl_group =
1069-
M._config.virtual_text_when_source_content.hl_group_default
1070-
end
1071-
if meta.virtual_text_when_source_content.delay_ms == nil then
1072-
meta.virtual_text_when_source_content.delay_ms = M._config.virtual_text_when_source_content.delay_ms
1073-
end
1052+
meta.source_command_hint =
1053+
vim.tbl_deep_extend('force', M._config.source_command_hint, meta.source_command_hint or {})
10741054
end
10751055
end
10761056

0 commit comments

Comments
 (0)