From 9aa4608401384a59ea54e0ba800ce063775e8ae9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 20 May 2026 17:33:01 -0400 Subject: refactor: introduce nvim_on internally #39883 Problem: `nvim_create_autocmd` is too verbose and its `callback` requires extra "nesting". Solution: Introduce `nvim_on`. Start using it internally. Then we can get a feel for how it should look before making it public. --- runtime/lua/vim/lsp/inline_completion.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'runtime/lua/vim/lsp/inline_completion.lua') diff --git a/runtime/lua/vim/lsp/inline_completion.lua b/runtime/lua/vim/lsp/inline_completion.lua index 7dae0c717b..76e15658a5 100644 --- a/runtime/lua/vim/lsp/inline_completion.lua +++ b/runtime/lua/vim/lsp/inline_completion.lua @@ -40,6 +40,7 @@ local log = require('vim.lsp.log') local protocol = require('vim.lsp.protocol') local grammar = require('vim.lsp._snippet_grammar') local api = vim.api +local nvim_on = require('vim._core.util').nvim_on local Capability = require('vim.lsp._capability') @@ -78,20 +79,12 @@ Capability.all[Completor.name] = Completor function Completor:new(buf) self = Capability.new(self, buf) self.client_state = {} - api.nvim_create_autocmd({ 'InsertEnter', 'CursorMovedI', 'TextChangedP' }, { - group = self.augroup, - buf = buf, - callback = function() - self:automatic_request() - end, - }) - api.nvim_create_autocmd({ 'InsertLeave' }, { - group = self.augroup, - buf = buf, - callback = function() - self:abort() - end, - }) + nvim_on({ 'InsertEnter', 'CursorMovedI', 'TextChangedP' }, self.augroup, { buf = buf }, function() + self:automatic_request() + end) + nvim_on({ 'InsertLeave' }, self.augroup, { buf = buf }, function() + self:abort() + end) return self end -- cgit