<commit_before>import sublime, sublime_plugin, os, re, codecs, threading, json, time, glob, itertools

class AngularJS():
	def init(self):
		self.projects_index_cache = {}
		self.index_cache_location = os.path.join(
			sublime.packages_path(),
			'User',
			'AngularJS.cache'
		)
		self.is_indexing = False
		self.attributes = []
		self.settings = sublime.load_settings('AngularJS-sublime-package.sublime-settings')

		try:
			json_data = open(self.index_cache_location, 'r').read()
			self.projects_index_cache = json.loads(json_data)
			json_data.close()
		except:
			pass

		self.settings.add_on_change('angular_components', self.process_angular_components)
		self.process_angular_components()

		self.settings.add_on_change('core_attribute_list', self.process_attributes)
		self.settings.add_on_change('extended_attribute_list', self.process_attributes)
		self.settings.add_on_change('AngularUI_attribute_list', self.process_attributes)
		self.settings.add_on_change('enable_data_prefix', self.process_attributes)
		self.settings.add_on_change('enable_AngularUI_directives', self.process_attributes)
		self.process_attributes()

	def view_settings(self):
		return self.active_view().settings().get('AngularJS', {})

	def active_window(self):
		return sublime.active_window()

	def active_view(self):
		return self.active_window().active_view()

	def get_index_key(self):
		return "".join(sublime.active_window().folders())

	def get_project_indexes_at(self, index_key):
		return self.projects_index_cache[index_key]

	def exclude_dirs(self):
		exclude_dirs = []
		for folder in ng.active_window().folders():
			exclude_dirs += [glob.glob(folder+"/"+path) for path in ng.settings.get('exclude_dirs')]
			exclude_dirs += [glob.glob(folder+"/"+path) for path in ng.view_settings().get('exclude_dirs', [])]
		return list(itertools.chain(*exclude_dirs))

	def get_current_project_indexes(self):
		if self.get_index_key() in self.projects_index_cache:
			return self.projects_index_cache[self.get_index_key()]
		else:
			return []

	def add_indexes_to_cache(self, indexes):
		self.projects_index_cache[self.get_index_key()] = indexes
		# save new indexes to file
		j_data = open(self.index_cache_location, 'w')
		j_data.write(json.dumps(self.projects_index_cache))
		j_data.close()

	def alert(self, status_message):
		sublime.status_message('AngularJS: %s' % status_message)

	#
	# completions definitions/logic
	#

	def completions(self, view, locations, is_inside_tag):
		if is_inside_tag:
			attrs = self.attributes[:]
			if ng.settings.get('add_indexed_directives'):
				attrs += self.add_indexed_directives()
			return (attrs, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)

		if not is_inside_tag:
			in_scope = False

			for scope in ng.settings.get('component_defined_scopes'):
				if view.match_selector(locations[0], scope):
					in_scope = True

			if in_scope:
				return self.custom_components
			else:
				return []

	def add_indexed_directives(self):
		indexes = ng.get_current_project_indexes()
		indexed_attrs = [
			tuple([
				self.definitionToDirective(directive) + "\t ng Indexed",
				self.definitionToDirective(directive)
			]) for directive in indexes if re.match('directive:', directive[0])
		]
		return list(set(indexed_attrs))

	def definitionToDirective(self, directive):
		return re.sub('([a-z0-9])([A-Z])', r'\1-\2', directive[0].replace('directive:  ', '')).lower()

	def process_attributes(self):
		add_data_prefix = ng.settings.get('enable_data_prefix')

		for attr in ng.settings.get('core_attribute_list'):
			if add_data_prefix:
				attr[1] = "data-" + attr[1]

			self.attributes.append(attr)

		for attr in ng.settings.get('extended_attribute_list'):
			if add_data_prefix:
				attr[1] = "data-" + attr[1]

			self.attributes.append(attr)

		if ng.settings.get('enable_AngularUI_directives'):
			for attr in ng.settings.get('AngularUI_attribute_list'):
				if add_data_prefix:
					attr[1] = "data-" + attr[1]

				self.attributes.append(attr)

		self.attributes = [tuple(attr) for attr in self.attributes]

	def process_angular_components(self):
		self.custom_components = []
		for component in ng.settings.get('angular_components'):
			self.custom_components.append((component + "\tAngularJS Component", component + "$1>$2</" + component + '>'))


ng = AngularJS()

if int(sublime.version()) < 3000:
	ng.init()

def plugin_loaded():
	global ng
	ng.init()

class AngularJSEventListener(sublime_plugin.EventListener):
	global ng

	def on_query_completions(self, view, prefix, locations):
		if ng.settings.get('disable_plugin'):
			return []
		if ng.settings.get('show_current_scope'):
			print(view.scope_name(view.sel()[0].end()))

		single_match = False
		all_matched = True

		for scope in ng.settings.get('attribute_avoided_scopes'):
			if view.match_selector(locations[0], scope):
				return []

		for scope in list(ng.settings.get('attribute_defined_scopes')):
			if view.match_selector(locations[0], scope):<commit_msg>Adds filter completions within html files<commit_after>import sublime, sublime_plugin, os, re, codecs, threading, json, time, glob, itertools

class AngularJS():
	def init(self):
		self.projects_index_cache = {}
		self.index_cache_location = os.path.join(
			sublime.packages_path(),
			'User',
			'AngularJS.cache'
		)
		self.is_indexing = False
		self.attributes = []
		self.settings = sublime.load_settings('AngularJS-sublime-package.sublime-settings')

		try:
			json_data = open(self.index_cache_location, 'r').read()
			self.projects_index_cache = json.loads(json_data)
			json_data.close()
		except:
			pass

		self.settings.add_on_change('angular_components', self.process_angular_components)
		self.process_angular_components()

		self.settings.add_on_change('core_attribute_list', self.process_attributes)
		self.settings.add_on_change('extended_attribute_list', self.process_attributes)
		self.settings.add_on_change('AngularUI_attribute_list', self.process_attributes)
		self.settings.add_on_change('enable_data_prefix', self.process_attributes)
		self.settings.add_on_change('enable_AngularUI_directives', self.process_attributes)
		self.process_attributes()

	def view_settings(self):
		return self.active_view().settings().get('AngularJS', {})

	def active_window(self):
		return sublime.active_window()

	def active_view(self):
		return self.active_window().active_view()

	def get_index_key(self):
		return "".join(sublime.active_window().folders())

	def get_project_indexes_at(self, index_key):
		return self.projects_index_cache[index_key]

	def exclude_dirs(self):
		exclude_dirs = []
		for folder in ng.active_window().folders():
			exclude_dirs += [glob.glob(folder+"/"+path) for path in ng.settings.get('exclude_dirs')]
			exclude_dirs += [glob.glob(folder+"/"+path) for path in ng.view_settings().get('exclude_dirs', [])]
		return list(itertools.chain(*exclude_dirs))

	def get_current_project_indexes(self):
		if self.get_index_key() in self.projects_index_cache:
			return self.projects_index_cache[self.get_index_key()]
		else:
			return []

	def add_indexes_to_cache(self, indexes):
		self.projects_index_cache[self.get_index_key()] = indexes
		# save new indexes to file
		j_data = open(self.index_cache_location, 'w')
		j_data.write(json.dumps(self.projects_index_cache))
		j_data.close()

	def alert(self, status_message):
		sublime.status_message('AngularJS: %s' % status_message)

	#
	# completions definitions/logic
	#

	def completions(self, view, locations, is_inside_tag):
		if is_inside_tag:
			attrs = self.attributes[:]
			if ng.settings.get('add_indexed_directives'):
				attrs += self.add_indexed_directives()
			return (attrs, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)

		if not is_inside_tag:
			in_scope = False

			for scope in ng.settings.get('component_defined_scopes'):
				if view.match_selector(locations[0], scope):
					in_scope = True

			if in_scope:
				return self.custom_components
			else:
				return []

	def filter_completions(self):
		current_point = ng.active_view().sel()[0].end()
		previous_text_block = ng.active_view().substr(sublime.Region(current_point-2,current_point))
		if(previous_text_block == '| '):
			filter_list = ng.get_current_project_indexes()
			filter_list = [(i[0], i[0][9:]) for i in filter_list if i[0][:6] == 'filter']
			return(list(set(filter_list)))
		else:
			return []


	def add_indexed_directives(self):
		indexes = ng.get_current_project_indexes()
		indexed_attrs = [
			tuple([
				self.definitionToDirective(directive) + "\t ng Indexed",
				self.definitionToDirective(directive)
			]) for directive in indexes if re.match('directive:', directive[0])
		]
		return list(set(indexed_attrs))

	def definitionToDirective(self, directive):
		return re.sub('([a-z0-9])([A-Z])', r'\1-\2', directive[0].replace('directive:  ', '')).lower()

	def process_attributes(self):
		add_data_prefix = ng.settings.get('enable_data_prefix')

		for attr in ng.settings.get('core_attribute_list'):
			if add_data_prefix:
				attr[1] = "data-" + attr[1]

			self.attributes.append(attr)

		for attr in ng.settings.get('extended_attribute_list'):
			if add_data_prefix:
				attr[1] = "data-" + attr[1]

			self.attributes.append(attr)

		if ng.settings.get('enable_AngularUI_directives'):
			for attr in ng.settings.get('AngularUI_attribute_list'):
				if add_data_prefix:
					attr[1] = "data-" + attr[1]

				self.attributes.append(attr)

		self.attributes = [tuple(attr) for attr in self.attributes]

	def process_angular_components(self):
		self.custom_components = []
		for component in ng.settings.get('angular_components'):
			self.custom_components.append((component + "\tAngularJS Component", component + "$1>$2</" + component + '>'))


ng = AngularJS()

if int(sublime.version()) < 3000:
	ng.init()

def plugin_loaded():
	global ng
	ng.init()

class AngularJSEventListener(sublime_plugin.EventListener):
	global ng

	def on_query_completions(self, view, prefix, locations):
		if ng.settings.get('disable_plugin'):
			return []
		if ng.settings.get('show_current_scope'):
			print(view.scope_name(view.sel()[0].end()))

		single_match = False
		all_matched = True

		if(view.score_selector(view.sel()[0].end(), 'text.html string.quoted')):
			return ng.filter_completions()

		for scope in ng.settings.get('attribute_avoided_scopes'):
			if view.match_selector(locations[0], scope):
				return []

		for scope in list(ng.settings.get('attribute_defined_scopes')):
			if view.match_selector(locations[0], scope):
{'fraction_non_alphanumeric': 0.13276271992391822, 'fraction_numerical': 0.004945316214931051, 'mean_word_length': 5.2558001189768, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3192711', 'n_tokens_mistral': 4022, 'n_tokens_neox': 3558, 'n_words': 609}