Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liam Cain
committed
Nov 29, 2011
1 parent
144db5a
commit 3b5b546
Showing
3 changed files
with
233 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
concat | ||
equals | ||
indexOf | ||
lastIndexOf | ||
length | ||
replace | ||
split | ||
startsWith | ||
substring | ||
trim | ||
valueOf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,122 @@ | ||
import sublime | ||
import sublime_plugin | ||
import re | ||
# import sublime | ||
# import sublime_plugin | ||
# import re | ||
# import os | ||
|
||
completions = [] | ||
# completions = [] | ||
|
||
class DisplayFunctionsCommand(sublime_plugin.TextCommand): | ||
# class DisplayFunctionsCommand(sublime_plugin.TextCommand): | ||
|
||
# def run(self, edit): | ||
|
||
def run(self, edit): | ||
# sel = self.view.sel()[0] | ||
# word = self.view.word(sel.end() - 1) | ||
# string = self.view.substr(word).strip() | ||
|
||
sel = self.view.sel()[0] | ||
word = self.view.word(sel.end() - 1) | ||
string = self.view.substr(word).strip() | ||
regions = self.view.find_all('(?<![\\w])' + re.escape(string) + '\\b') | ||
# if not self.is_proceeding_method(word): | ||
|
||
self.view.insert(edit, sel.end(), ".") # this is for when the plugin is eventually mapped to "." | ||
# regions = self.view.find_all('(?<![\\w])' + re.escape(string) + '\\b') | ||
|
||
for r in regions: | ||
prev_end = r.begin() - 2 | ||
prev_word = self.view.word(prev_end) | ||
# self.view.insert(edit, sel.end(), ".") | ||
|
||
if "storage.type" in self.view.scope_name(prev_word.begin()): | ||
print "Class: " + self.view.substr(prev_word) | ||
self.add_functions(self.view.substr(prev_word)) | ||
# for r in regions: | ||
# prev_end = r.begin() - 2 | ||
# prev_word = self.view.word(prev_end) | ||
|
||
self.view.run_command('auto_complete', {'disable_auto_insert': True}) | ||
break | ||
|
||
return | ||
# if "storage.type" in self.view.scope_name(prev_word.begin()): | ||
# print "Class: " + self.view.substr(prev_word) | ||
# self.add_functions(self.view.substr(prev_word)) | ||
|
||
# self.view.run_command('auto_complete', {'disable_auto_insert': True}) | ||
# break | ||
|
||
# return | ||
|
||
# def get_package_dir(self): | ||
# return os.path.join(sublime.packages_path(), "Display-Functions") | ||
|
||
#This function will take a classname and return a list of all the class methods | ||
#Will use find_by_selector(selector) | ||
def add_functions(self, classname): | ||
|
||
# def prev(self, word): | ||
# return self.view.word(word.begin() - 2) | ||
# def next(self, word): | ||
# return self.view.word(word.end() + 2) | ||
|
||
# def get_type(self, current_word): | ||
# string = self.view.substr(current_word) | ||
# regions = self.view.find_all('(?<![\\w])' + re.escape(string) + '\\b') | ||
# for r in regions: | ||
# prev_word = self.prev(r) | ||
# print self.view.substr(prev_word) | ||
|
||
# if "storage.type" in self.view.scope_name(prev_word.begin()): | ||
# return self.view.substr(prev_word) | ||
|
||
this_file = self.view.file_name() | ||
print this_file | ||
|
||
|
||
# def is_proceeding_method(self, word): | ||
# prev_word = self.prev(word) | ||
# while "storage.type" in self.view.scope_name(prev_word.begin()): | ||
# prev_word = self.view.word(prev_word.begin() - 2) | ||
# current_word = prev_word | ||
|
||
dir_len = this_file.rfind('/') #(for OSX) | ||
# word_type = self.get_type(current_word) | ||
# regions = self.view.find_all('(?<![\\w])' + re.escape(word_type) + '\\b') | ||
|
||
|
||
# for r in regions: | ||
# prev_word = self.prev(r) | ||
# print self.view.substr(prev_word) | ||
|
||
# if "storage.type" in self.view.scope_name(prev_word.begin()): | ||
# print "method" | ||
# with open(filename, 'r') as f: | ||
# read_data = f.read() | ||
# current_word = self.next(current_word) | ||
# return_type = self.prev(re.find(current_word)) | ||
# print return_type | ||
# return True | ||
|
||
|
||
# def check_str(self, classname, check_name): | ||
# if classname == check_name: | ||
# check_path = os.path.join(self.get_package_dir(), check_name) | ||
# check_path += '.txt' | ||
# print check_path | ||
|
||
# with open(check_path, 'r') as f: | ||
# str_fun = f.read().splitlines() | ||
# return str_fun | ||
|
||
# #This function will take a classname and return a list of all the class methods | ||
# #Will use find_by_selector(selector) | ||
# def add_functions(self, classname): | ||
|
||
# methods = self.check_str(classname, "String") | ||
|
||
if not dir_len > 0: | ||
dir_len = this_file.rfind('\\') #(for Windows) | ||
# if not methods: | ||
# this_file = self.view.file_name() | ||
|
||
this_dir = this_file[:(dir_len + 1)] # + 1 for the '/' | ||
filename = this_dir + classname + ".java" | ||
# dir_len = this_file.rfind('/') #(for OSX) | ||
|
||
print filename | ||
# if not dir_len > 0: | ||
# dir_len = this_file.rfind('\\') #(for Windows) | ||
|
||
with open(filename, 'r') as f: | ||
read_data = f.read() | ||
methods = re.findall("(\w+)\s*\(", read_data) #Regex taken from Java.tmLanguage (needs fix) | ||
# this_dir = this_file[:(dir_len + 1)] # + 1 for the '/' | ||
# filename = this_dir + classname + ".java" | ||
|
||
methods = list(set(methods)) #to remove duplicates | ||
# with open(filename, 'r') as f: | ||
# read_data = f.read() | ||
# methods = re.findall("(\w+)\s*\(", read_data) #Regex taken from Java.tmLanguage | ||
|
||
print 'methods: ' | ||
print methods | ||
# methods = list(set(methods)) #to remove duplicates | ||
|
||
del completions[:] | ||
# del completions[:] | ||
|
||
for m in methods: | ||
completions.append(m + "()") | ||
# for m in methods: | ||
# m.strip('h') | ||
# completions.append(m + "()") | ||
|
||
|
||
class FillAutoComplete(sublime_plugin.EventListener): | ||
def on_query_completions(self, view, prefix, locations): | ||
return [(x, x) for x in completions] | ||
# class FillAutoComplete(sublime_plugin.EventListener): | ||
# def on_query_completions(self, view, prefix, locations): | ||
# return [(x, x) for x in completions] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import sublime | ||
import sublime_plugin | ||
import re | ||
import os | ||
|
||
completions = [] | ||
|
||
class DisplayFunctionsCommand(sublime_plugin.TextCommand): | ||
|
||
# while previous word is a method | ||
# go back && count ++ | ||
|
||
# now have root word | ||
|
||
# get type of root | ||
#while less than count | ||
# open up file | ||
# get return type of next method | ||
|
||
#open up file and get methods... | ||
# | ||
|
||
def run(self, edit): | ||
|
||
sel = self.view.sel()[0] | ||
word = self.view.word(sel.end() - 1) | ||
#string = self.view.substr(word).strip() | ||
count = 0 | ||
|
||
prev_word = self.prev(word) | ||
|
||
print self.view.substr(prev_word) | ||
|
||
return | ||
|
||
while "meta.method" in self.view.scope_name(prev_word.begin()): | ||
prev_word = self.prev(prev_word) | ||
count = count + 1 | ||
|
||
root = prev_word | ||
|
||
return | ||
|
||
return_type = self.get_type(root) | ||
|
||
i = 0 | ||
while i < count: | ||
filename = self.make_filename(return_type) | ||
with open(filename, 'r') as f: | ||
read_data = f.read() | ||
return_type = re.search('(\w+)\W+\w+$', read_data) | ||
print return_type | ||
|
||
self.add_functions(return_type) | ||
|
||
def make_filename(self, classname): | ||
this_file = self.view.file_name() | ||
|
||
dir_len = this_file.rfind('/') #(for OSX) | ||
|
||
if not dir_len > 0: | ||
dir_len = this_file.rfind('\\') #(for Windows) | ||
|
||
this_dir = this_file[:(dir_len + 1)] # + 1 for the '/' | ||
return this_dir + classname + ".java" | ||
|
||
def get_package_dir(self): | ||
return os.path.join(sublime.packages_path(), "Display-Functions") | ||
|
||
def prev(self, word): | ||
return self.view.word(word.begin() - 2) | ||
|
||
def next(self, word): | ||
return self.view.word(word.end() + 2) | ||
|
||
def get_type(self, current_word): | ||
string = self.view.substr(current_word) | ||
regions = self.view.find_all('(?<![\\w])' + re.escape(string) + '\\b') | ||
for r in regions: | ||
prev_word = self.prev(r) | ||
print self.view.substr(prev_word) | ||
|
||
if "storage.type" in self.view.scope_name(prev_word.begin()): | ||
return self.view.substr(prev_word) | ||
|
||
def check_str(self, classname, check_name): | ||
if classname == check_name: | ||
check_path = os.path.join(self.get_package_dir(), check_name) | ||
check_path += '.txt' | ||
print check_path | ||
|
||
with open(check_path, 'r') as f: | ||
str_fun = f.read().splitlines() | ||
return str_fun | ||
|
||
#This function will take a classname and return a list of all the class methods | ||
#Will use find_by_selector(selector) | ||
def add_functions(self, classname): | ||
|
||
methods = self.check_str(classname, "String") | ||
|
||
if not methods: | ||
|
||
filename = self.make_filename(classname) | ||
|
||
with open(filename, 'r') as f: | ||
read_data = f.read() | ||
methods = re.findall("(\w+)\s*\(", read_data) #Regex taken from Java.tmLanguage | ||
|
||
methods = list(set(methods)) #to remove duplicates | ||
|
||
del completions[:] | ||
|
||
for m in methods: | ||
m.strip('h') | ||
completions.append(m + "()") | ||
|
||
|
||
class FillAutoComplete(sublime_plugin.EventListener): | ||
def on_query_completions(self, view, prefix, locations): | ||
return [(x, x) for x in completions] |