Skip to content

Commit 51a006b

Browse files
committed
Middle word completion
1 parent 0935661 commit 51a006b

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

typescript.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,34 @@ def format_diffs(old_content, new_content):
4646
prefixes = {
4747
"method": u"◉",
4848
"property": u"●",
49-
"class":u"⊗"
49+
"class":u"◆",
50+
"interface":u"◇",
51+
"keyword":u"∆",
52+
"variable": u"∨",
5053
}
5154

55+
js_id_re = re.compile(
56+
ur'^[_$a-zA-Z\u00FF-\uFFFF][_$a-zA-Z0-9\u00FF-\uFFFF]*'
57+
)
58+
59+
def is_member_completion(line):
60+
61+
def partial_completion():
62+
print "IN partial_completion"
63+
print line
64+
sp = line.split(".")
65+
if len(sp) > 1:
66+
print "OKAY"
67+
return js_id_re.match(sp[-1]) is not None
68+
print "NOTOKAY"
69+
return False
70+
71+
return line.endswith(".") or partial_completion()
72+
73+
74+
5275
def format_completion_entry(c_entry):
53-
prefix = prefixes[c_entry["kind"]]
76+
prefix = prefixes.get(c_entry["kind"], u"-")
5477
prefix += " "
5578
middle = c_entry["name"]
5679
suffix = "\t" + c_entry["type"]
@@ -128,7 +151,8 @@ def msg(self, *args):
128151
message = json.dumps(args) + "\n"
129152
t = time()
130153
self.p.stdin.write(message)
131-
res = json.loads(self.p.stdout.readline())
154+
msg_content = self.p.stdout.readline()
155+
res = json.loads(msg_content)
132156
return res
133157

134158
def serv_add_file(self, file_name):
@@ -373,10 +397,13 @@ def on_query_completions(self, view, prefix, locations):
373397
if is_ts(view):
374398
# Get the position of the cursor (first one in case of multiple sels)
375399
pos = view.sel()[0].begin()
376-
line = view.substr(sublime.Region(view.word(pos-1).a, pos))
377-
# Determine wether it is a member completion or not
378-
is_member = line.endswith(".")
379-
completions_json = get_plugin(view).serv_get_completions(view.file_name(), pos, is_member)
400+
line = view.substr(sublime.Region(view.line(pos-1).a, pos))
401+
bword_pos = sublime.Region(view.word(pos).a, pos)
402+
word = view.substr(bword_pos)
403+
print "WORD : ", word
404+
completions_json = get_plugin(view).serv_get_completions(
405+
view.file_name(), bword_pos.a, is_member_completion(line)
406+
)
380407
get_plugin(view).set_error_status(view)
381408
return completions_ts_to_sublime(completions_json)
382409

0 commit comments

Comments
 (0)