Skip to content

feat: dismissal and acceptWord commands#62

Open
alvaromrveiga wants to merge 1 commit into
augmentcode:mainfrom
alvaromrveiga:alvaromrveiga/feat-dismissal-accept-word
Open

feat: dismissal and acceptWord commands#62
alvaromrveiga wants to merge 1 commit into
augmentcode:mainfrom
alvaromrveiga:alvaromrveiga/feat-dismissal-accept-word

Conversation

@alvaromrveiga

Copy link
Copy Markdown

Motivation

I was missing being able to accept only a few words of the suggestion and also dismissing it when it is not relevant, hope this helps other people too.

augment.webm

Changes

This pull requests exposes augment#suggestion#Clear() as a public API that can be called as augment#Dismiss and create the new command augment#AcceptWord() it accepts a fallback just like augment#Accept does.

Here is an example on how I configured those keys in Neovim using lazy.nvim:

	keys = {
		{ "<M-d>", "<cmd>call augment#Accept()<cr>", desc = "Accept Augment suggestion", mode = "i" },
		{ "<M-a>", "<cmd>call augment#AcceptWord()<cr>", desc = "Accept one Augment suggestion word", mode = "i" },
		{ "<M-;>", "<cmd>call augment#Dismiss()<cr>", desc = "Dismiss Augment suggestion", mode = "i" },
	},
	config = function()
		vim.g.augment_disable_tab_mapping = true
	end,

In case someone else needs it, I use nvim-cmp for completions so this change was needed in my config so it does not get in the way of suggestions:

					-- Allow Augment keybinds to work even when cmp is visible
					["<M-a>"] = cmp.mapping(function(fallback)
						-- Close cmp and let Augment handle the key
						if cmp.visible() then
							cmp.close()
						end
						fallback()
					end, { "i" }),
					["<M-d>"] = cmp.mapping(function(fallback)
						-- Close cmp and let Augment handle the key
						if cmp.visible() then
							cmp.close()
						end
						fallback()
					end, { "i" }),

Testing

  • Verified that augment#AcceptWord() correctly moves the cursor and accepts only the next word of the ghost text.

  • Confirmed augment#Dismiss() clears the current suggestion UI immediately.

@mgmonteleone mgmonteleone left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent🛡️ with @mgmonteleone's authorization

Verdict: REQUEST CHANGES

The new augment#AcceptWord() and augment#Dismiss() APIs are valuable, but AcceptWord has a couple of correctness bugs that need to be fixed before this is safe to ship.

Blocker: accepting the last word on a line loses the newline boundary

s:ComputeRemainingLines() drops the first suggestion line when the accepted word consumes it and then returns a:lines[1:]. For a multi-line suggestion such as foo\nbar, accepting foo leaves ['bar'] as the remaining ghost text. The next AcceptWord() then inserts bar on the same line, producing foobar instead of preserving the newline boundary.

The remaining state needs to retain an explicit newline boundary after consuming the final text on a line, for example by leaving an empty first-line sentinel so the next accept operation consumes the newline before rendering/inserting the next line's text.

Blocker: word extraction and cursor movement are byte-oriented and can mishandle multibyte text

The implementation indexes and measures strings with operations such as first_line[0], strpart(...), and len(word). Those are byte-oriented in Vimscript. For non-ASCII suggestions, this can misclassify the first character, split in the middle of a multibyte character, or move the cursor by bytes rather than characters/display cells after inserting an accepted word.

Please make the extraction and cursor-update logic multibyte-safe, and add coverage with Unicode input. The tests/manual verification should include a multibyte word, multibyte punctuation, and a multi-line suggestion where the first accepted token ends exactly at a newline.

@mgmonteleone mgmonteleone left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great refactors. Two bugs: 1. s:ComputeRemainingLines drops the newline boundary, breaking rendering/insertion for multi-line words. 2. s:ExtractNextWord uses byte-indexing for the first char; use strcharpart for multibyte safety. Also, the 10ms timer is a bit fragile.

@mgmonteleone mgmonteleone added the feature request Suggests new functionality or enhancements to existing features label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Suggests new functionality or enhancements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants