Exemplo n.º 1
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)
                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)
Exemplo n.º 2
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)
                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)
Exemplo n.º 3
0
	def present(self, vfn, src, pkg_dir):
		win = self.window
		if win is None:
			return

		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']])

		mg9.declarations(vfn, src, pkg_dir, f)
Exemplo n.º 4
0
	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)
Exemplo n.º 5
0
    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)