Sublime Forum

Remove specific words / or duplicates

#1

I am trying to make a plugin that will remove duplicate / or specific words from showing on the auto-complete popup. For example var_dump like in the image below, should not appear.

So I created the following script. But don’t understand how to replace the region / rebuild the index / or what is needed to remove/hide that word.

import sublime
import sublime_plugin
import re
class TestPlugin(sublime_plugin.EventListener):

	def on_query_completions(self, view, prefix, locations):
		remove_duplicates = ['var_dump']
		region = sublime.Region(0, view.size())
		visible_region = view.visible_region()
		content = view.substr(region)
		for duplicate in remove_duplicates:
			content = re.sub(duplicate+"(\(.*?\);)", '', content)
		print(content)
		#view.replace(self, visible_region, content)
		#view.erase(self.edit, sublime.Region(0, view.size()))
		#regions = view.get_regions()
		#print(regions)
0 Likes

#2

Plugins can’t remove items from the list of autocompletion suggestions, they can only add suggestions to the mix. The only exception to this are the flags you can return from on_query_completions that tell Sublime to inhibit completions sourced from text in the buffer (sublime.INHIBIT_WORD_COMPLETIONS) and inhibit completions that are sourced from sublime-completions files (sublime.INHIBIT_EXPLICIT_COMPLETIONS).

To stop completions from appearing in the list, you need to block all other completions with those options and then become the sole provider of completions for a particular type of file; that is, your plugin needs to generate all possible completions based on the code in the buffer and the language, and then also inhibit the completions that would be sourced from elsewhere.

Even so, you also can’t block other plugins from providing completions, so other plugins doing the same thing can still provide completions.

1 Like

#3

ok got the point, it’s like

word_list = ['123', 456]
return (word_list, sublime.INHIBIT_WORD_COMPLETIONS)

it’s required to re-create the list.

0 Likes