Esempio n. 1
0
    def on_query_completions(self, view, prefix, locations):
        if ng.settings.get('disable_all_completions'):
            return []
        if ng.settings.get('show_current_scope'):
            print(view.scope_name(view.sel()[0].a))

        single_match = False
        all_matched = True
        _scope = view.sel()[0].a

        if (view.score_selector(_scope, ng.settings.get('js_scope'))
                and not view.substr(locations[0] - 1)
                in ng.settings.get('js_prefixes')):
            word = None
            if prefix == '':
                word = view.substr(view.word(locations[0] - 2))
                # Check if we're possibly at a directive attrs param
                if 'attrs' in word.lower():
                    word = 'attrs'
                # Check if we're possibly at a scope var
                if 'scope' in word.lower():
                    word = '$rootScope'
            return jscompletions.global_completions(word)
        if (view.score_selector(_scope, 'source.js string.quoted')):
            if viewlocation.at_line_with_module(view, locations):
                return jscompletions.get(('module'),
                                         ng.get_current_project_indexes())
            return jscompletions.in_string_completions(
                prefix, ng.get_current_project_indexes())

        if (viewlocation.at_html_attribute(view, 'ng-controller', locations)):
            return jscompletions.get(('controller'),
                                     ng.get_current_project_indexes())
        if (viewlocation.at_html_attribute(view, 'ng-app', locations)):
            return jscompletions.get(('module'),
                                     ng.get_current_project_indexes())
        if (view.score_selector(_scope, ng.settings.get('filter_scope'))):
            return ng.filter_completions()
        for selector in ng.settings.get('attribute_avoided_scopes'):
            if view.score_selector(_scope, selector):
                return []
        attribute_defined_scopes = list(
            ng.settings.get('attribute_defined_scopes'))

        for selector in attribute_defined_scopes:
            if view.score_selector(_scope, selector):
                single_match = True
            else:
                all_matched = False

        is_inside_tag = view.score_selector(
            _scope, ', '.join(attribute_defined_scopes)) > 0

        if not ng.settings.get(
                'ensure_all_scopes_are_matched') and single_match:
            return ng.completions(view, prefix, locations, is_inside_tag)
        elif ng.settings.get('ensure_all_scopes_are_matched') and all_matched:
            return ng.completions(view, prefix, locations, is_inside_tag)
        else:
            return ng.completions(view, prefix, locations, False)
	def on_query_completions(self, view, prefix, locations):
		if ng.settings.get('disable_all_completions'):
			return []
		if ng.settings.get('show_current_scope'):
			print(view.scope_name(view.sel()[0].a))

		single_match = False
		all_matched = True
		_scope = view.sel()[0].a

		if(
			view.score_selector(_scope, ng.settings.get('js_scope'))
			and not view.substr(locations[0] - 1) in ng.settings.get('js_prefixes')
		):
			word = None
			if prefix == '':
				word = view.substr(view.word(locations[0] - 2))
				# Check if we're possibly at a directive attrs param
				if 'attrs' in word.lower():
					word = 'attrs'
				# Check if we're possibly at a scope var
				if 'scope' in word.lower():
					word = '$rootScope'
			return jscompletions.global_completions(word)
		if(view.score_selector(_scope, 'source.js string.quoted')):
			if viewlocation.at_line_with_module(view, locations):
				return jscompletions.get(('module'), ng.get_current_project_indexes())
			return jscompletions.in_string_completions(prefix, ng.get_current_project_indexes())

		if(viewlocation.at_html_attribute(view, 'ng-controller', locations)):
			return jscompletions.get(('controller'), ng.get_current_project_indexes())
		if(viewlocation.at_html_attribute(view, 'ng-app', locations)):
			return jscompletions.get(('module'), ng.get_current_project_indexes())
		if(view.score_selector(_scope, ng.settings.get('filter_scope'))):
			return ng.filter_completions()
		for selector in ng.settings.get('attribute_avoided_scopes'):
			if view.score_selector(_scope, selector):
				return []
		attribute_defined_scopes = list(ng.settings.get('attribute_defined_scopes'))

		for selector in attribute_defined_scopes:
			if view.score_selector(_scope, selector):
				single_match = True
			else:
				all_matched = False

		is_inside_tag = view.score_selector(_scope, ', '.join(attribute_defined_scopes)) > 0

		if not ng.settings.get('ensure_all_scopes_are_matched') and single_match:
			return ng.completions(view, prefix, locations, is_inside_tag)
		elif ng.settings.get('ensure_all_scopes_are_matched') and all_matched:
			return ng.completions(view, prefix, locations, is_inside_tag)
		else:
			return ng.completions(view, prefix, locations, False)