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

class AngularJS():
	def init(self, isST2):
		self.isST2 = isST2
		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]['definitions']

	def isHTML(self):
		view = self.active_view()
		return view.score_selector(view.sel()[0].begin(), 'text.html') > 0

	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:
			if 'definitions' not in self.projects_index_cache[self.get_index_key()]:
				self.projects_index_cache[self.get_index_key()] = {'definitions':[], 'attributes': {}}
			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()] = {
			'definitions': indexes[0],
			'attributes': indexes[1]
		}
		# 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, prefix, locations, is_inside_tag):
		if is_inside_tag:
			pt = locations[0] - len(prefix) - 1
			ch = view.substr(sublime.Region(pt, pt + 1))
			if(ch != '<'):
				attrs = self.attributes[:]
			else:
				attrs = []
			if ng.settings.get('add_indexed_directives'):
				attrs += self.get_attribute_completions(view, prefix, locations, pt)
				attrs += self.add_indexed_directives()
			return (attrs, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)

		def convertDirectiveToTagCompletion(directive):
			if ng.isHTML():
				return directive.replace('="$1"$0','')+'$1>$0</'+directive.replace('="$1"$0','')+'>'
			else: #assume Jade
				return directive.replace('="$1"$0','')+'${1:($2)}$0'
		if not is_inside_tag:
			if not ng.isST2:
				if(view.substr(view.sel()[0].b-1) == '<'): return
			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:
				completions = self.custom_components[:]
				#adjust how completions work when used for completing a tag
				completions += [
					(directive[0], convertDirectiveToTagCompletion(directive[1])) for directive in self.add_indexed_directives()
				]
				return completions
			else:<commit_msg>Fixes html tab completion issue in ST2<commit_after>import sublime, sublime_plugin, os, re, codecs, threading, json, time, glob, itertools

class AngularJS():
	def init(self, isST2):
		self.isST2 = isST2
		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]['definitions']

	def isHTML(self):
		view = self.active_view()
		return view.score_selector(view.sel()[0].begin(), 'text.html') > 0

	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:
			if 'definitions' not in self.projects_index_cache[self.get_index_key()]:
				self.projects_index_cache[self.get_index_key()] = {'definitions':[], 'attributes': {}}
			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()] = {
			'definitions': indexes[0],
			'attributes': indexes[1]
		}
		# 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, prefix, locations, is_inside_tag):
		if is_inside_tag:
			pt = locations[0] - len(prefix) - 1
			ch = view.substr(sublime.Region(pt, pt + 1))
			if(ch != '<'):
				attrs = self.attributes[:]
			else:
				attrs = []
			if ng.settings.get('add_indexed_directives'):
				attrs += self.get_attribute_completions(view, prefix, locations, pt)
				attrs += self.add_indexed_directives()
			return (attrs, 0)

		def convertDirectiveToTagCompletion(directive):
			if ng.isHTML():
				return directive.replace('="$1"$0','')+'$1>$0</'+directive.replace('="$1"$0','')+'>'
			else: #assume Jade
				return directive.replace('="$1"$0','')+'${1:($2)}$0'
		if not is_inside_tag:
			if not ng.isST2:
				if(view.substr(view.sel()[0].b-1) == '<'): return
			if ng.isST2:
				if(view.substr(view.sel()[0].b-1) != '<'): return
			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:
				completions = self.custom_components[:]
				#adjust how completions work when used for completing a tag
				completions += [
					(directive[0], convertDirectiveToTagCompletion(directive[1])) for directive in self.add_indexed_directives()
				]
				return (completions, 0)
			else:
{'fraction_non_alphanumeric': 0.14257907542579076, 'fraction_numerical': 0.0072992700729927005, 'mean_word_length': 5.190512048192771, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '2460581', 'n_tokens_mistral': 3207, 'n_tokens_neox': 2830, 'n_words': 477}