def run(self, edit):

        # Get the window
        self.window = sublime.active_window()

        # The current view
        view = self.view
        # Lines for currently viewed file
        current_file_lines = coffee_utils.get_view_content_lines(view)

        # Get currently selected word
        coffee_utils.select_current_word(view)
        selected_word = coffee_utils.get_selected_word(view)

        selected_region = self.view.sel()[0]

        # http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9076
        settings = sublime.load_settings(coffee_utils.SETTINGS_FILE_NAME)

        # Pull the excluded dirs from preferences
        excluded_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_EXCLUDED_DIRS)
        if not excluded_dirs:
            excluded_dirs = []

        restricted_to_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_RESTRICTED_TO_PATHS)
        if not restricted_to_dirs:
            restricted_to_dirs = []

            # List of all project folders
        project_folder_list = self.window.folders()

        if restricted_to_dirs:
            specific_project_folders = []
            for next_restricted_dir in restricted_to_dirs:
                for next_project_folder in project_folder_list:
                    next_specific_folder = os.path.normpath(os.path.join(next_project_folder, next_restricted_dir))
                    specific_project_folders.append(next_specific_folder)
            project_folder_list = specific_project_folders

            # If there is a word selection and we're looking at a coffee file...
        if len(selected_word) > 0 and coffee_utils.is_coffee_syntax(view):

            thread = CoffeeGotoDefinitionThread(
                project_folder_list, current_file_lines, selected_word, excluded_dirs, selected_region
            )
            thread.start()
            self.check_operation(thread)
Exemple #2
0
	def run(self, edit):

		# Get the window
		self.window = sublime.active_window()

		# The current view
		view = self.view
		# Lines for currently viewed file
		current_file_lines = coffee_utils.get_view_content_lines(view)
		
		# Get currently selected word
		coffee_utils.select_current_word(view)
		selected_word = coffee_utils.get_selected_word(view)

		selected_region = self.view.sel()[0]

		# http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9076
		settings = sublime.load_settings(coffee_utils.SETTINGS_FILE_NAME)

		# Pull the excluded dirs from preferences
		excluded_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_EXCLUDED_DIRS)
		if not excluded_dirs:
			excluded_dirs = []

		restricted_to_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_RESTRICTED_TO_PATHS)
		if not restricted_to_dirs:
			restricted_to_dirs = []

		# List of all project folders
		project_folder_list = self.window.folders()

		if restricted_to_dirs:
			specific_project_folders = []
			for next_restricted_dir in restricted_to_dirs:
				for next_project_folder in project_folder_list:
					next_specific_folder = os.path.normpath(os.path.join(next_project_folder, next_restricted_dir))
					specific_project_folders.append(next_specific_folder)
			project_folder_list = specific_project_folders

		# If there is a word selection and we're looking at a coffee file...
		if len(selected_word) > 0 and coffee_utils.is_coffee_syntax(view):

			thread = CoffeeGotoDefinitionThread(project_folder_list, current_file_lines, selected_word, excluded_dirs, selected_region)
			thread.start()
			self.check_operation(thread)
Exemple #3
0
    def on_query_completions(self, view, prefix, locations):

        completions = copy(final_completions)
        working = status["working"]

        # If there is a word selection and we're looking at a coffee file...
        if not completions and coffee_utils.is_coffee_syntax(
                view) and not working:
            if not view.match_selector(locations[0], "source.coffee -comment"):
                return []

            status["working"] = True

            current_location = locations[0]

            # Get the window
            self.window = sublime.active_window()

            # http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9076
            settings = sublime.load_settings(coffee_utils.SETTINGS_FILE_NAME)

            built_in_types_settings = sublime.load_settings(
                coffee_utils.BUILT_IN_TYPES_SETTINGS_FILE_NAME)
            built_in_types = built_in_types_settings.get(
                coffee_utils.BUILT_IN_TYPES_SETTINGS_KEY)
            if not built_in_types:
                built_in_types = []

            custom_types_settings = sublime.load_settings(
                coffee_utils.CUSTOM_TYPES_SETTINGS_FILE_NAME)
            custom_types = custom_types_settings.get(
                coffee_utils.CUSTOM_TYPES_SETTINGS_KEY)
            if not custom_types:
                custom_types = []

            built_in_types.extend(custom_types)

            # Pull the excluded dirs from preferences
            excluded_dirs = settings.get(
                coffee_utils.PREFERENCES_COFFEE_EXCLUDED_DIRS)
            if not excluded_dirs:
                excluded_dirs = []

            restricted_to_dirs = settings.get(
                coffee_utils.PREFERENCES_COFFEE_RESTRICTED_TO_PATHS)
            if not restricted_to_dirs:
                restricted_to_dirs = []

            # List of all project folders
            project_folder_list = self.window.folders()

            if restricted_to_dirs:
                specific_project_folders = []
                for next_restricted_dir in restricted_to_dirs:
                    for next_project_folder in project_folder_list:
                        next_specific_folder = os.path.normpath(
                            os.path.join(next_project_folder,
                                         next_restricted_dir))
                        specific_project_folders.append(next_specific_folder)
                project_folder_list = specific_project_folders

            function_return_types = settings.get(
                coffee_utils.FUNCTION_RETURN_TYPES_SETTINGS_KEY)
            if not function_return_types:
                function_return_types = []

            this_aliases = settings.get(coffee_utils.PREFERENCES_THIS_ALIASES)
            if not this_aliases:
                this_aliases = []

            member_exclusion_regexes = settings.get(
                coffee_utils.PREFERENCES_MEMBER_EXCLUSION_REGEXES)
            if not member_exclusion_regexes:
                member_exclusion_regexes = []

            # Lines for the current file in view
            current_file_lines = coffee_utils.get_view_content_lines(view)

            # TODO: Smarter previous word selection
            preceding_symbol = coffee_utils.get_preceding_symbol(
                view, prefix, locations)
            immediately_preceding_symbol = coffee_utils.get_preceding_symbol(
                view, "", locations)

            preceding_function_call = coffee_utils.get_preceding_function_call(
                view).strip()

            # Determine preceding token, if any (if a period was typed).
            token = coffee_utils.get_preceding_token(view).strip()

            # TODO: Smarter region location
            symbol_region = sublime.Region(locations[0] - len(prefix),
                                           locations[0] - len(prefix))

            if (preceding_function_call or token
                    or coffee_utils.THIS_SUGAR_SYMBOL == preceding_symbol
                ) and coffee_utils.is_autocomplete_trigger(
                    immediately_preceding_symbol):
                self.window.active_view().run_command('hide_auto_complete')

                thread = CoffeeAutocompleteThread(
                    project_folder_list, excluded_dirs, this_aliases,
                    current_file_lines, preceding_symbol, prefix,
                    preceding_function_call, function_return_types, token,
                    symbol_region, built_in_types, member_exclusion_regexes)
                thread.start()
                self.check_operation(thread, final_completions,
                                     current_location, token, status)
            else:
                status["working"] = False

        elif completions:
            self.clear_completions(final_completions)

        return completions
	def on_query_completions(self, view, prefix, locations):

		completions = copy(final_completions)
		working = status["working"]

		# If there is a word selection and we're looking at a coffee file...
		if not completions and coffee_utils.is_coffee_syntax(view) and not working:
			if not view.match_selector(locations[0], "source.coffee -comment"):
				return []

			status["working"] = True

			current_location = locations[0]

			# Get the window
			self.window = sublime.active_window()

			# http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9076
			settings = sublime.load_settings(coffee_utils.SETTINGS_FILE_NAME)

			built_in_types_settings = sublime.load_settings(coffee_utils.BUILT_IN_TYPES_SETTINGS_FILE_NAME)
			built_in_types = built_in_types_settings.get(coffee_utils.BUILT_IN_TYPES_SETTINGS_KEY)
			if not built_in_types:
				built_in_types = []

			custom_types_settings = sublime.load_settings(coffee_utils.CUSTOM_TYPES_SETTINGS_FILE_NAME)
			custom_types = custom_types_settings.get(coffee_utils.CUSTOM_TYPES_SETTINGS_KEY)
			if not custom_types:
				custom_types = []

			built_in_types.extend(custom_types)

			# Pull the excluded dirs from preferences
			excluded_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_EXCLUDED_DIRS)
			if not excluded_dirs:
				excluded_dirs = []

			restricted_to_dirs = settings.get(coffee_utils.PREFERENCES_COFFEE_RESTRICTED_TO_PATHS)
			if not restricted_to_dirs:
				restricted_to_dirs = []

			# List of all project folders
			project_folder_list = self.window.folders()

			if restricted_to_dirs:
				specific_project_folders = []
				for next_restricted_dir in restricted_to_dirs:
					for next_project_folder in project_folder_list:
						next_specific_folder = os.path.normpath(os.path.join(next_project_folder, next_restricted_dir))
						specific_project_folders.append(next_specific_folder)
				project_folder_list = specific_project_folders

			function_return_types = settings.get(coffee_utils.FUNCTION_RETURN_TYPES_SETTINGS_KEY)
			if not function_return_types:
				function_return_types = []

			this_aliases = settings.get(coffee_utils.PREFERENCES_THIS_ALIASES)
			if not this_aliases:
				this_aliases = []

			member_exclusion_regexes = settings.get(coffee_utils.PREFERENCES_MEMBER_EXCLUSION_REGEXES)
			if not member_exclusion_regexes:
				member_exclusion_regexes = []

			# Lines for the current file in view
			current_file_lines = coffee_utils.get_view_content_lines(view)

			# TODO: Smarter previous word selection
			preceding_symbol = coffee_utils.get_preceding_symbol(view, prefix, locations)
			immediately_preceding_symbol = coffee_utils.get_preceding_symbol(view, "", locations)

			preceding_function_call = coffee_utils.get_preceding_function_call(view).strip()

			# Determine preceding token, if any (if a period was typed).
			token = coffee_utils.get_preceding_token(view).strip()

			# TODO: Smarter region location
			symbol_region = sublime.Region(locations[0] - len(prefix), locations[0] - len(prefix))

			if (preceding_function_call or token or coffee_utils.THIS_SUGAR_SYMBOL == preceding_symbol) and coffee_utils.is_autocomplete_trigger(immediately_preceding_symbol):
				self.window.active_view().run_command('hide_auto_complete')

				thread = CoffeeAutocompleteThread(project_folder_list, excluded_dirs, this_aliases, current_file_lines, preceding_symbol, prefix, preceding_function_call, function_return_types, token, symbol_region, built_in_types, member_exclusion_regexes)
				thread.start()
				self.check_operation(thread, final_completions, current_location, token, status)
			else: 
				status["working"] = False

		elif completions:
			self.clear_completions(final_completions)

		return completions