Skip to content

feat: complete the autosquash prefixes and the commit titles - #92

Merged
petertriho merged 1 commit into
mainfrom
feat/autosquash-completion
Nov 2, 2026
Merged

petertriho merged 1 commit into
mainfrom
feat/autosquash-completion

Conversation

@petertriho

Copy link
Copy Markdown
Owner

Summary

On line 1 of a commit message, cmp-git now completes the subjects that git rebase --autosquash reads.

  • Prefix words: fi, sq, and am give fixup!, squash!, and amend!. git.autosquash.prefixes sets the words and the minimum number of letters (default 2). After a prefix item, the menu opens again with the commit titles.
  • Commit titles: after fixup!, squash!, and amend!, the menu shows the commit titles, newest first, one item for each title. Titles that start with an autosquash prefix are hidden. The list uses the commit cache, so a cached history starts no new git process. A :, #, @, or ! in the title starts no other completion.
  • The completion works only on line 1, in the filetypes of git.autosquash.filetypes (gitcommit and NeogitCommitMessage).
  • Core loads only the line checks. Only the git source loads the autosquash capability.
  • README.md and docs/configuration.md describe the feature, the config, and how to turn off each part.

Engine API used for the menu reopen

  • nvim-cmp 2ffe79f: source.execute(self, item, callback) calls self.source:execute(item, callback) after the insert. cmp-git calls callback, then cmp.complete() with only the git source.
  • blink.cmp v1.10.0-258-geece1c5: module:execute(context, item, resolve, default_implementation). cmp-git calls default_implementation and resolve, then blink.show() with the provider of the item.

Test plan

  • make ci (StyLua, Selene, lua-language-server, 314 tests, 0 fails)
  • make test in the nvim-0_12_0 shell (v0.12.0) and the nightly shell (v0.13.0-nightly+1cfebe9)
  • A test runs git rebase -i --autosquash on completed subjects. Each commit comes right after its target with fixup, squash, or fixup -C.
  • make bench-compare: no regression in the keystroke/ group
  • Real Neovim 0.12.6, keys typed one at a time: blink.cmp passes 18 of 18 checks, nvim-cmp passes 16 of 18

Known limits

  • nvim-cmp, f with min_length = 1: no item until the second letter. nvim-cmp starts no request for the first character typed after insert mode starts, for any source.
  • nvim-cmp, squash! fixup! x: no item shows. cmp-git gives the titles with the edit after squash! , but nvim-cmp filters them on fixup! x, and no title matches. blink.cmp filters on the last word, so it shows the list.
  • Startup benchmarks: require/setup allocates about 23 KB more (+12%), and new_source about 2.8 KB more. new_source_with_overrides allocates about 2.6 KB more and takes 26% longer. Setup loads the new code, copies the larger defaults, and compiles two more regexes.

Fixes #42

On line 1 of a commit message, cmp-git now completes the subjects that
`git rebase --autosquash` reads:

- The prefix words: `fi`, `sq`, and `am` give `fixup!`, `squash!`,
  and `amend!`. `git.autosquash.prefixes` sets the words and the
  minimum number of letters (default 2). After a prefix item, the menu
  opens again with the commit titles.
- The commit titles after `fixup!`, `squash!`, and `amend!`, newest
  first, with one item for each title. The list hides the titles that
  start with an autosquash prefix. It uses the commit cache and the
  `git.commits` config, so a cached history starts no new git process.
  The edit starts after the prefix and its spaces, so a `:`, `#`, `@`,
  or `!` in the title starts no other completion.

The completion works only on line 1, in the filetypes of
`git.autosquash.filetypes` (`gitcommit` and `NeogitCommitMessage`).
Two new default entries come before the trailer entries:
`git_autosquash_prefixes` shares the regex of the trailer keys, and
`git_autosquash` has its own pattern and keyword pattern. Core loads
only the line checks, which run before the reads of the buffer. Only
the git source loads the autosquash capability.

The menu reopen uses the `execute` hook of each engine:

- nvim-cmp `2ffe79f`: `source.execute(self, item, callback)` calls
  `self.source:execute(item, callback)` after the insert. cmp-git
  calls `callback`, then `cmp.complete()` with only the `git` source.
- blink.cmp `v1.10.0-258-geece1c5`: `module:execute(context, item,
  resolve, default_implementation)`. cmp-git calls
  `default_implementation` and `resolve`, then `blink.show()` with the
  provider of the item.

A test runs `git rebase -i --autosquash` on completed subjects and
checks that each commit comes right after its target with `fixup`,
`squash`, or `fixup -C`. The keystroke benchmarks get an autosquash
line and a declined line 1 request.

Fixes #42
@petertriho
petertriho force-pushed the feat/autosquash-completion branch from b620f54 to 87c03ef Compare November 2, 2026 11:05
@petertriho
petertriho merged commit 8f0b51d into main Nov 2, 2026
6 of 7 checks passed
@petertriho
petertriho deleted the feat/autosquash-completion branch November 2, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autosquash completions?

1 participant