How to remove words in the current buffer from Sublime Text 4 autocomplete list

For the past 8 years or so, this plugin has worked fine with Sublime Text 2 and 3 to remove words in the current buffer from the ctrl + space autocomplete list, but it no longer works in ST4 (b4126):

import sublime, sublime_plugin

class MyAutocomplete(sublime_plugin.EventListener):
  def on_query_completions(self, view, prefix, locations):
    # Popup autocomplete only for .sublime-snippet and
    # .sublime-completions files
    return ([], sublime.INHIBIT_WORD_COMPLETIONS)

I know the on_query_completions and sublime.INHIBIT_WORD_COMPLETIONS are still valid, so I think the problem is with the array return statement. The docs don't show any changes between versions.

The only variation of a return statement I was able to get sublime.INHIBIT_WORD_COMPLETIONS to work with was this, but now I've got an extra completion in the list I don't want:

return [
  sublime.CompletionItem(
    trigger="fox",
    completion="The quick brown fox jumps over the lazy dog",
    kind=sublime.KIND_KEYWORD
  )
], sublime.INHIBIT_WORD_COMPLETIONS

Had no luck at all with sublime.CompletionList or set_completions


Solution 1:

It seems like it isn't possible to inhibit buffer/word completions without returning at least one completion. But, if that completion (both trigger and outcome) is a single character, it will never be relevant, and thus the autocomplete will never be shown.

import sublime, sublime_plugin


class InhibitWordCompletionsEventListener(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        clist = sublime.CompletionList()
        sublime.set_timeout(lambda: clist.set_completions([' '], sublime.INHIBIT_WORD_COMPLETIONS), 0)
        return clist

(Note: partially based on a comment on https://github.com/sublimehq/sublime_text/issues/4999, which I found while searching to see if a bug was reported for this or not.)