Exemplo n.º 1
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    if proc:
                        try:
                            proc.kill()
                            proc.stdout.close()
                        except:
                            pass

                    maybe_install()

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

                    proc, _, err = gsshell.proc([MARGO9_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 MarGo: %s' % err)
                        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)
                proc.stdin.write(ln)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Exemplo n.º 2
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = _send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					if proc:
						try:
							proc.kill()
							proc.stdout.close()
						except:
							pass

					maybe_install()

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

					proc, _, err = gsshell.proc([MARGO9_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 MarGo: %s' % err)
						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)
				proc.stdin.write(ln)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
Exemplo n.º 3
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _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(
                        [MARGO9_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)
                proc.stdin.write(ln)
            except Exception:
                killSrv()
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Exemplo n.º 4
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr("mg9.proc")
                if not proc or proc.poll() is not None:
                    if proc:
                        try:
                            proc.kill()
                            proc.stdout.close()
                        except:
                            pass

                    maybe_install()

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

                        # ideally the env should be setup before-hand with a bcall
                        # so we won't run this through the shell
                    proc, _, err = gsshell.proc([MARGO9_BIN], stderr=gs.LOGFILE)
                    gs.set_attr("mg9.proc", proc)

                    if not proc:
                        gs.notice(DOMAIN, "Cannot start MarGo9: %s" % err)
                        continue

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

                token = "mg9.autoken.%s" % uuid.uuid4()
                _stash[token] = cb

                header, _ = gs.json_encode({"method": method, "token": token})
                body, _ = gs.json_encode(arg)
                ln = "%s %s\n" % (header, body)
                proc.stdin.write(ln)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Exemplo n.º 5
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = _send_q.get()

				proc = gs.attr('mg9.proc')
				if not proc or proc.poll() is not None:
					if proc:
						try:
							proc.kill()
							proc.stdout.close()
						except:
							pass

					maybe_install()

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

					proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=5'], stderr=gs.LOGFILE)
					gs.set_attr('mg9.proc', proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot start MarGo9: %s' % err)
						continue

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

				token = 'mg9.autoken.%s' % uuid.uuid4()
				_stash[token] = cb

				header, _ = gs.json_encode({'method': method, 'token': token})
				body, _ = gs.json_encode(arg)
				ln = '%s %s\n' % (header, body)
				proc.stdin.write(ln)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
Exemplo n.º 6
0
    'go env',
    'go fix',
    'go fmt',
    'go get',
    'go install',
    'go list',
    'go run',
    'go test',
    'go tool',
    'go version',
    'go vet',
    'go help',
]
DEFAULT_CL = [(s, s + ' ') for s in DEFAULT_COMMANDS]

if not gs.checked(DOMAIN, '_vars'):
    stash = {}
    tid_alias = {}


def active_wd(win=None):
    _, v = gs.win_view(win=win)
    return gs.basedir_or_cwd(v.file_name() if v else '')


def wdid(wd):
    return '9o://%s' % wd


class EV(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
Exemplo n.º 7
0
def acall(method, arg, cb):
	if not gs.checked(DOMAIN, 'launch _send'):
		gsq.launch(DOMAIN, _send)

	_send_q.put((method, arg, cb))
Exemplo n.º 8
0
import atexit

DOMAIN = 'MarGo9'
REQUEST_PREFIX = '%s.rqst.' % DOMAIN
PROC_ATTR_NAME = 'mg9.proc'

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path('something_borrowed/margo0')
MARGO9_SRC = gs.dist_path('margo9')
MARGO0_EXE = 'gosublime.margo0.exe'
MARGO9_EXE = 'gosublime.margo9.exe'
MARGO0_BIN = gs.home_path('bin', MARGO0_EXE)
MARGO9_BIN = gs.home_path('bin', MARGO9_EXE)

if not gs.checked(DOMAIN, '_vars'):
	_send_q = Queue.Queue()
	_recv_q = Queue.Queue()

class Request(object):
	def __init__(self, f, method='', token=''):
		self.f = f
		self.tm = time.time()
		self.method = method
		if token:
			self.token = token
		else:
			self.token = 'mg9.autoken.%s' % uuid.uuid4()

def _sb(s):
	bdir = gs.home_path('bin')
Exemplo n.º 9
0
	'go env',
	'go fix',
	'go fmt',
	'go get',
	'go install',
	'go list',
	'go run',
	'go test',
	'go tool',
	'go version',
	'go vet',
	'go help',
]
DEFAULT_CL = [(s, s+' ') for s in DEFAULT_COMMANDS]

if not gs.checked(DOMAIN, '_vars'):
	stash = {}
	tid_alias = {}

def active_wd(win=None):
	_, v = gs.win_view(win=win)
	return gs.basedir_or_cwd(v.file_name() if v else '')

def wdid(wd):
	return '9o://%s' % wd


class EV(sublime_plugin.EventListener):
	def on_query_completions(self, view, prefix, locations):
		pos = gs.sel(view).begin()
		if view.score_selector(pos, 'text.9o') == 0:
Exemplo n.º 10
0
def acall(method, arg, cb):
    if not gs.checked(DOMAIN, 'launch _send'):
        gsq.launch(DOMAIN, _send)

    _send_q.put((method, arg, cb))
Exemplo n.º 11
0
import atexit

DOMAIN = 'MarGo9'
REQUEST_PREFIX = '%s.rqst.' % DOMAIN
PROC_ATTR_NAME = 'mg9.proc'

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path('something_borrowed/margo0')
MARGO9_SRC = gs.dist_path('margo9')
MARGO0_EXE = 'gosublime.margo0.exe'
MARGO9_EXE = 'gosublime.margo9.exe'
MARGO0_BIN = gs.home_path('bin', MARGO0_EXE)
MARGO9_BIN = gs.home_path('bin', MARGO9_EXE)

if not gs.checked(DOMAIN, '_vars'):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()


class Request(object):
    def __init__(self, f, method='', token=''):
        self.f = f
        self.tm = time.time()
        self.method = method
        if token:
            self.token = token
        else:
            self.token = 'mg9.autoken.%s' % uuid.uuid4()

Exemplo n.º 12
0
def plugin_loaded():
	if not gs.checked(DOMAIN, 'do_init'):
		atexit.register(killSrv)
		sublime.set_timeout(do_init, 0)
Exemplo n.º 13
0
import time
import hashlib
import base64
import Queue
import uuid

DOMAIN = "MarGo9"

# customization of, or user-owned gocode and margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO9_SRC = gs.dist_path("margo9")
GOCODE_SRC = gs.dist_path("something_borrowed/gocode")
MARGO9_BIN = gs.home_path("bin", "gosublime.margo9.exe")
GOCODE_BIN = gs.home_path("bin", "gosublime.gocode.exe")

if not gs.checked(DOMAIN, "_vars"):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()
    _stash = {}


def _sb(s):
    bdir = gs.home_path("bin")
    if s.startswith(bdir):
        s = "~bin%s" % (s[len(bdir) :])
    return s


def _tp(s):
    return (_sb(s), ("ok" if os.path.exists(s) else "missing"))