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[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], []) 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): 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], []) 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): win, view = gs.win_view(None, self.window) if view is None: return mats = {} args = {} vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) res, err = margo.declarations(vfn, src, pkg_dir) if err: gs.notice(DOMAIN, err) return 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): if i >= 0: s = 'go test %s' % args.get(ents[i], '') win.run_command('gs_shell', {'run': s}) win.show_quick_panel(ents, cb)
def run(self): win, view = gs.win_view(None, self.window) if view is None: return mats = {} args = {} vfn = gs.view_fn(view) src = gs.view_src(view) pkg_dir = '' if view.file_name(): pkg_dir = os.path.dirname(view.file_name()) res, err = margo.declarations(vfn, src, pkg_dir) if err: gs.notice(DOMAIN, err) return decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] m = TEST_PAT.match(name) if m and d['kind'] == 'func' and d['repr'] == '': mats[m.group(1)] = 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): if i >= 0: s = 'go test %s' % args.get(ents[i], '') win.run_command('gs_shell', {'run': s}) win.show_quick_panel(ents, cb)
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 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 cb(s): file_name = self.view.file_name() or '' s = GO_PLAY_PAT.sub(r'\1go run\2', s) s = s.strip() if s and s.lower() != "go" and self.change_history: hist = self.settings.get('cmd_hist') if not gs.is_a(hist, {}): hist = {} basedir = gs.basedir_or_cwd(file_name) hist[basedir] = [s] # todo: store a list of historical commands hst = {} for k in hist: # :| hst[gs.ustr(k)] = gs.ustr(hist[k]) self.settings.set('cmd_hist', hst) sublime.save_settings('GoSublime-GsShell.sublime-settings') if GO_SHARE_PAT.match(s): s = '' host = "play.golang.org" warning = 'Are you sure you want to share this file. It will be public on %s' % host if not sublime.ok_cancel_dialog(warning): return try: c = httplib.HTTPConnection(host) src = gs.astr(self.view.substr(sublime.Region(0, self.view.size()))) c.request('POST', '/share', src, {'User-Agent': 'GoSublime'}) s = 'http://%s/p/%s' % (host, c.getresponse().read()) except Exception as ex: s = 'Error: %s' % ex self.show_output(s, focus=True) return if GO_RUN_PAT.match(s): if not file_name: # todo: clean this up after the command runs err = '' tdir, _ = gs.temp_dir('play') file_name = hashlib.sha1(gs.view_fn(self.view) or 'a').hexdigest() file_name = os.path.join(tdir, ('%s.go' % file_name)) try: with open(file_name, 'w') as f: src = gs.astr(self.view.substr(sublime.Region(0, self.view.size()))) f.write(src) except Exception as ex: err = str(ex) if err: self.show_output('Error: %s' % err) return s = ['go', 'run', file_name] self.view.window().run_command("exec", { 'kill': True }) if gs.is_a(s, []): use_shell = False else: use_shell = True s = [s] gs.println('running %s' % ' '.join(s)) self.view.window().run_command("exec", { 'shell': use_shell, 'env': gs.env(), 'cmd': s, 'file_regex': '^(.+\.go):([0-9]+):(?:([0-9]+):)?\s*(.*)', })
def cb(s): file_name = self.view.file_name() or '' s = GO_PLAY_PAT.sub(r'\1go run\2', s) s = s.strip() if s and s.lower() != "go" and self.change_history: hist = self.settings.get('cmd_hist') if not gs.is_a(hist, {}): hist = {} basedir = gs.basedir_or_cwd(file_name) hist[basedir] = [s ] # todo: store a list of historical commands hst = {} for k in hist: # :| hst[gs.ustr(k)] = gs.ustr(hist[k]) self.settings.set('cmd_hist', hst) sublime.save_settings('GoSublime-GsShell.sublime-settings') if GO_SHARE_PAT.match(s): s = '' host = "play.golang.org" warning = 'Are you sure you want to share this file. It will be public on %s' % host if not sublime.ok_cancel_dialog(warning): return try: c = httplib.HTTPConnection(host) src = gs.astr( self.view.substr(sublime.Region(0, self.view.size()))) c.request('POST', '/share', src, {'User-Agent': 'GoSublime'}) s = 'http://%s/p/%s' % (host, c.getresponse().read()) except Exception as ex: s = 'Error: %s' % ex self.show_output(s, focus=True) return if GO_RUN_PAT.match(s): if not file_name: # todo: clean this up after the command runs err = '' tdir, _ = gs.temp_dir('play') file_name = hashlib.sha1(gs.view_fn(self.view) or 'a').hexdigest() file_name = os.path.join(tdir, ('%s.go' % file_name)) try: with open(file_name, 'w') as f: src = gs.astr( self.view.substr( sublime.Region(0, self.view.size()))) f.write(src) except Exception as ex: err = str(ex) if err: self.show_output('Error: %s' % err) return s = ['go', 'run', file_name] self.view.window().run_command("exec", {'kill': True}) if gs.is_a(s, []): use_shell = False else: use_shell = True s = [s] gs.println('running %s' % ' '.join(s)) self.view.window().run_command( "exec", { 'shell': use_shell, 'env': gs.env(), 'cmd': s, 'file_regex': '^(.+\.go):([0-9]+):(?:([0-9]+):)?\s*(.*)', })
def cb(s): file_name = self.view.file_name() or "" s = GO_PLAY_PAT.sub(r"\1go run\2", s) s = s.strip() if s and s.lower() != "go" and self.change_history: hist = self.settings.get("cmd_hist") if not gs.is_a(hist, {}): hist = {} basedir = gs.basedir_or_cwd(file_name) hist[basedir] = [s] # todo: store a list of historical commands hst = {} for k in hist: # :| hst[gs.ustr(k)] = gs.ustr(hist[k]) self.settings.set("cmd_hist", hst) sublime.save_settings("GoSublime-GsShell.sublime-settings") if GO_SHARE_PAT.match(s): s = "" host = "play.golang.org" warning = "Are you sure you want to share this file. It will be public on %s" % host if not sublime.ok_cancel_dialog(warning): return try: c = httplib.HTTPConnection(host) src = gs.astr(self.view.substr(sublime.Region(0, self.view.size()))) c.request("POST", "/share", src, {"User-Agent": "GoSublime"}) s = "http://%s/p/%s" % (host, c.getresponse().read()) except Exception as ex: s = "Error: %s" % ex self.show_output(s, focus=True) return if GO_RUN_PAT.match(s): if not file_name: # todo: clean this up after the command runs err = "" tdir, _ = gs.temp_dir("play") file_name = hashlib.sha1(gs.view_fn(self.view) or "a").hexdigest() file_name = os.path.join(tdir, ("%s.go" % file_name)) try: with open(file_name, "w") as f: src = gs.astr(self.view.substr(sublime.Region(0, self.view.size()))) f.write(src) except Exception as ex: err = str(ex) if err: self.show_output("Error: %s" % err) return s = ["go", "run", file_name] self.view.window().run_command("exec", {"kill": True}) if gs.is_a(s, []): use_shell = False else: use_shell = True s = [s] gs.println("running %s" % " ".join(s)) self.view.window().run_command( "exec", { "shell": use_shell, "env": gs.env(), "cmd": s, "file_regex": "^(.+\.go):([0-9]+):(?:([0-9]+):)?\s*(.*)", }, )