def jump_to_imports(self): view = gs.active_valid_go_view() if not view: return last_import = gs.attr('last_import_path.%s' % gs.view_fn(view), '') r = None if last_import: offset = len(last_import) + 2 last_import = re.escape(last_import) pat = '(?s)import.*?(?:"%s"|`%s`)' % (last_import, last_import) r = view.find(pat, 0) if not r: offset = 1 pat = '(?s)import.*?["`]' r = view.find(pat, 0) if not r: gs.notice(DOMAIN, "cannot find import declarations") return pt = r.end() - offset row, col = view.rowcol(pt) loc = Loc(view.file_name(), row, col) self.jump_to((view, loc))
def cmd_9(view, edit, args, wd, rkey): if len(args) == 0 or args[0] not in ('run', 'replay', 'build'): push_output(view, rkey, ('9: invalid args %s' % args)) return subcmd = args[0] cid = '' if subcmd == 'replay': cid = '9replay-%s' % wd cid, cb = _9_begin_call(subcmd, view, edit, args, wd, rkey, cid) a = { 'cid': cid, 'env': gs.env(), 'dir': wd, 'args': args[1:], 'build_only': (subcmd == 'build'), } win = view.window() if win is not None: av = win.active_view() if av is not None: fn = av.file_name() if fn: _save_all(win, wd) else: if gs.is_go_source_view(av, False): a['fn'] = gs.view_fn(av) a['src'] = av.substr(sublime.Region(0, av.size())) sublime.set_timeout(lambda: mg9.acall('play', a, cb), 0)
def cmd_9(view, edit, args, wd, rkey): if len(args) == 0 or args[0] not in ("run", "replay", "build"): push_output(view, rkey, ("9: invalid args %s" % args)) return subcmd = args[0] cid = "" if subcmd == "replay": cid = "9replay-%s" % wd cid, cb = _9_begin_call(subcmd, view, edit, args, wd, rkey, cid) a = {"cid": cid, "env": sh.env(), "dir": wd, "args": args[1:], "build_only": (subcmd == "build")} win = view.window() if win is not None: av = win.active_view() if av is not None: fn = av.file_name() if fn: _save_all(win, wd) else: if gs.is_go_source_view(av, False): a["fn"] = gs.view_fn(av) a["src"] = av.substr(sublime.Region(0, av.size())) sublime.set_timeout(lambda: mg9.acall("play", a, cb), 0)
def cmd_9(view, edit, args, wd, rkey): if len(args) == 0 or args[0] not in ('run', 'replay', 'build'): push_output(view, rkey, ('9: invalid args %s' % args)) return subcmd = args[0] cid = '' if subcmd == 'replay': cid = '9replay-%s' % wd cid, cb = _9_begin_call(subcmd, view, edit, args, wd, rkey, cid) a = { 'cid': cid, 'env': sh.env(), 'dir': wd, 'args': args[1:], 'build_only': (subcmd == 'build'), } win = view.window() if win is not None: av = win.active_view() if av is not None: fn = av.file_name() if fn: _save_all(win, wd) else: if gs.is_go_source_view(av, False): a['fn'] = gs.view_fn(av) a['src'] = av.substr(sublime.Region(0, av.size())) sublime.set_timeout(lambda: mg9.acall('play', a, cb), 0)
def run(self): def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get("file_decls", []) decls.extend(res.get("pkg_decls", [])) for d in decls: name = d["name"] prefix, _ = match_prefix_name(name) kind = d["kind"].lstrip("+- ") if prefix and kind == "func" and d["repr"] == "": mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ["Run all tests and examples"] for k in ["Test", "Benchmark", "Example"]: if mats.get(k): s = "Run %ss Only" % k ents.append(s) if k == "Benchmark": args[s] = ["-test.run=none", '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith("Benchmark"): args[k] = ["-test.run=none", '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command( "gs9o_open", {"run": gs.lst("go", "test", a)} ) gs.show_quick_panel(ents, cb) win, view = gs.win_view(None, self.window) if view is None: return vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = "" if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) mg9.declarations(vfn, src, pkg_dir, f)
def run(self): def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) kind = d['kind'].lstrip('+-~ ') if prefix and kind == 'func' and d['repr'] == '': mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command('gs9o_open', {'run': gs.lst('go', 'test', a)}) gs.show_quick_panel(ents, cb) win, view = gs.win_view(None, self.window) if view is None: return vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) mg9.declarations(vfn, src, pkg_dir, f)
def run(self): def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command('gs9o_open', {'run': gs.lst('go', 'test', a)}) gs.show_quick_panel(ents, cb) win, view = gs.win_view(None, self.window) if view is None: return vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) mg9.declarations(vfn, src, pkg_dir, f)
def present_current(self): pkg_dir = '' view = gs.active_valid_go_view(win=self.window, strict=False) if view: if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) vfn = gs.view_fn(view) src = gs.view_src(view) else: vfn = '' src = '' self.present(vfn, src, pkg_dir)
def run(self, edit, pos, content, added_path=''): pos = int(pos) # un-f*****g-believable view = self.view dirty, err = gspatch.merge(view, pos, content, edit) if err: gs.notice_undo(DOMAIN, err, view, dirty) elif dirty: k = 'last_import_path.%s' % gs.view_fn(self.view) if added_path: gs.set_attr(k, added_path) else: gs.del_attr(k)
def run(self, edit, row, col=0): pt = self.view.text_point(row, col) r = sublime.Region(pt, pt) self.view.sel().clear() self.view.sel().add(r) self.view.show(pt) dmn = 'gs.focus.%s:%s:%s' % (gs.view_fn(self.view), row, col) flags = sublime.DRAW_EMPTY_AS_OVERWRITE show = lambda: self.view.add_regions(dmn, [r], 'comment', 'bookmark', flags) hide = lambda: self.view.erase_regions(dmn) for i in range(3): m = 300 s = i * m * 2 h = s + m sublime.set_timeout(show, s) sublime.set_timeout(hide, h)
def palette_declarations(self, view, direct=False): def f(res, err): if err: gs.notify("GsDeclarations", err) else: decls = res.get("file_decls", []) decls.sort(key=lambda v: v.get("row", 0)) added = 0 for i, v in enumerate(decls): loc = Loc(v["fn"], v["row"], v["col"]) s = "%s %s" % (v["kind"], (v["repr"] or v["name"])) self.add_item(s, self.jump_to, (view, loc)) added += 1 if added < 1: self.add_item(["", "No declarations found"]) self.do_show_panel() mg9.declarations(gs.view_fn(view), gs.view_src(view), "", f)
def palette_declarations(self, view, direct=False): def f(res, err): if err: gs.notify('GsDeclarations', err) else: decls = res.get('file_decls', []) decls.sort(key=lambda v: v.get('row', 0)) added = 0 for i, v in enumerate(decls): loc = Loc(v['fn'], v['row'], v['col']) s = '%s %s' % (v['kind'], (v['repr'] or v['name'])) self.add_item(s, self.jump_to, (view, loc)) added += 1 if added < 1: self.add_item(['', 'No declarations found']) self.do_show_panel() mg9.declarations(gs.view_fn(view), gs.view_src(view), '', f)
def run(self, debug=False): global w_builders g_builder = None wid = self.window.id() if w_builders.has_key(wid): g_builder = w_builders[wid] if (g_builder is not None) and (g_builder.is_running()): g_builder.showLView() return def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[True] = prefix args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run=^%s$' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) sargs = "" if len(a) > 0: sargs = a[0] # print sargs if debug: win.run_command('gdb_launch', { 'test': True, 'trun': sargs }) else: global g_builder g_builder = GoBuilder() g_builder.initEnv(True, sargs, self.window.active_view(), n_console_view) g_builder.run() gs.show_quick_panel(ents, cb) win, view = gs.win_view(None, self.window) if view is None: return vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) mg9.declarations(vfn, src, pkg_dir, f)
def run(self,debug=False): global w_builders g_builder=None wid=self.window.id() if w_builders.has_key(wid): g_builder=w_builders[wid] if (g_builder is not None) and (g_builder.is_running()): g_builder.showLView() return def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[True] = prefix args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run=^%s$' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) sargs="" if len(a)>0: sargs=a[0] # print sargs if debug: win.run_command('gdb_launch', {'test':True,'trun':sargs}) else: global g_builder g_builder=GoBuilder() g_builder.initEnv(True,sargs,self.window.active_view(),n_console_view) g_builder.run() gs.show_quick_panel(ents, cb) win, view = gs.win_view(None, self.window) if view is None: return vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) mg9.declarations(vfn, src, pkg_dir, f)