def show_pkgfiles(dirname): ents = [] m = {} try: dirname = os.path.abspath(dirname) for fn in gs.list_dir_tree(dirname, ext_filter, gs.setting('fn_exclude_prefixes', [])): name = os.path.relpath(fn, dirname).replace('\\', '/') m[name] = fn ents.append(name) except Exception as ex: gs.notice(DOMAIN, 'Error: %s' % ex) if ents: ents.sort(key = lambda a: a.lower()) try: s = " ../ ( current: %s )" % dirname m[s] = os.path.join(dirname, "..") ents.insert(0, s) except Exception: pass def cb(i, win): if i >= 0: fn = m[ents[i]] if os.path.isdir(fn): win.run_command("gs_browse_files", {"dir": fn}) else: gs.focus(fn, 0, 0, win) gs.show_quick_panel(ents, cb) else: gs.show_quick_panel([['', 'No files found']])
def f(res, err): if err: gs.notify(DOMAIN, err) return decls = res.get('file_decls', []) for d in res.get('pkg_decls', []): if not vfn or d['fn'] != vfn: decls.append(d) for d in decls: dname = (d['repr'] or d['name']) trailer = [] trailer.extend(GOOS_PAT.findall(d['fn'])) trailer.extend(GOARCH_PAT.findall(d['fn'])) if trailer: trailer = ' (%s)' % ', '.join(trailer) else: trailer = '' d['ent'] = '%s %s%s' % (d['kind'], dname, trailer) ents = [] decls.sort(key=lambda d: d['ent']) for d in decls: ents.append(d['ent']) def cb(i, win): if i >= 0: d = decls[i] gs.focus(d['fn'], d['row'], d['col'], win) if ents: gs.show_quick_panel(ents, cb) else: gs.show_quick_panel([['', 'No declarations found']])
def cb(): settings_fn = 'GoSublime-GsDepends.sublime-settings' settings = sublime.load_settings(settings_fn) new_rev = changes[-1][0] old_rev = settings.get('tracking_rev', '') def on_panel_close(i, win): if i > 0: settings.set('tracking_rev', new_rev) sublime.save_settings(settings_fn) win.open_file(changelog_fn) if i == 1: run_go_get() if new_rev > old_rev: items = [ [ " ", "GoSublime updated to %s" % new_rev, " ", ], [ "Install/Update dependencies: Gocode, MarGo", "go get -u %s" % GOCODE_REPO, "go get -u %s" % MARGO_REPO, ], [ "View changelog", "Packages/GoSublime/CHANGELOG.md" " ", ] ] gs.show_quick_panel(items, on_panel_close)
def f(res, err): if err: gs.notice(DOMAIN, err) return ents, m = handle_pkgdirs_res(res) if ents: def cb(i, win): if i >= 0: dirname = gs.basedir_or_cwd(m[ents[i]]) win.run_command('gs_browse_files', {'dir': dirname}) gs.show_quick_panel(ents, cb) else: gs.show_quick_panel([['', 'No source directories found']])
def do_show_panel(self): # todo cleanup this file and get rid of the old gspalette items = [] actions = {} for tup in self.items: item, action, args = tup actions[len(items)] = (action, args) items.append(item) self.items = [] def on_done(i, win): action, args = actions.get(i, (None, None)) if i >= 0 and action: action(args) gs.show_quick_panel(items, on_done)
def f(res, err): if err: gs.notice(DOMAIN, err) return ents, m = handle_pkgdirs_res(res) if ents: ents.insert(0, "Current Package") def cb(i, win): if i == 0: self.present_current() elif i >= 1: self.present('', '', os.path.dirname(m[ents[i]])) gs.show_quick_panel(ents, cb) else: gs.show_quick_panel([['', 'No source directories found']])
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)
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)
def check_depends(): gr = gs.go_env_goroot() if not gr: gs.notice(DOMAIN, 'The `go` command cannot be found') return e = gs.env() if not e.get('GOROOT'): os.environ['GOROOT'] = gr elif not e.get('GOPATH'): gs.notice(DOMAIN, "GOPATH and/or GOROOT appear to be unset") gs.println( 'GoSublime: checking dependencies', ('\tGOROOT is: %s' % e.get('GOROOT', gr)), ('\tGOPATH is: %s' % e.get('GOPATH', '')) ) missing = [] for cmd in ('gocode', 'MarGo'): if not call_cmd([cmd, '--help']): missing.append(cmd) if missing: def cb(i, _): if i == 0: run_go_get() items = [[ 'GoSublime depends on gocode and MarGo', 'Install %s (using `go get`)' % ', '.join(missing), 'gocode repo: %s' % GOCODE_REPO, 'MarGo repo: %s' % MARGO_REPO, ]] gs.show_quick_panel(items, cb) gs.println(DOMAIN, '\n'.join(items[0])) return changelog_fn = os.path.join(sublime.packages_path(), 'GoSublime', "CHANGELOG.md") try: with open(changelog_fn) as f: s = f.read() except IOError: gs.notice(DOMAIN, traceback.format_exc()) return changes = split_changes(s) if changes: def cb(): settings_fn = 'GoSublime-GsDepends.sublime-settings' settings = sublime.load_settings(settings_fn) new_rev = changes[-1][0] old_rev = settings.get('tracking_rev', '') def on_panel_close(i, win): if i > 0: settings.set('tracking_rev', new_rev) sublime.save_settings(settings_fn) win.open_file(changelog_fn) if i == 1: run_go_get() if new_rev > old_rev: items = [ [ " ", "GoSublime updated to %s" % new_rev, " ", ], [ "Install/Update dependencies: Gocode, MarGo", "go get -u %s" % GOCODE_REPO, "go get -u %s" % MARGO_REPO, ], [ "View changelog", "Packages/GoSublime/CHANGELOG.md" " ", ] ] gs.show_quick_panel(items, on_panel_close) sublime.set_timeout(cb, 0) else: margo.call( path='/', args='hello', message='hello MarGo' )