コード例 #1
0
    def run(self):
        win = self.window
        view = win.active_view()

        if view is None or view.is_loading() or not is_haxe_scope(view):
            return

        self.context = get_context(view)

        if not self.context.type:
            return

        method_names = {'new': True}
        for methodCtx in self.context.type.methods:
            method_names[methodCtx.name] = True
        tmp_name = '__sublime_tmp_method__'
        method_names[tmp_name] = True

        win.run_command(
            'haxe_override_method_edit',
            {'pos': self.context.type.block.begin(), 'name': tmp_name})

        complete = HaxeComplete_inst()
        temp = complete.save_temp_file(view)
        _, _, _, _, fields = complete.run_haxe(view, dict(
            mode=None,
            filename=view.file_name(),
            offset=0,
            commas=None))
        complete.clear_temp_file(view, temp)

        win.run_command('undo')

        self.methods = []
        for field in fields:
            name = field[0]
            args = field[1]
            if args is None or name in method_names:
                continue
            self.methods.append(field)

        options = []
        for method in self.methods:
            options.append('%s()' % method[0])

        show_quick_panel(
            win, options, self.on_select, sublime.MONOSPACE_FONT, 0)
コード例 #2
0
    def run(self):
        win = self.window
        view = win.active_view()

        if view is None or view.is_loading() or not is_haxe_scope(view):
            return

        self.context = get_context(view)

        if not self.context.type:
            return

        method_names = {'new': True}
        for methodCtx in self.context.type.methods:
            method_names[methodCtx.name] = True
        tmp_name = '__sublime_tmp_method__'
        method_names[tmp_name] = True

        win.run_command('haxe_override_method_edit', {
            'pos': self.context.type.block.begin(),
            'name': tmp_name
        })

        complete = HaxeComplete_inst()
        temp = complete.save_temp_file(view)
        _, _, _, _, fields = complete.run_haxe(
            view,
            dict(mode=None, filename=view.file_name(), offset=0, commas=None))
        complete.clear_temp_file(view, temp)

        win.run_command('undo')

        self.methods = []
        for field in fields:
            name = field[0]
            args = field[1]
            if args is None or name in method_names:
                continue
            self.methods.append(field)

        options = []
        for method in self.methods:
            options.append('%s()' % method[0])

        show_quick_panel(win, options, self.on_select, sublime.MONOSPACE_FONT,
                         0)
コード例 #3
0
    def run( self , edit ) :

        view = self.view

        # 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 )
        pos = complete.run_haxe(view, dict(
            mode="position",
            filename=view.file_name(),
            offset=offset,
            commas=None
        ))
        complete.clear_temp_file( view , temp )

        if pos is None:
            status = "Definition of '" + view.substr(sublime.Region(word.a, word.b)) + "' not found."
            self.view.set_status( "haxe-status", status )
            return
        else :
            pos = pos.strip()

        # parse position
        m = posRe.match(pos)
        filename = m.group(1)
        line = int(m.group(2)) - 1
        mode = m.group(3)
        start = int(m.group(4))
        if mode == "lines":
            start = 0

        if os.name == "nt":
            filename = self.get_windows_path(filename)

        # open definition file in the active window and go to given position
        window = sublime.active_window()
        view = window.open_file(filename)
        self.goto_pos(view, line, start)
コード例 #4
0
    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('<', '&lt;')
            hint = hint.replace('>', '&gt;')
            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)
コード例 #5
0
def get_type(view, pos, name):
    win = view.window()

    win.run_command('haxe_promote_var_edit', {
        'pos0': pos,
        'pos1': pos,
        'text': '%s.|' % name
    })

    complete = HaxeComplete_inst()
    temp = complete.save_temp_file(view)
    tp = complete.run_haxe(
        view,
        dict(mode="type", filename=view.file_name(), offset=0, commas=None))
    complete.clear_temp_file(view, temp)

    win.run_command('undo')

    return tp
コード例 #6
0
def get_type(view, pos, name):
    win = view.window()

    win.run_command(
        'haxe_promote_var_edit',
        {'pos0': pos, 'pos1': pos, 'text': '%s.|' % name})

    complete = HaxeComplete_inst()
    temp = complete.save_temp_file(view)
    tp = complete.run_haxe(view, dict(
        mode="type",
        filename=view.file_name(),
        offset=0,
        commas=None
    ))
    complete.clear_temp_file(view, temp)

    win.run_command('undo')

    return tp
コード例 #7
0
    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)
コード例 #8
0
    def find_local_or_field_usages(self):
        self.show_panel()
        self.log('Find usages: %s' % self.word.name)

        # print('HU local_or_field')
        ctx = self.context

        is_param = ctx.method and \
            ctx.method.region.begin() < ctx.word.region.begin() and \
            self.word.region.end() <= ctx.method.block.begin() and \
            '(' in ctx.src[ctx.method.region.begin():ctx.word.region.begin()]

        complete = HaxeComplete_inst()
        temp = complete.save_temp_file(self.view, is_param)

        filepath = None
        usage_line = 0

        src = self.view.substr(
            sublime.Region(0, ctx.word.region.end()))
        offset = len(codecs.encode(src, 'utf-8')) + 1

        mos = [mo for mo in re.finditer(
            r'\b(for\s*\(\s*|var\s+|function\s+)%s\b' % ctx.word.name,
            src, re.M)]
        mo = mos[-1] if mos else None
        is_declaration = mo and mo.end(0) == ctx.word.region.end()
        is_field = False
        view_filepath = os.path.realpath(self.view.file_name())

        if is_declaration or is_param:
            filepath = os.path.realpath(self.view.file_name())
            usage_line, _ = self.view.rowcol(ctx.word.region.end())
            usage_line += 1
            self.append_usage(filepath, usage_line)

            if is_declaration:
                is_field = not ctx.method or \
                    ctx.word.region.end() <= ctx.method.block.begin()
        else:
            position = complete.run_haxe(self.view, dict(
                mode='position',
                filename=self.view.file_name(),
                offset=offset,
                commas=None
            ))

            if position:
                filepath, usage_line, begin, end = \
                    self.parse_and_append_usage(position)
                begin = self.view.text_point(usage_line, begin)
                end = self.view.text_point(usage_line, end)
                is_field = view_filepath != filepath or \
                    not ctx.method or \
                    end <= ctx.method.block.begin() or \
                    begin >= ctx.method.block.end()
            else:
                self.has_pos_errors = True

        if filepath:
            if filepath != view_filepath:
                self.find_field_usages(filepath, usage_line)
            else:
                if is_param:
                    self.find_param_usages(filepath)
                elif not is_field:
                    # print('HU local usages')
                    self.hx_files = [filepath]

                    if is_declaration:
                        self.find_local_usages(filepath, usage_line)
                    else:
                        self.find_usages(offset)
                else:
                    self.find_field_usages(filepath, usage_line)
        else:
            self.finish()

        complete.clear_temp_file(self.view, temp)
コード例 #9
0
    def find_local_or_field_usages(self):
        self.show_panel()
        self.log('Find usages: %s' % self.word.name)

        # print('HU local_or_field')
        ctx = self.context

        is_param = ctx.method and \
            ctx.method.region.begin() < ctx.word.region.begin() and \
            self.word.region.end() <= ctx.method.block.begin() and \
            '(' in ctx.src[ctx.method.region.begin():ctx.word.region.begin()]

        complete = HaxeComplete_inst()
        temp = complete.save_temp_file(self.view, is_param)

        filepath = None
        usage_line = 0

        src = self.view.substr(sublime.Region(0, ctx.word.region.end()))
        offset = len(codecs.encode(src, 'utf-8')) + 1

        mos = [
            mo for mo in re.finditer(
                r'\b(for\s*\(\s*|var\s+|function\s+)%s\b' %
                ctx.word.name, src, re.M)
        ]
        mo = mos[-1] if mos else None
        is_declaration = mo and mo.end(0) == ctx.word.region.end()
        is_field = False
        view_filepath = os.path.realpath(self.view.file_name())

        if is_declaration or is_param:
            filepath = os.path.realpath(self.view.file_name())
            usage_line, _ = self.view.rowcol(ctx.word.region.end())
            usage_line += 1
            self.append_usage(filepath, usage_line)

            if is_declaration:
                is_field = not ctx.method or \
                    ctx.word.region.end() <= ctx.method.block.begin()
        else:
            position = complete.run_haxe(
                self.view,
                dict(mode='position',
                     filename=self.view.file_name(),
                     offset=offset,
                     commas=None))

            if position:
                filepath, usage_line, begin, end = \
                    self.parse_and_append_usage(position)
                begin = self.view.text_point(usage_line, begin)
                end = self.view.text_point(usage_line, end)
                is_field = view_filepath != filepath or \
                    not ctx.method or \
                    end <= ctx.method.block.begin() or \
                    begin >= ctx.method.block.end()
            else:
                self.has_pos_errors = True

        if filepath:
            if filepath != view_filepath:
                self.find_field_usages(filepath, usage_line)
            else:
                if is_param:
                    self.find_param_usages(filepath)
                elif not is_field:
                    # print('HU local usages')
                    self.hx_files = [filepath]

                    if is_declaration:
                        self.find_local_usages(filepath, usage_line)
                    else:
                        self.find_usages(offset)
                else:
                    self.find_field_usages(filepath, usage_line)
        else:
            self.finish()

        complete.clear_temp_file(self.view, temp)