Skip to content

Commit 56c712a

Browse files
committed
implement better handling of comments, strings, ifdefs and states
1 parent a333f74 commit 56c712a

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

Haxe.sublime-settings

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"auto_complete_selectors": "source - (string, comment, keyword.control.directive.conditional.haxe)",
2+
"auto_complete_selector": "source - (comment, string.quoted, keyword.control.directive.conditional.haxe)",
3+
"auto_complete_selectors": "source - (comment, string.quoted, keyword.control.directive.conditional.haxe)",
34
"auto_complete_triggers": [
45
{"selector": "source.haxe", "characters": "."}
56
]

flow.py

+47-30
Original file line numberDiff line numberDiff line change
@@ -115,72 +115,89 @@ def on_query_completions(self, view, prefix, locations):
115115

116116
_res = self.completion(view, view.file_name())
117117

118-
if _res is None:
119118
#explicitly no completion
119+
if _res is None:
120+
# print('[flow] completion res was none')
120121
return ([], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
121122
else:
122123
if(len(_res)):
123124
return (_res, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
125+
# else:
126+
# print('[flow] completion _res `{}`'.format(_res))
124127

125128
def completion(self, view, fname):
126129

127130
if self.flow_file == "" or self.flow_file is None:
128131
sublime.status_message("No flow file, right click in a flow file! {}".format(str(self.flow_file)))
132+
# print('[flow] completion return [], no flow file')
129133
return []
130134

131135
if not self.hxml_data:
132136
sublime.status_message("no info/hxml for flow file, caching...")
133137
self.refresh_info()
134138

135-
sel = view.sel()[0]
136-
word = view.word(sel)
139+
#ignore strings, comments, #if conditionals, for some reason the triggers won't work
140+
ifsel = view.sel()[0]
141+
ifsel.a -= 2; ifsel.b -= 2
142+
scsel = view.sel()[0]
143+
ifdef_score = view.score_selector(ifsel.begin(), "source - (keyword.control.directive.conditional.haxe)")
144+
scope_score = view.score_selector(scsel.begin(), "source - (comment, string.quoted, keyword.control.directive.conditional.haxe)")
145+
# print('[flow] ifdef score `{}`'.format(str(ifdef_score)))
146+
# print('[flow] scope score `{}`'.format(str(scope_score)))
147+
148+
if scope_score <= 0 or ifdef_score <= 0:
149+
# print('[flow] ignore invalid scope for completion')
150+
return None
137151

138-
if len(word) == 0:
139-
return []
152+
sel = view.sel()[0]; sel.a -= 1
153+
ch = view.substr(sel)
154+
# print('[flow] completion ch `{}`'.format(ch))
155+
156+
if ch != "." and ch != "(":
157+
# print('[flow] ignore completion by non . or (')
158+
return None
140159

141-
ch = view.substr(word)[0]
142160
code = view.substr(sublime.Region(0, view.size()))
143-
prior = code[0:sel.begin()].encode('utf-8')
161+
prior = code[0:view.sel()[0].begin()].encode('utf-8')
144162
offset = len(prior)
145163

146164
cwd = self.get_working_dir()
147165
filename = fname
148166

149-
if ch == "." or ch == "(":
150-
151-
from sublime_haxe.haxe_completion import _completionist_
167+
from sublime_haxe.haxe_completion import _completionist_
152168

153-
self.completion_file = fname
154-
self.completion_view = view
155-
self.completion_data = None
169+
self.completion_file = fname
170+
self.completion_view = view
171+
self.completion_data = None
156172

157-
_hxml = self.hxml_data.splitlines()
173+
_hxml = self.hxml_data.splitlines()
158174

159-
self.completion_pending = True
175+
self.completion_pending = True
160176

161-
self.completion_start_time = time.time()
177+
self.completion_start_time = time.time()
162178

163-
self.save_file_for_completion(view, fname)
179+
self.save_file_for_completion(view, fname)
164180

165-
result = _completionist_.complete(cwd, filename, offset, _hxml)
181+
result = _completionist_.complete(cwd, filename, offset, _hxml)
166182

167-
self.restore_file_post_completion()
183+
self.restore_file_post_completion()
168184

169-
time_diff = time.time() - self.completion_start_time
170-
print("[flow] completion took {}".format(time_diff))
171-
# print("[flow]\n{}".format(result))
185+
time_diff = time.time() - self.completion_start_time
186+
print("[flow] completion took {}".format(time_diff))
187+
# print("[flow]\n{}".format(result))
172188

173-
_err = haxe_has_error(result)
174-
if _err:
175-
return self.show_errors(view, _err)
189+
if not result:
190+
return None
176191

177-
_args = haxe_has_args(result)
178-
if _args:
179-
return self.show_args(view, _args)
192+
_err = haxe_has_error(result)
193+
if _err:
194+
return self.show_errors(view, _err)
180195

181-
return haxe_completion_list(result)
196+
_args = haxe_has_args(result)
197+
if _args:
198+
return self.show_args(view, _args)
182199

183-
return []
200+
return haxe_completion_list(result)
184201

185202
def show_errors(self, view, errs):
186203

0 commit comments

Comments
 (0)