def get_text(self): view = self.window.active_view() name = self.name mod, idx = self.get_mods( name, False, True, self.context.type.group == 'abstract', self.static) types = None ret = None if SCOPE_PARAMETERS in self.context.scope and \ self.caret_name: param_type = self.get_param_type() if param_type: tp = param_type[0].split(':')[1].strip() types, ret = parse_sig(tp) if types is not None: types = [shorten_imported_type( tp, self.context.imports) for tp in types] if ret is not None: ret = shorten_imported_type(ret, self.context.imports) if 'var' in self.field: text = '%svar %s:%s$0;' text = format_statement(view, text) if ret is None: ret = 'Dynamic' if types is not None: if not types: types.append('Void') types.append(ret) ret = '$HX_W_AR->${HX_AR_W}'.join(types) text = text % ( mod, '${%d:%s}' % (idx, name), '${%d:%s}' % (idx + 1, ret)) else: text = '%sfunction %s(%s):%s$HX_W_OCB{\n\t$0\n}' text = format_statement(view, text) params = '' if ret is None: ret = 'Void' ret_idx = idx + 2 param_idx = 1 if types: for tp in types: if params: params += '$HX_W_CM,${HX_CM_W}' params += '${%d:p%d}$HX_W_C:${HX_C_W}%s' % ( ret_idx, param_idx, tp) ret_idx += 1 param_idx += 1 text = text % ( mod, '${%d:%s}' % (idx, name), '${%d:%s}' % (idx + 1, params), '${%d:%s}' % (ret_idx, ret)) return text
def on_select(self, index): if index == -1: return view = self.window.active_view() field = self.methods[index] ftype = FIELD_FUNC fname = field[0] fparams = ','.join(field[1]) fparams = format_statement(view, fparams) fparams = re_type_path.sub(r'\2', fparams) fargs = ','.join([s.partition(':')[0].strip() for s in field[1]]) fargs = format_statement(view, fargs) ret = format_statement(view, field[2]) ret = re_type_path.sub(r'\2', ret) ftext = \ get_editable_mods(view, 1, 0, 1, 1, 0, 0, 0, 1) +\ 'function ' +\ '%s$HX_W_ORB(${HX_ORB_W}%s$HX_W_CRB)$HX_CRB_W_C:${HX_C_W}%s' +\ '$HX_W_OCB{\n\t' +\ ('' if ret == 'Void' else '${2:return }') +\ '${3:super.%s(${HX_ORB_W}%s$HX_W_CRB);}$0' +\ '\n}' ftext = ftext % (fname, fparams, ret, fname, fargs) self.window.run_command('haxe_generate_field', { 'name': fname, 'field': ftype, 'text': ftext, 'move': True })
def on_select(self, index): if index == -1: return view = self.window.active_view() field = self.methods[index] ftype = FIELD_FUNC fname = field[0] fparams = ','.join(field[1]) fparams = format_statement(view, fparams) fparams = re_type_path.sub(r'\2', fparams) fargs = ','.join([s.partition(':')[0].strip() for s in field[1]]) fargs = format_statement(view, fargs) ret = format_statement(view, field[2]) ret = re_type_path.sub(r'\2', ret) ftext = \ get_editable_mods(view, 1, 0, 1, 1, 0, 0, 0, 1) +\ 'function ' +\ '%s$HX_W_ORB(${HX_ORB_W}%s$HX_W_CRB)$HX_CRB_W_C:${HX_C_W}%s' +\ '$HX_W_OCB{\n\t' +\ ('' if ret == 'Void' else '${2:return }') +\ '${3:super.%s(${HX_ORB_W}%s$HX_W_CRB);}$0' +\ '\n}' ftext = ftext % (fname, fparams, ret, fname, fargs) self.window.run_command( 'haxe_generate_field', {'name': fname, 'field': ftype, 'text': ftext, 'move': True})
def get_text(self): view = self.window.active_view() name = self.name mod, idx = self.get_mods( name, False, True, self.context.type.group == 'abstract', self.static) types = None if SCOPE_PARAMETERS in self.context.scope and \ self.caret_name: param_type = self.get_param_type() tp = param_type[0].split(':')[1] types = [r.strip() for r in tp.split('->')] if 'var' in self.field: text = '%svar %s:%s$0;' text = format_statement(view, text) ret = 'Dynamic' if types: ret = '$HX_W_AR->${HX_AR_W}'.join(types) text = text % ( mod, '${%d:%s}' % (idx, name), '${%d:%s}' % (idx + 1, ret)) else: text = '%sfunction %s(%s):%s$HX_W_OCB{\n\t$0\n}' text = format_statement(view, text) params = '' ret = 'Void' ret_idx = idx + 2 param_idx = 1 if types: ret = types.pop() for tp in types: if params: params += '$HX_W_CM,${HX_CM_W}' params += '${%d:p%d}$HX_W_C:${HX_C_W}%s' % ( ret_idx, param_idx, tp) ret_idx += 1 param_idx += 1 text = text % ( mod, '${%d:%s}' % (idx, name), '${%d:%s}' % (idx + 1, params), '${%d:%s}' % (ret_idx, ret)) return text
def get_text(self): view = self.window.active_view() name = self.name mod, idx = self.get_mods(name, False, True, self.context.type.group == "abstract", self.static) types = None ret = None if SCOPE_PARAMETERS in self.context.scope and self.caret_name: param_type = self.get_param_type() if param_type: tp = param_type[0].split(":")[1].strip() types, ret = parse_sig(tp) if types is not None: types = [shorten_imported_type(tp, self.context.imports) for tp in types] if ret is not None: ret = shorten_imported_type(ret, self.context.imports) if "var" in self.field: text = "%svar %s:%s$0;" text = format_statement(view, text) if ret is None: ret = "Dynamic" if types is not None: if not types: types.append("Void") types.append(ret) ret = "$HX_W_AR->${HX_AR_W}".join(types) text = text % (mod, "${%d:%s}" % (idx, name), "${%d:%s}" % (idx + 1, ret)) else: text = "%sfunction %s(%s):%s$HX_W_OCB{\n\t$0\n}" text = format_statement(view, text) params = "" if ret is None: ret = "Void" ret_idx = idx + 2 param_idx = 1 if types: for tp in types: if params: params += "$HX_W_CM,${HX_CM_W}" params += "${%d:p%d}$HX_W_C:${HX_C_W}%s" % (ret_idx, param_idx, tp) ret_idx += 1 param_idx += 1 text = text % (mod, "${%d:%s}" % (idx, name), "${%d:%s}" % (idx + 1, params), "${%d:%s}" % (ret_idx, ret)) return text
def on_select(self, index): if index == -1: return view = self.window.active_view() txt = None if self.tp is not None: is_static = index != 0 self.tp = format_statement(view, self.tp) txt = get_editable_mods( view, 1, self.name[0] == '_', 0, 1, 0, is_static, 0, 1) + \ 'var %s$HX_W_C:${HX_C_W}%s;$0' % (self.name, self.tp) self.window.run_command('haxe_promote_var_edit', { 'pos0': self.pos0, 'pos1': self.pos1, 'text': self.name + self.post }) self.window.run_command( 'haxe_generate_field', { 'name': self.name, 'field': FIELD_VAR if index == 0 else FIELD_STATIC_VAR, 'text': txt, 'move': True })
def on_select(self, index): if index == -1: return view = self.window.active_view() txt = None if self.tp is not None: is_static = index != 0 self.tp = format_statement(view, self.tp) txt = get_editable_mods( view, 1, self.name[0] == '_', 0, 1, 0, is_static, 0, 1) + \ 'var %s$HX_W_C:${HX_C_W}%s;$0' % (self.name, self.tp) self.window.run_command('haxe_promote_var_edit', { 'pos0': self.pos0, 'pos1': self.pos1, 'text': self.name + self.post }) self.window.run_command('haxe_generate_field', { 'name': self.name, 'field': FIELD_VAR if index == 0 else FIELD_STATIC_VAR, 'text': txt, 'move': True })
def get_text(self): view = self.window.active_view() name = self.name mod, idx = self.get_mod( name, False, True, self.context['type']['group'] == 'abstract', self.static) types = None if 'meta.parameters.haxe.2' in self.context['scope'] and \ self.caret_name: param_type = self.get_param_type() tp = param_type[0].split(':')[1] types = [r.strip() for r in tp.split('->')] if 'var' in self.field: text = '%svar %s:%s$0;' text = format_statement(view, text) ret = 'Dynamic' if types: ret = '$HX_W_AR->${HX_AR_W}'.join(types) text = text % (mod, name, '${%d:%s}' % (idx, ret)) else: text = '%sfunction %s(%s):%s$HX_W_OCB{\n\t$0\n}' text = format_statement(view, text) params = '' ret = 'Void' ret_idx = idx + 1 param_idx = 1 if types: ret = types.pop() for tp in types: if params: params += '$HX_W_CM,${HX_CM_W}' params += '${%d:p%d}$HX_W_C:${HX_C_W}%s' % ( ret_idx, param_idx, tp) ret_idx += 1 param_idx += 1 text = text % ( mod, name, '${%d:%s}' % (idx, params), '${%d:%s}' % (ret_idx, ret)) return text
def show_popup(self, hints): view = self.view text = '' for h in hints: if not text: text = '{}%s{}' % h else: text += ',%s' % h text = format_statement(view, text) text = text.format('<b>', '</b>') view.run_command('haxe_show_popup', {'text': text})
def insert_snippet(self, hints): view = self.view snippet = '' i = 1 for h in hints: var = '%d:%s' % (i, h) if snippet == '': snippet = var else: snippet += ',${%s}' % var i += 1 snippet = format_statement(view, snippet) view.run_command('insert_snippet', {'contents': '${' + snippet + '}'})
def show_popup(self, hints): view = self.view text = '' for h in hints: if not text: text = '{}%s{}' % h else: text += ',%s' % h text = format_statement(view, text) text = text.format('<b>', '</b>') view.run_command('haxe_show_popup', { 'text': text })
def insert_snippet(self, hints): view = self.view snippet = '' i = 1 for h in hints: var = '%d:%s' % (i, h) if snippet == '': snippet = var else: snippet += ',${%s}' % var i += 1 snippet = format_statement(view, snippet) view.run_command('insert_snippet', { 'contents': '${' + snippet + '}' })
def run(self, edit): view = self.view if view.score_selector(0, 'source.haxe.2') == 0 or \ int(sublime.version()) < 3000: return # get word under cursor word = view.word(view.sel()[0]) # get utf-8 byte offset to the end of the word src = view.substr(sublime.Region(0, word.b)) offset = len(codecs.encode(src, "utf-8")) + 1 # add 1 because offset is 1-based complete = HaxeComplete_inst() # save file and run completion temp = complete.save_temp_file(view) hint = complete.run_haxe( view, dict(mode="type", filename=view.file_name(), offset=offset, commas=None)) complete.clear_temp_file(view, temp) if hint is None: status = "No type information for '%s'." % \ view.substr(sublime.Region(word.a, word.b)) view.set_status("haxe-status", status) else: hint = format_statement(view, hint) view.set_status("haxe-status", hint) hint = hint.replace('<', '<') hint = hint.replace('>', '>') hint = re_params.sub(r'<b>\1</b>\2:', hint) if int(sublime.version()) >= 3070 and \ view.settings().get("haxe_use_popup", True): view.run_command('haxe_show_popup', {'text': hint}) else: view.show_popup_menu([hint], lambda i: None)
def run(self, edit): view = self.view if view.score_selector(0, 'source.haxe.2') == 0 or \ int(sublime.version()) < 3000: return # get word under cursor word = view.word(view.sel()[0]) # get utf-8 byte offset to the end of the word src = view.substr(sublime.Region(0, word.b)) offset = len(codecs.encode(src, "utf-8")) + 1 # add 1 because offset is 1-based complete = HaxeComplete_inst() # save file and run completion temp = complete.save_temp_file(view) hint = complete.run_haxe(view, dict( mode="type", filename=view.file_name(), offset=offset, commas=None )) complete.clear_temp_file(view, temp) if hint is None: status = "No type information for '%s'." % \ view.substr(sublime.Region(word.a, word.b)) view.set_status("haxe-status", status) else: hint = format_statement(view, hint) if int(sublime.version()) >= 3070 and \ view.settings().get("haxe_use_popup", True): view.run_command('haxe_show_popup', {'text': hint}) else: view.show_popup_menu([hint], lambda i: None) view.set_status("haxe-status", hint)