Esempio n. 1
0
    def run(self):

        project_folder_list = self.project_folder_list
        excluded_dirs = self.excluded_dirs
        this_aliases = self.this_aliases
        current_file_lines = self.current_file_lines
        preceding_symbol = self.preceding_symbol
        prefix = self.prefix
        preceding_function_call = self.preceding_function_call
        function_return_types = self.function_return_types
        token = self.token
        symbol_region = self.symbol_region
        built_in_types = self.built_in_types
        member_exclusion_regexes = self.member_exclusion_regexes

        selected_word = token[token.rfind(".") + 1:]

        completions = []

        # First see if it is a special function return definition, like $ for $("#selector")
        if preceding_function_call:
            for next_return_type in function_return_types:
                function_names = next_return_type[
                    coffee_utils.FUNCTION_RETURN_TYPE_FUNCTION_NAMES_KEY]
                if preceding_function_call in function_names:
                    return_type = next_return_type[
                        coffee_utils.FUNCTION_RETURN_TYPE_TYPE_NAME_KEY]
                    completions = coffee_utils.get_completions_for_class(
                        return_type, False, None, prefix, None, built_in_types,
                        member_exclusion_regexes, False)

        if not completions:
            # Prepare to search globally if we need to...
            # Coffeescript filename regex
            coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
            # All coffeescript file paths
            all_coffee_file_paths = coffee_utils.get_files_in(
                project_folder_list, coffeescript_filename_regex,
                excluded_dirs)

            # If @ typed, process as "this."
            if preceding_symbol == coffee_utils.THIS_SUGAR_SYMBOL:
                # Process as "this."
                this_type = coffee_utils.get_this_type(current_file_lines,
                                                       symbol_region)
                if this_type:
                    completions = coffee_utils.get_completions_for_class(
                        this_type, False, current_file_lines, prefix,
                        all_coffee_file_paths, built_in_types,
                        member_exclusion_regexes, True)
                pass
            elif preceding_symbol == coffee_utils.PERIOD_OPERATOR:
                # If "this" or a substitute for it, process as "this."
                if selected_word == coffee_utils.THIS_KEYWORD or selected_word in this_aliases:
                    # Process as "this."
                    this_type = coffee_utils.get_this_type(
                        current_file_lines, symbol_region)
                    if this_type:
                        completions = coffee_utils.get_completions_for_class(
                            this_type, False, current_file_lines, prefix,
                            all_coffee_file_paths, built_in_types,
                            member_exclusion_regexes, True)
                else:
                    # If TitleCase, assume a class, and that we want static properties and functions.
                    if coffee_utils.is_capitalized(selected_word):
                        # Assume it is either in the current view or in a coffee file somewhere
                        completions = coffee_utils.get_completions_for_class(
                            selected_word, True, current_file_lines, prefix,
                            all_coffee_file_paths, built_in_types,
                            member_exclusion_regexes, False)
                        if not completions:
                            # Now we search globally...
                            completions = coffee_utils.get_completions_for_class(
                                selected_word, True, None, prefix,
                                all_coffee_file_paths, built_in_types,
                                member_exclusion_regexes, False)

                    # If nothing yet, assume a variable.
                    if not completions:
                        variable_type = coffee_utils.get_variable_type(
                            current_file_lines, token, symbol_region,
                            all_coffee_file_paths, built_in_types, [])
                        if variable_type:
                            # Assume it is either in the current view or in a coffee file somewhere
                            completions = coffee_utils.get_completions_for_class(
                                variable_type, False, current_file_lines,
                                prefix, all_coffee_file_paths, built_in_types,
                                member_exclusion_regexes, False)
                    if not completions:
                        # Now we search globally for a class... Maybe they're making a static call on something lowercase? Bad design, but check anyways.
                        completions = coffee_utils.get_completions_for_class(
                            selected_word, True, None, prefix,
                            all_coffee_file_paths, built_in_types,
                            member_exclusion_regexes, False)
        if completions:
            self.completions = completions
Esempio n. 2
0
	def run(self):

		project_folder_list = self.project_folder_list
		current_file_lines = self.current_file_lines
		selected_word = self.selected_word
		excluded_dirs = self.excluded_dirs
		selected_region = self.selected_region

		# This will be assigned whem a match is made
		matched_location_tuple = None

		# The regular expression used to search for the selected class
		class_regex = coffee_utils.CLASS_REGEX % re.escape(selected_word)
		# The regex used to search for the selected function
		function_regex = coffee_utils.FUNCTION_REGEX % re.escape(selected_word)
		# The regex used to search for the selected variable assignment
		assignment_regex = coffee_utils.ASSIGNMENT_REGEX % re.escape(selected_word)
		# The regex used to search for the selected variable as a parameter in a method
		param_regex = coffee_utils.PARAM_REGEX.format(name=re.escape(selected_word))

		# The regex used to search for the selected variable as a for loop var
		for_loop_regex = coffee_utils.FOR_LOOP_REGEX % re.escape(selected_word)

		debug(("Selected: \"%s\"" % selected_word))

		# ------ CURRENT FILE: CLASS (TitleCaps ONLY) ------------

		if not matched_location_tuple:

				# If so, we assume it is a class. 
				debug("Checking for local class %s..." % selected_word)
				class_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, current_file_lines, [])
				if class_location_search_tuple:
					matched_location_tuple = class_location_search_tuple

		# ------ GLOBAL SEARCH: CLASS ----------------------------

		if not matched_location_tuple:

			# Coffeescript filename regex
			coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
			# All coffeescript file paths
			all_coffee_file_paths = coffee_utils.get_files_in(project_folder_list, coffeescript_filename_regex, excluded_dirs)

			debug("Checking globally for class %s..." % selected_word)
			# Assume it is a file called selected_word.coffee
			exact_file_name_regex = "^" + re.escape(selected_word) + "(?:" + coffee_utils.COFFEE_EXTENSIONS_WITH_PIPES + ")$"
			exact_name_file_paths = coffee_utils.get_files_in(project_folder_list, exact_file_name_regex, excluded_dirs)
			exact_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, None, exact_name_file_paths)
			if exact_location_search_tuple:
				matched_location_tuple = exact_location_search_tuple
			else:
				global_class_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, None, all_coffee_file_paths)
				if global_class_location_search_tuple:
					matched_location_tuple = global_class_location_search_tuple

		# ------ CURRENT FILE: FUNCTION --------------------------
		if not matched_location_tuple:
			debug("Checking for local function %s..." % selected_word)
			local_function_location_search_tuple = coffee_utils.find_location_of_regex_in_files(function_regex, current_file_lines, [])
			if local_function_location_search_tuple:
				matched_location_tuple = local_function_location_search_tuple

		# ------ CURRENT FILE: ASSIGNMENT ------------------------

		if not matched_location_tuple:
			
			debug("Checking for local assignment of %s..." % selected_word)
			backwards_match_tuple = coffee_utils.search_backwards_for(current_file_lines, assignment_regex, selected_region)
			if backwards_match_tuple:
				filename_tuple = tuple([None])
				matched_location_tuple = filename_tuple + backwards_match_tuple
			else:
				# Nothing found. Now let's look backwards for a method parameter
				param_match_tuple = coffee_utils.search_backwards_for(current_file_lines, param_regex, selected_region)
				if param_match_tuple:
					filename_tuple = tuple([None])
					matched_location_tuple = filename_tuple + param_match_tuple	
				else:
					for_loop_match_tuple = coffee_utils.search_backwards_for(current_file_lines, for_loop_regex, selected_region)
					if for_loop_match_tuple:
						filename_tuple = tuple([None])
						matched_location_tuple = filename_tuple + for_loop_match_tuple
					# Otherwise, forwards search for it. It could be defined in the constructor.
					else:
						forwards_match_tuple = coffee_utils.find_location_of_regex_in_files(assignment_regex, current_file_lines, [])
						if forwards_match_tuple:
							matched_location_tuple = forwards_match_tuple

		# ------ GLOBAL SEARCH: FUNCTION -------------------------

		if not matched_location_tuple:

			# Coffeescript filename regex
			coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
			# All coffeescript file paths
			all_coffee_file_paths = coffee_utils.get_files_in(project_folder_list, coffeescript_filename_regex, excluded_dirs)

			debug("Checking globally for function %s..." % selected_word)
			global_function_location_search_tuple = coffee_utils.find_location_of_regex_in_files(function_regex, None, all_coffee_file_paths)
			if global_function_location_search_tuple:
				matched_location_tuple = global_function_location_search_tuple

		# ------ DOT OPERATION LOOKUP (TBD) ----------------------
		# TODO: Pull out dot operator object, determine its assignment type, find class, goto method/property.
		#	    Also, determine where to put this lookup.

		# ------ SUPER METHOD LOOKUP (TBD) -----------------------
		# TODO: If selected_word is "super", assume a function and then attempt to find 
		#       extending class and open it to the function the cursor is within.

		# ------ STORE MATCH RESULTS -----------------------------
		# If not None, then we found something that matched the search!
		if matched_location_tuple:
			self.matched_location_tuple = matched_location_tuple
	def run(self):

		project_folder_list = self.project_folder_list
		excluded_dirs = self.excluded_dirs
		this_aliases = self.this_aliases
		current_file_lines = self.current_file_lines
		preceding_symbol = self.preceding_symbol
		prefix = self.prefix
		preceding_function_call = self.preceding_function_call
		function_return_types = self.function_return_types
		token = self.token
		symbol_region = self.symbol_region
		built_in_types = self.built_in_types
		member_exclusion_regexes = self.member_exclusion_regexes

		selected_word = token[token.rfind(".") + 1:]

		completions = []

		# First see if it is a special function return definition, like $ for $("#selector")
		if preceding_function_call:
			for next_return_type in function_return_types:
				function_names = next_return_type[coffee_utils.FUNCTION_RETURN_TYPE_FUNCTION_NAMES_KEY]
				if preceding_function_call in function_names:
					return_type = next_return_type[coffee_utils.FUNCTION_RETURN_TYPE_TYPE_NAME_KEY]
					completions = coffee_utils.get_completions_for_class(return_type, False, None, prefix, None, built_in_types, member_exclusion_regexes, False)

		if not completions:
			# Prepare to search globally if we need to...
			# Coffeescript filename regex
			coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
			# All coffeescript file paths
			all_coffee_file_paths = coffee_utils.get_files_in(project_folder_list, coffeescript_filename_regex, excluded_dirs)

			# If @ typed, process as "this."
			if preceding_symbol == coffee_utils.THIS_SUGAR_SYMBOL:
				# Process as "this."
				this_type = coffee_utils.get_this_type(current_file_lines, symbol_region)
				if this_type:
					completions = coffee_utils.get_completions_for_class(this_type, False, current_file_lines, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, True)
				pass
			elif preceding_symbol == coffee_utils.PERIOD_OPERATOR:
				# If "this" or a substitute for it, process as "this."
				if selected_word == coffee_utils.THIS_KEYWORD or selected_word in this_aliases:
					# Process as "this."
					this_type = coffee_utils.get_this_type(current_file_lines, symbol_region)
					if this_type:
						completions = coffee_utils.get_completions_for_class(this_type, False, current_file_lines, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, True)
				else:
					# If TitleCase, assume a class, and that we want static properties and functions.
					if coffee_utils.is_capitalized(selected_word):
						# Assume it is either in the current view or in a coffee file somewhere
						completions = coffee_utils.get_completions_for_class(selected_word, True, current_file_lines, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, False)
						if not completions:
							# Now we search globally...
							completions = coffee_utils.get_completions_for_class(selected_word, True, None, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, False)

					# If nothing yet, assume a variable.
					if not completions:
						variable_type = coffee_utils.get_variable_type(current_file_lines, token, symbol_region, all_coffee_file_paths, built_in_types, [])
						if variable_type:
							# Assume it is either in the current view or in a coffee file somewhere
							completions = coffee_utils.get_completions_for_class(variable_type, False, current_file_lines, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, False)
					if not completions:
						# Now we search globally for a class... Maybe they're making a static call on something lowercase? Bad design, but check anyways.
						completions = coffee_utils.get_completions_for_class(selected_word, True, None, prefix, all_coffee_file_paths, built_in_types, member_exclusion_regexes, False)
		if completions:
			self.completions = completions
	def run(self):

		project_folder_list = self.project_folder_list
		current_file_lines = self.current_file_lines
		selected_word = self.selected_word
		excluded_dirs = self.excluded_dirs
		selected_region = self.selected_region

		# This will be assigned whem a match is made
		matched_location_tuple = None

		# The regular expression used to search for the selected class
		class_regex = coffee_utils.CLASS_REGEX % re.escape(selected_word)
		# The regex used to search for the selected function
		function_regex = coffee_utils.FUNCTION_REGEX % re.escape(selected_word)
		# The regex used to search for the selected variable assignment
		assignment_regex = coffee_utils.ASSIGNMENT_REGEX % re.escape(selected_word)
		# The regex used to search for the selected variable as a parameter in a method
		param_regex = coffee_utils.PARAM_REGEX.format(name=re.escape(selected_word))

		# The regex used to search for the selected variable as a for loop var
		for_loop_regex = coffee_utils.FOR_LOOP_REGEX % re.escape(selected_word)

		debug(("Selected: \"%s\"" % selected_word))

		# ------ CURRENT FILE: CLASS (TitleCaps ONLY) ------------

		if not matched_location_tuple:

				# If so, we assume it is a class. 
				debug("Checking for local class %s..." % selected_word)
				class_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, current_file_lines, [])
				if class_location_search_tuple:
					matched_location_tuple = class_location_search_tuple

		# ------ GLOBAL SEARCH: CLASS ----------------------------

		if not matched_location_tuple:

			# Coffeescript filename regex
			coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
			# All coffeescript file paths
			all_coffee_file_paths = coffee_utils.get_files_in(project_folder_list, coffeescript_filename_regex, excluded_dirs)

			debug("Checking globally for class %s..." % selected_word)
			# Assume it is a file called selected_word.coffee
			exact_file_name_regex = "^" + re.escape(selected_word) + coffee_utils.COFFEE_EXTENSION_WITH_DOT + "$"
			exact_name_file_paths = coffee_utils.get_files_in(project_folder_list, exact_file_name_regex, excluded_dirs)
			exact_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, None, exact_name_file_paths)
			if exact_location_search_tuple:
				matched_location_tuple = exact_location_search_tuple
			else:
				global_class_location_search_tuple = coffee_utils.find_location_of_regex_in_files(class_regex, None, all_coffee_file_paths)
				if global_class_location_search_tuple:
					matched_location_tuple = global_class_location_search_tuple

		# ------ CURRENT FILE: FUNCTION --------------------------
		if not matched_location_tuple:
			debug("Checking for local function %s..." % selected_word)
			local_function_location_search_tuple = coffee_utils.find_location_of_regex_in_files(function_regex, current_file_lines, [])
			if local_function_location_search_tuple:
				matched_location_tuple = local_function_location_search_tuple

		# ------ CURRENT FILE: ASSIGNMENT ------------------------

		if not matched_location_tuple:
			
			debug("Checking for local assignment of %s..." % selected_word)
			backwards_match_tuple = coffee_utils.search_backwards_for(current_file_lines, assignment_regex, selected_region)
			if backwards_match_tuple:
				filename_tuple = tuple([None])
				matched_location_tuple = filename_tuple + backwards_match_tuple
			else:
				# Nothing found. Now let's look backwards for a method parameter
				param_match_tuple = coffee_utils.search_backwards_for(current_file_lines, param_regex, selected_region)
				if param_match_tuple:
					filename_tuple = tuple([None])
					matched_location_tuple = filename_tuple + param_match_tuple	
				else:
					for_loop_match_tuple = coffee_utils.search_backwards_for(current_file_lines, for_loop_regex, selected_region)
					if for_loop_match_tuple:
						filename_tuple = tuple([None])
						matched_location_tuple = filename_tuple + for_loop_match_tuple
					# Otherwise, forwards search for it. It could be defined in the constructor.
					else:
						forwards_match_tuple = coffee_utils.find_location_of_regex_in_files(assignment_regex, current_file_lines, [])
						if forwards_match_tuple:
							matched_location_tuple = forwards_match_tuple

		# ------ GLOBAL SEARCH: FUNCTION -------------------------

		if not matched_location_tuple:

			# Coffeescript filename regex
			coffeescript_filename_regex = coffee_utils.COFFEE_FILENAME_REGEX
			# All coffeescript file paths
			all_coffee_file_paths = coffee_utils.get_files_in(project_folder_list, coffeescript_filename_regex, excluded_dirs)

			debug("Checking globally for function %s..." % selected_word)
			global_function_location_search_tuple = coffee_utils.find_location_of_regex_in_files(function_regex, None, all_coffee_file_paths)
			if global_function_location_search_tuple:
				matched_location_tuple = global_function_location_search_tuple

		# ------ DOT OPERATION LOOKUP (TBD) ----------------------
		# TODO: Pull out dot operator object, determine its assignment type, find class, goto method/property.
		#	    Also, determine where to put this lookup.

		# ------ SUPER METHOD LOOKUP (TBD) -----------------------
		# TODO: If selected_word is "super", assume a function and then attempt to find 
		#       extending class and open it to the function the cursor is within.

		# ------ STORE MATCH RESULTS -----------------------------
		# If not None, then we found something that matched the search!
		if matched_location_tuple:
			self.matched_location_tuple = matched_location_tuple