Beispiel #1
0
class PatternSearchLogic():
	def __init__(self, word):
		self.files = []
		self.word = word

		self.patterns = Patterns()
		self.patterns.reset()
		self.patterns.init_common_patterns(self.word)


	def find_patterns_in_line(self, line, number, fn):
		for pattern in self.patterns.get_patterns():
			match = pattern.search(line)
			if match:
				self.files.append((fn, number))
				break
				
	def run(self):
		print "[G2f] Searching for 'function " + self.word + "'..."
		
		del self.files[:]
	
		file_search_manager.check_project_folders(self.find_patterns_in_line)
	
		result = file_search_manager.show_search_results(self.files)
			
		if not result:
			print "[G2f] " + self.word + " not found"
Beispiel #2
0
    def __init__(self, word):
        self.files = []
        self.word = word

        self.patterns = Patterns()
        self.patterns.reset()
        self.patterns.init_common_patterns(self.word)
Beispiel #3
0
class PatternSearchLogic():
    def __init__(self, word):
        self.files = []
        self.word = word

        self.patterns = Patterns()
        self.patterns.reset()
        self.patterns.init_common_patterns(self.word)

    def find_patterns_in_line(self, line, number, fn):
        for pattern in self.patterns.get_patterns():
            match = pattern.search(line)
            if match:
                self.files.append((fn, number))
                break

    def run(self):
        print "[G2f] Searching for 'function " + self.word + "'..."

        del self.files[:]

        file_search_manager.check_project_folders(self.find_patterns_in_line)

        result = file_search_manager.show_search_results(self.files)

        if not result:
            print "[G2f] " + self.word + " not found"
Beispiel #4
0
	def __init__(self, word):
		self.files = []
		self.word = word

		self.patterns = Patterns()
		self.patterns.reset()
		self.patterns.init_common_patterns(self.word)
	def __init__(self, view):
		self.view = view
		self.patterns = Patterns()
class AutocompleteSearchLogic():
	def __init__(self, view):
		self.view = view
		self.patterns = Patterns()

	def run(self):
		view = self.view

		self.patterns.reset()
		Settings.reset()
		
		AutocompleteList.clear()
	
		prev_word = SelectedRegion(view).get_previous_word()
	
		if (Constants.SELF_WORD == prev_word):
			class_names = self.find_class_names()
		else:
			class_names = [prev_word]
	
		if (len(class_names) > 0):
			for class_name in class_names:
				self.patterns.init_autocomplete_patterns(class_name)
			file_search_manager.check_project_folders(self.find_methods_in_line)
			
			Settings.get_word_param().enable(False)
			Settings.get_explicit_param().enable(False)
			Settings.get_autocomplete_param().enable(True)
	
			view.run_command("auto_complete")
		else:
			print "[G2f] could not find function definition"


	def find_class_names(self):
		view = self.view
		word = None
		class_region = None
	
		selection_region = view.sel()[0]
		regions = view.find_by_selector('meta.class.simple.lua')
		regions = regions + view.find_by_selector('meta.class.derived.lua')
			
		for region in regions:
			if region.a < selection_region.a:
				class_region = region
	
		classes = []
		if class_region:
			word = view.substr(class_region)
			words = re.sub("[\'\"\(\)]", ' ', word).strip().split()
				
		classes.append(str(words[1]))
		if (len(words) > 2):
			classes.append(str(words[2]))
			
		return classes

	def find_methods_in_line(self, line, number, fn):
		if (Constants.FUNCTION in line) and (
			(Constants.POINT in line) or (Constants.COLON in line)):
			
			for pattern in self.patterns.get_patterns():
				match = pattern.search(line)
				if match:
					method = match.group(0)
					
					start_pos = line.find(Constants.COLON)
					if (start_pos < 0):
						start_pos = line.find(Constants.POINT)
					end_pos = line.find(')')
					if ((start_pos > 0) and (end_pos > start_pos)):
						subs = line[start_pos + 1 : end_pos + 1]
	
						method = re.sub("[.:\(\)]", ' ', method).strip().split()
						method = method[2]
						out = (method, subs)
	
					AutocompleteList.append(out)
Beispiel #7
0
 def __init__(self, view):
     self.view = view
     self.patterns = Patterns()
Beispiel #8
0
class AutocompleteSearchLogic():
    def __init__(self, view):
        self.view = view
        self.patterns = Patterns()

    def run(self):
        view = self.view

        self.patterns.reset()
        Settings.reset()

        AutocompleteList.clear()

        prev_word = SelectedRegion(view).get_previous_word()

        if (Constants.SELF_WORD == prev_word):
            class_names = self.find_class_names()
        else:
            class_names = [prev_word]

        if (len(class_names) > 0):
            for class_name in class_names:
                self.patterns.init_autocomplete_patterns(class_name)
            file_search_manager.check_project_folders(
                self.find_methods_in_line)

            Settings.get_word_param().enable(False)
            Settings.get_explicit_param().enable(False)
            Settings.get_autocomplete_param().enable(True)

            view.run_command("auto_complete")
        else:
            print "[G2f] could not find function definition"

    def find_class_names(self):
        view = self.view
        word = None
        class_region = None

        selection_region = view.sel()[0]
        regions = view.find_by_selector('meta.class.simple.lua')
        regions = regions + view.find_by_selector('meta.class.derived.lua')

        for region in regions:
            if region.a < selection_region.a:
                class_region = region

        classes = []
        if class_region:
            word = view.substr(class_region)
            words = re.sub("[\'\"\(\)]", ' ', word).strip().split()

        classes.append(str(words[1]))
        if (len(words) > 2):
            classes.append(str(words[2]))

        return classes

    def find_methods_in_line(self, line, number, fn):
        if (Constants.FUNCTION in line) and ((Constants.POINT in line) or
                                             (Constants.COLON in line)):

            for pattern in self.patterns.get_patterns():
                match = pattern.search(line)
                if match:
                    method = match.group(0)

                    start_pos = line.find(Constants.COLON)
                    if (start_pos < 0):
                        start_pos = line.find(Constants.POINT)
                    end_pos = line.find(')')
                    if ((start_pos > 0) and (end_pos > start_pos)):
                        subs = line[start_pos + 1:end_pos + 1]

                        method = re.sub("[.:\(\)]", ' ',
                                        method).strip().split()
                        method = method[2]
                        out = (method, subs)

                    AutocompleteList.append(out)
Beispiel #9
0
	def __init__(self, *args, **kw):
		super(GoToFieldCommand, self).__init__(*args, **kw)
		
		self.files = []
		self.project_files = []
		self.patterns = Patterns()
Beispiel #10
0
class GoToFieldCommand(sublime_plugin.TextCommand):
	def __init__(self, *args, **kw):
		super(GoToFieldCommand, self).__init__(*args, **kw)
		
		self.files = []
		self.project_files = []
		self.patterns = Patterns()

	def run(self, text):
		t1 = time.clock()
		
		del self.files[:]

		self.patterns.reset()
		Settings.reset()
		
		AutocompleteList.clear()

		self.do_search()

		t2 = time.clock()
		print t2 - t1

	def do_search(self):
		prev_word = SelectedRegion(self.view).get_previous_word()

		if (Constants.SELF_WORD != prev_word):
			self.patterns.init_table_patterns(prev_word)
			self.check_project_folders(self.check_pattern_in_lines)
		
			Settings.get_word_param().enable(False)
			Settings.get_explicit_param().enable(False)
			Settings.get_autocomplete_param().enable(True)

			self.view.run_command("auto_complete")
		else:
			print "[G2f] Could not find function definition"

	def check_project_folders(self, callback):
		if (0 == len(self.project_files)):
			for folder in sublime.active_window().folders():
				for r, d, f in os.walk(folder):
					if Directory(r).should_check():
						for files in f:
							fn = os.path.join(r, files)
							if File(fn).should_check():
								self.project_files.append(fn)
								file_search_manager.check_file(fn, callback, True)
		else:
			print "[G2f] " + str(len(self.project_files)) + " files in cach to check."
			for fn in self.project_files:
				file_search_manager.check_file(fn, callback, True)

	def check_pattern_in_lines(self, lines):
		for pattern in self.patterns.get_patterns():
			for (content) in re.findall(pattern, lines):
				words = content.split('\n')
				for word in words:
					if Constants.EQUAL in word:
						word = word.split(Constants.EQUAL)[0].strip()
						out = (word, word)
						AutocompleteList.append(out)