def run(self):
		message.alert('Deleting Cache')
		try:
			os.remove(ng.index_cache_location)
		except:
			message.alert('Deleting Cache: No cache file found.')
		ng.projects_index_cache = {}
	def run(self):
		self.active_view = ng.active_view()

		if not ng.get_current_project_indexes().get('definitions'):
			message.alert('No indexing found for project')
			return

		# grab first region
		region = self.active_view.sel()[0]

		# no selection has been made
		# so begin expanding to find word
		if not region.size():
			definition = viewlocation.find_word(self.active_view, region)
		else:
			definition = self.active_view.substr(region)

		# ensure data- is striped out before trying to
		# normalize and look up
		definition = definition.replace('data-', '')

		# convert selections such as app-version to appVersion
		# for proper look up
		definition = re.sub('(\w*)-(\w*)', lambda match: match.group(1) + match.group(2).capitalize(), definition)
		for item in ng.get_current_project_indexes().get('definitions'):
			if(re.search('. '+definition+'$', item[0])):
				self.active_view = ng.active_window().open_file(item[1])
				ng.handle_file_open_go_to(int(item[2]))
				return
		message.alert('definition "%s" could not be found' % definition)
Ejemplo n.º 3
0
    def reindex_file(self, index_key):
        file_path = self.kwargs['file_path']

        if not file_path.endswith(".js"): return

        current_path = os.path.split(file_path)[0]
        # adds limit, to insure we never hit an infinite loop...
        folders, limit, count = [], 100, 0
        while True and count < limit:
            count += 1
            current_path, folder = os.path.split(current_path)
            if folder != "": folders.append(folder)
            if current_path == "" or folder == "": break
        if [
                f for f in folders
                if f in list(self.kwargs['folder_exclude_patterns'])
        ]:
            return

        if (not file_path.endswith(tuple(self.kwargs['exclude_file_suffixes']))
                and index_key in ng.projects_index_cache and not [
                    skip for skip in self.kwargs['exclude_dirs']
                    if os.path.normpath(skip) in file_path
                ]):
            message.alert('Reindexing ' + self.kwargs['file_path'])
            project_index = ng.get_project_indexes_at(index_key)

            project_index[:] = [
                item for item in project_index if item[1] != file_path
            ]

            _file = codecs.open(file_path)
            _lines = _file.readlines()
            _file.close()
            line_number = 1
            previous_matched_directive = ''

            for line in _lines:
                if previous_matched_directive != '':
                    self.look_for_directive_attribute(
                        line, previous_matched_directive)

                matches = self.get_definition_details(
                    line,
                    self.compile_patterns(self.kwargs['match_definitions']))
                if matches:
                    for matched in matches:
                        definition_name = matched[0] + ':  '
                        definition_value = matched[1].group(
                            int(self.kwargs['match_expression_group']))
                        definition_name += definition_value
                        project_index.append(
                            [definition_name, file_path,
                             str(line_number)])
                        if (matched[0] == 'directive'):
                            previous_matched_directive = definition_value
                        else:
                            previous_matched_directive = ''
                line_number += 1
            ng.add_indexes_to_cache([project_index, self.attribute_dict])
Ejemplo n.º 4
0
    def run(self):
        self.active_view = ng.active_view()

        if not ng.get_current_project_indexes().get('definitions'):
            message.alert('No indexing found for project')
            return

        # grab first region
        region = self.active_view.sel()[0]

        # no selection has been made
        # so begin expanding to find word
        if not region.size():
            definition = viewlocation.find_word(self.active_view, region)
        else:
            definition = self.active_view.substr(region)

        # ensure data- is striped out before trying to
        # normalize and look up
        definition = definition.replace('data-', '')

        # convert selections such as app-version to appVersion
        # for proper look up
        definition = re.sub(
            '(\w*)-(\w*)',
            lambda match: match.group(1) + match.group(2).capitalize(),
            definition)
        for item in ng.get_current_project_indexes().get('definitions'):
            if (re.search('. ' + definition + '$', item[0])):
                self.active_view = ng.active_window().open_file(item[1])
                ng.handle_file_open_go_to(int(item[2]))
                return
        message.alert('definition "%s" could not be found' % definition)
Ejemplo n.º 5
0
 def run(self):
     message.alert('Deleting Cache')
     try:
         os.remove(ng.index_cache_location)
     except:
         message.alert('Deleting Cache: No cache file found.')
     ng.projects_index_cache = {}
    def run(self):
        if not ng.active_view():
            message.alert(
                'There was no active view found to process this command')
            return

        ng.is_indexing = True

        match_expression = ng.settings.get('match_expression')
        match_app_names = ng.settings.get('match_app_names', 'app')
        print('match... ', match_expression)
        match_expression = match_expression.replace('{match_app_names}',
                                                    match_app_names)

        thread = AngularJSThread(
            folders=ng.get_folders(),
            folder_exclude_patterns=ng.active_view().settings().get(
                'folder_exclude_patterns'),
            exclude_dirs=ng.exclude_dirs(),
            exclude_file_suffixes=ng.settings.get('exclude_file_suffixes'),
            match_definitions=ng.settings.get('match_definitions'),
            match_expression=match_expression,
            match_expression_group=ng.settings.get('match_expression_group'))

        thread.start()
        self.track_walk_thread(thread)
	def track_walk_thread(self, thread):
		message.alert('indexing definitions')

		if thread.is_alive():
			sublime.set_timeout(lambda: self.track_walk_thread(thread), 1000)
		else:
			ng.add_indexes_to_cache(thread.result)
			message.alert('indexing completed in ' + str(thread.time_taken))
			ng.is_indexing = False
Ejemplo n.º 8
0
    def track_walk_thread(self, thread):
        message.alert('indexing definitions')

        if thread.is_alive():
            sublime.set_timeout(lambda: self.track_walk_thread(thread), 1000)
        else:
            ng.add_indexes_to_cache(thread.result)
            message.alert('indexing completed in ' + str(thread.time_taken))
            ng.is_indexing = False
	def run(self):
		indx = ng.get_current_project_indexes()
		missing_files = []
		for definition in indx['definitions']:
			if not os.path.isfile(definition[1]):
				missing_files.append(definition)
		missing_len = len(missing_files)
		message.alert('Removed %s files from index.' % missing_len)
		if missing_len:
			for f in missing_files:
				indx['definitions'].remove(f)
			j_data = open(ng.index_cache_location, 'w')
			j_data.write(json.dumps(ng.projects_index_cache))
			j_data.close()
Ejemplo n.º 10
0
 def run(self):
     indx = ng.get_current_project_indexes()
     missing_files = []
     for definition in indx['definitions']:
         if not os.path.isfile(definition[1]):
             missing_files.append(definition)
     missing_len = len(missing_files)
     message.alert('Removed %s files from index.' % missing_len)
     if missing_len:
         for f in missing_files:
             indx['definitions'].remove(f)
         j_data = open(ng.index_cache_location, 'w')
         j_data.write(json.dumps(ng.projects_index_cache))
         j_data.close()
	def reindex_file(self, index_key):
		file_path = self.kwargs['file_path']

		if not file_path.endswith(".js"): return

		current_path = os.path.split(file_path)[0]
		# adds limit, to insure we never hit an infinite loop...
		folders, limit, count = [], 100, 0
		while True and count < limit:
			count += 1
			current_path, folder = os.path.split(current_path)
			if folder != "": folders.append(folder)
			if current_path == "" or folder == "": break
		if [f for f in folders if f in list(self.kwargs['folder_exclude_patterns'])]:
			return

		if (not file_path.endswith(tuple(self.kwargs['exclude_file_suffixes']))
		and index_key in ng.projects_index_cache
		and not [skip for skip in self.kwargs['exclude_dirs'] if os.path.normpath(skip) in file_path]):
			message.alert('Reindexing ' + self.kwargs['file_path'])
			project_index = ng.get_project_indexes_at(index_key)

			project_index[:] = [
				item for item in project_index
				if item[1] != file_path
			]

			_file = codecs.open(file_path)
			_lines = _file.readlines();
			_file.close()
			line_number = 1
			previous_matched_directive = ''

			for line in _lines:
				if previous_matched_directive != '':
					self.look_for_directive_attribute(line, previous_matched_directive)

				matches = self.get_definition_details(line, self.compile_patterns(self.kwargs['match_definitions']))
				if matches:
					for matched in matches:
						definition_name = matched[0] + ':  '
						definition_value = matched[1].group(int(self.kwargs['match_expression_group']))
						definition_name += definition_value
						project_index.append([definition_name, file_path, str(line_number)])
						if(matched[0] == 'directive'): previous_matched_directive = definition_value
						else: previous_matched_directive = '';
				line_number += 1
			ng.add_indexes_to_cache([project_index, self.attribute_dict])
	def run(self):
		if not ng.active_view():
			message.alert('There was no active view found to process this command')
			return

		ng.is_indexing = True
		thread = AngularJSThread(
			folders = ng.get_folders(),
			folder_exclude_patterns = ng.active_view().settings().get('folder_exclude_patterns'),
			exclude_dirs = ng.exclude_dirs(),
			exclude_file_suffixes = ng.settings.get('exclude_file_suffixes'),
			match_definitions = ng.settings.get('match_definitions'),
			match_expression = ng.settings.get('match_expression'),
			match_expression_group = ng.settings.get('match_expression_group')
		)

		thread.start()
		self.track_walk_thread(thread)
def find_word(view, region):
	non_char = re.compile(settings().get('non_word_chars'))
	look_up_found = ""
	start_point = region.end()
	begin_point = start_point-1
	end_point = start_point+1

	while (
		not non_char.search(view.substr(sublime.Region(start_point, end_point)))
		and end_point
	):
		end_point += 1
	while (
		not non_char.search(view.substr(sublime.Region(begin_point, start_point)))
	):
		begin_point -= 1

	look_up_found = view.substr(sublime.Region(begin_point+1, end_point-1))
	message.alert('Looking up: ' + look_up_found)
	return look_up_found