コード例 #1
0
    def find_param_usages(self, filepath):
        # print('HU param usage')
        src = self.context.src
        src = src[:self.context.method.block.begin()] + \
            '%s' % self.context.word.name

        offset = len(codecs.encode(src, 'utf-8')) + 1

        src += ';' + self.context.src[self.context.method.block.begin():]
        complete = HaxeComplete_inst()

        with open(filepath, 'w') as f:
            f.write(src)

        usage = complete.run_haxe(self.view, dict(
            mode='usage',
            filename=filepath,
            offset=offset,
            commas=None
        ))

        if usage:
            tree = self.parse_xml(usage[0])

            if tree is not None:
                usages = [i.text for i in tree.getiterator('pos')]
                if usages:
                    usages.pop(0)
                for u in usages:
                    self.parse_and_append_usage(u)

        self.finish()
コード例 #2
0
    def find_param_usages(self, filepath):
        # print('HU param usage')
        src = self.context.src
        src = src[:self.context.method.block.begin()] + \
            '%s' % self.context.word.name

        offset = len(codecs.encode(src, 'utf-8')) + 1

        src += ';' + self.context.src[self.context.method.block.begin():]
        complete = HaxeComplete_inst()

        with open(filepath, 'w') as f:
            f.write(src)

        usage = complete.run_haxe(
            self.view,
            dict(mode='usage', filename=filepath, offset=offset, commas=None))

        if usage:
            tree = self.parse_xml(usage[0])

            if tree is not None:
                usages = [i.text for i in tree.getiterator('pos')]
                if usages:
                    usages.pop(0)
                for u in usages:
                    self.parse_and_append_usage(u)

        self.finish()
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
    def find_local_usages(self, filepath, usage_line):
        self.append_usage(self.view.file_name(), usage_line)

        rgn = self.word.region
        pos_cols = (
            self.view.rowcol(rgn.begin())[1],
            self.view.rowcol(rgn.end())[1])

        src = self.view.substr(sublime.Region(
            self.context.word.region.end(), self.context.method.region.end()))

        idx = 0
        idx = src.find(self.context.word.name, idx)
        complete = HaxeComplete_inst()

        while idx != -1:
            offset = self.context.word.region.end() + idx + \
                len(self.context.word.name)
            src_o = self.view.substr(sublime.Region(0, offset))
            offset = len(codecs.encode(src_o, 'utf-8')) + 1

            position = complete.run_haxe(self.view, dict(
                mode='position',
                filename=filepath,
                offset=offset,
                commas=None
            ))

            if position:
                mo = re_haxe_position.search(position)
                if mo:
                    line = int(mo.group(2))
                    cols = (int(mo.group(3)), int(mo.group(4)))

                    if line == usage_line and \
                            cols[0] <= pos_cols[0] and pos_cols[1] <= cols[1]:
                        self.find_usages(offset)
                        return
            else:
                self.has_pos_errors = True

            idx = src.find(self.context.word.name, idx + 1)

        self.finish()
コード例 #8
0
    def find_local_usages(self, filepath, usage_line):
        self.append_usage(self.view.file_name(), usage_line)

        rgn = self.word.region
        pos_cols = (self.view.rowcol(rgn.begin())[1],
                    self.view.rowcol(rgn.end())[1])

        src = self.view.substr(
            sublime.Region(self.context.word.region.end(),
                           self.context.method.region.end()))

        idx = 0
        idx = src.find(self.context.word.name, idx)
        complete = HaxeComplete_inst()

        while idx != -1:
            offset = self.context.word.region.end() + idx + \
                len(self.context.word.name)
            src_o = self.view.substr(sublime.Region(0, offset))
            offset = len(codecs.encode(src_o, 'utf-8')) + 1

            position = complete.run_haxe(
                self.view,
                dict(mode='position',
                     filename=filepath,
                     offset=offset,
                     commas=None))

            if position:
                mo = re_haxe_position.search(position)
                if mo:
                    line = int(mo.group(2))
                    cols = (int(mo.group(3)), int(mo.group(4)))

                    if line == usage_line and \
                            cols[0] <= pos_cols[0] and pos_cols[1] <= cols[1]:
                        self.find_usages(offset)
                        return
            else:
                self.has_pos_errors = True

            idx = src.find(self.context.word.name, idx + 1)

        self.finish()
コード例 #9
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
コード例 #10
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
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)