コード例 #1
0
ファイル: mg9.py プロジェクト: OlingCat/GoSublime
def _send():
	while True:
		try:
			try:
				method, arg, cb = gs.mg9_send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					killSrv()
					maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					proc, _, err = gsshell.proc([_margo_bin(), '-poll=30'], stderr=gs.LOGFILE ,env={
						'XDG_CONFIG_HOME': gs.home_path(),
					})
					gs.set_attr(PROC_ATTR_NAME, proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err)
						try:
							cb({}, 'Abort. Cannot start MarGo')
						except:
							pass
						continue

					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				req = Request(f=cb, method=method)
				gs.set_attr(REQUEST_PREFIX+req.token, req)

				gs.debug(DOMAIN, 'margo request: method: %s, token: %s' % (req.method, req.token))

				header, _ = gs.json_encode({'method': method, 'token': req.token})
				body, _ = gs.json_encode(arg)
				ln = '%s %s\n' % (header, body)

				if gs.PY3K:
					proc.stdin.write(bytes(ln, 'UTF-8'))
				else:
					proc.stdin.write(ln)
			except Exception:
				killSrv()
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
コード例 #2
0
ファイル: mg9.py プロジェクト: allanw1/Arianrhod
			pass

		try:
			p.stdin.close()
		except Exception:
			pass

def on(token, cb):
	req = Request(f=cb, token=token)
	gs.set_attr(REQUEST_PREFIX+req.token, req)

def _dump(res, err):
	gs.println(json.dumps({
		'res': res,
		'err': err,
	}, sort_keys=True, indent=2))

if not gs.checked(DOMAIN, 'launch ipc threads'):
	gsq.launch(DOMAIN, _send)
	gsq.launch(DOMAIN, _recv)

def on_mg_msg(res, err):
	msg = res.get('message', '')
	if msg:
		print('GoSublime: MarGo: %s' % msg)
		gs.notify('MarGo', msg)

	return True

on('margo.message', on_mg_msg)
コード例 #3
0
            pass


def on(token, cb):
    req = Request(f=cb, token=token)
    gs.set_attr(REQUEST_PREFIX + req.token, req)


def _dump(res, err):
    gs.println(json.dumps({
        'res': res,
        'err': err,
    }, sort_keys=True, indent=2))


if not gs.checked(DOMAIN, 'launch ipc threads'):
    gsq.launch(DOMAIN, _send)
    gsq.launch(DOMAIN, _recv)


def on_mg_msg(res, err):
    msg = res.get('message', '')
    if msg:
        print('GoSublime: MarGo: %s' % msg)
        gs.notify('MarGo', msg)

    return True


on('margo.message', on_mg_msg)
コード例 #4
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = gs.mg9_send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					killSrv()

					if gs.attr(_inst_name(), '') != "busy":
						maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					while gs.attr(_inst_name(), '') == "busy":
						time.sleep(0.100)

					mg_bin = _margo_bin()
					cmd = [
						mg_bin,
						'-oom', gs.setting('margo_oom', 0),
						'-poll', 30,
						'-tag', TAG,
					]

					if os.path.exists(mg_bin):
						proc, _, err = gsshell.proc(cmd, stderr=gs.LOGFILE ,env={
							'GOGC': 10,
							'XDG_CONFIG_HOME': gs.home_path(),
						})
					else:
						proc = None
						err = "Can't find the MarGo binary at `%s`" % mg_bin

					if err or not proc or proc.poll() is not None:
						killSrv()

						gs.notice(DOMAIN, 'Cannot start MarGo:\n%s' % err)
						try:
							cb({}, 'Abort. Cannot start MarGo')
						except:
							pass

						continue

					gs.set_attr(PROC_ATTR_NAME, proc)
					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				req = Request(f=cb, method=method)
				gs.set_attr(REQUEST_PREFIX+req.token, req)

				header, err = gs.json_encode(req.header())
				if err:
					_cb_err(cb, 'Failed to construct ipc header: %s' % err)
					continue

				body, err = gs.json_encode(arg)
				if err:
					_cb_err(cb, 'Failed to construct ipc body: %s' % err)
					continue

				ev.debug(DOMAIN, 'margo request: %s ' % header)

				ln = '%s %s\n' % (header, body)

				try:
					if gs.PY3K:
						proc.stdin.write(bytes(ln, 'UTF-8'))
					else:
						proc.stdin.write(ln)

				except Exception as ex:
					_cb_err(cb, 'Cannot talk to MarGo: %s' % err)
					killSrv()
					gs.println(gs.traceback())

			except Exception:
				killSrv()
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
コード例 #5
0
def acall(method, arg, cb):
	if not gs.checked(DOMAIN, 'launch _send'):
		gsq.launch(DOMAIN, _send)

	gs.mg9_send_q.put((method, arg, cb))
コード例 #6
0
ファイル: gscomplete.py プロジェクト: RazoRTR/Arianrhod
                        typ = c['type']
                        if typ.startswith(pfx):
                            s = 'func %s(%s' % (c['name'], typ[len(pfx):])
                        else:
                            s = '%s: %s' % (c['name'], typ)

                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
                    else:
                        s = '// %s' % (err or 'No calltips found')

                    gs.show_output(HINT_KEY,
                                   s,
                                   print_output=False,
                                   syntax_file='GsDoc')

            sublime.set_timeout(lambda: f2(cl, err), 0)

        fn = view.file_name()
        src = gs.view_src(view)
        pos = gs.sel(view).begin()
        mg9.calltip(fn, src, pos, set_status, f)


if not gs.checked(DOMAIN, '_ct_poller'):
    _ct_poller()
コード例 #7
0
ファイル: gscomplete.py プロジェクト: xiocode/config
		m = END_SELECTOR_PAT.match(s)
		if not m:
			return ({}, "can't match selector")

		offset = (line_start + m.end())
		sel = m.group(1)
		name = m.group(2)
		candidates = []
		src = view.substr(sublime.Region(0, view.size()))
		fn = view.file_name()
		candidates, err = mg9.complete(fn, src, offset)
		if err:
			gs.notice(DOMAIN, err)
		else:
			c = {}
			for i in candidates:
				if i['name'] == name:
					if c:
						c = None
						break
					c = i

			if c:
				return (c, '')

			return ({}, 'no candidates found')


if not gs.checked(DOMAIN, '_ct_poller'):
	_ct_poller()
コード例 #8
0
ファイル: gscomplete.py プロジェクト: charlievieth/GoSubl
                if set_status:
                    if c:
                        pfx = "func("
                        typ = c["type"]
                        if typ.startswith(pfx):
                            s = "func %s(%s" % (c["name"], typ[len(pfx) :])
                        else:
                            s = "%s: %s" % (c["name"], typ)

                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = "%s %s\n%s" % (c["name"], c["class"], c["type"])
                    else:
                        s = "// %s" % (err or "No calltips found")

                    gs.show_output(HINT_KEY, s, print_output=False, syntax_file="GsDoc")

            sublime.set_timeout(lambda: f2(cl, err), 0)

        fn = view.file_name()
        src = gs.view_src(view)
        pos = gs.sel(view).begin()
        mg9.calltip(fn, src, pos, set_status, f)


if not gs.checked(DOMAIN, "_ct_poller"):
    _ct_poller()
コード例 #9
0
ファイル: mg9.py プロジェクト: xiocode/config
def _send():
	while True:
		try:
			try:
				method, arg, cb = gs.mg9_send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					killSrv()

					if gs.attr(INSTALL_ATTR_NAME) != "busy":
						maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					while gs.attr(INSTALL_ATTR_NAME) == "busy":
						time.sleep(0.100)

					proc, _, err = gsshell.proc([_margo_bin(), '-poll', 30, '-tag', TAG], stderr=gs.LOGFILE ,env={
						'XDG_CONFIG_HOME': gs.home_path(),
					})
					gs.set_attr(PROC_ATTR_NAME, proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err)
						try:
							cb({}, 'Abort. Cannot start MarGo')
						except:
							pass
						continue

					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				req = Request(f=cb, method=method)
				gs.set_attr(REQUEST_PREFIX+req.token, req)

				header, err = gs.json_encode(req.header())
				if err:
					_cb_err('Failed to construct ipc header: ' % err)
					continue

				body, err = gs.json_encode(arg)
				if err:
					_cb_err(cb, 'Failed to construct ipc body: ' % err)
					continue

				gs.debug(DOMAIN, 'margo request: %s ' % header)

				ln = '%s %s\n' % (header, body)

				if gs.PY3K:
					proc.stdin.write(bytes(ln, 'UTF-8'))
				else:
					proc.stdin.write(ln)
			except Exception:
				killSrv()
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
コード例 #10
0
ファイル: gscomplete.py プロジェクト: OneOfOne/GoSublime-next
						pfx = 'func('
						typ = c['type']
						if typ.startswith(pfx):
							s = 'func %s(%s' % (c['name'], typ[len(pfx):])
						else:
							s = '%s: %s' % (c['name'], typ)

					func = intel.get('Func')
					if func:
						s = u'%s \u00B7 %s > %s' % (s, intel.get('Pkg'), func)

					if s:
						view.set_status(HINT_KEY, s)
					else:
						view.erase_status(HINT_KEY)
				else:
					if c:
						s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
					else:
						s = '// %s' % (err or 'No calltips found')

					gs.show_output(HINT_KEY, s, print_output=False, syntax_file='GsDoc')

			sublime.set_timeout(lambda: f2(cl, err), 0)

		mg9.calltip(fn, src, pos, set_status, f)


if not gs.checked(DOMAIN, '_ct'):
	ev.cursor_moved += _ct
コード例 #11
0
ファイル: mg9.py プロジェクト: charlievieth/GoSubl
            pass


def on(token, cb):
    req = Request(f=cb, token=token)
    gs.set_attr(REQUEST_PREFIX + req.token, req)


def _dump(res, err):
    gs.println(json.dumps({"res": res, "err": err}, sort_keys=True, indent=2))


# WARN: module level
#
# Start send and recieve threads.
if not gs.checked(DOMAIN, "launch ipc threads"):
    gsq.launch(DOMAIN, _send)
    gsq.launch(DOMAIN, _recv)


def on_mg_msg(res, err):
    msg = res.get("message", "")
    if msg:
        print("GoSublime: MarGo: %s" % msg)
        gs.notify("MarGo", msg)
    return True


# WARN: module level
on("margo.message", on_mg_msg)
コード例 #12
0
                            s = 'func %s(%s' % (c['name'], typ[len(pfx):])
                        else:
                            s = '%s: %s' % (c['name'], typ)

                    func = intel.get('Func')
                    if func:
                        s = u'%s \u00B7 %s > %s' % (s, intel.get('Pkg'), func)

                    if s:
                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
                    else:
                        s = '// %s' % (err or 'No calltips found')

                    gs.show_output(HINT_KEY,
                                   s,
                                   print_output=False,
                                   syntax_file='GsDoc')

            sublime.set_timeout(lambda: f2(cl, err), 0)

        mg9.calltip(fn, src, pos, set_status, f)


if not gs.checked(DOMAIN, '_ct'):
    ev.cursor_moved += _ct
コード例 #13
0
ファイル: mg9.py プロジェクト: hickford/GoSublime
def _send():
    while True:
        try:
            try:
                method, arg, cb = gs.mg9_send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    killSrv()

                    if gs.attr(_inst_name(), "") != "busy":
                        maybe_install()

                    if not gs.checked(DOMAIN, "launch _recv"):
                        gsq.launch(DOMAIN, _recv)

                    while gs.attr(_inst_name(), "") == "busy":
                        time.sleep(0.100)

                    mg_bin = _margo_bin()
                    cmd = [mg_bin, "-oom", gs.setting("margo_oom", 0), "-poll", 30, "-tag", TAG]

                    if os.path.exists(mg_bin):
                        c = sh.Command(cmd)
                        c.stderr = gs.LOGFILE
                        c.env = {"GOGC": 10, "XDG_CONFIG_HOME": gs.home_path()}

                        pr = c.proc()
                        if pr.ok:
                            proc = pr.p
                            err = ""
                        else:
                            proc = None
                            err = "Cannot start MarGo: %s" % pr.exc
                    else:
                        proc = None
                        err = "Can't find the MarGo binary at `%s`" % mg_bin

                    if err or not proc or proc.poll() is not None:
                        killSrv()

                        gs.notice(DOMAIN, "Cannot start MarGo:\n%s" % err)
                        try:
                            cb({}, "Abort. Cannot start MarGo")
                        except:
                            pass

                        continue

                    gs.set_attr(PROC_ATTR_NAME, proc)
                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                header, err = gs.json_encode(req.header())
                if err:
                    _cb_err(cb, "Failed to construct ipc header: %s" % err)
                    continue

                body, err = gs.json_encode(arg)
                if err:
                    _cb_err(cb, "Failed to construct ipc body: %s" % err)
                    continue

                ev.debug(DOMAIN, "margo request: %s " % header)

                ln = "%s %s\n" % (header, body)

                try:
                    if gs.PY3K:
                        proc.stdin.write(bytes(ln, "UTF-8"))
                    else:
                        proc.stdin.write(ln)

                except Exception as ex:
                    _cb_err(cb, "Cannot talk to MarGo: %s" % err)
                    killSrv()
                    gs.println(gs.traceback())

            except Exception:
                killSrv()
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
コード例 #14
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = gs.mg9_send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    killSrv()

                    if gs.attr(INSTALL_ATTR_NAME) != "busy":
                        maybe_install()

                    if not gs.checked(DOMAIN, 'launch _recv'):
                        gsq.launch(DOMAIN, _recv)

                    while gs.attr(INSTALL_ATTR_NAME) == "busy":
                        time.sleep(0.100)

                    proc, _, err = gsshell.proc(
                        [_margo_bin(), '-poll', 30, '-tag', TAG],
                        stderr=gs.LOGFILE,
                        env={
                            'XDG_CONFIG_HOME': gs.home_path(),
                        })
                    gs.set_attr(PROC_ATTR_NAME, proc)

                    if not proc:
                        gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err)
                        try:
                            cb({}, 'Abort. Cannot start MarGo')
                        except:
                            pass
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                header, err = gs.json_encode(req.header())
                if err:
                    _cb_err('Failed to construct ipc header: ' % err)
                    continue

                body, err = gs.json_encode(arg)
                if err:
                    _cb_err(cb, 'Failed to construct ipc body: ' % err)
                    continue

                gs.debug(DOMAIN, 'margo request: %s ' % header)

                ln = '%s %s\n' % (header, body)

                if gs.PY3K:
                    proc.stdin.write(bytes(ln, 'UTF-8'))
                else:
                    proc.stdin.write(ln)
            except Exception:
                killSrv()
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break