def do_comp_lint(dirname, fn): fr = ref(fn, False) reports = {} if not fr: return fn = gs.apath(fn, dirname) bindir, _ = gs.temp_dir('bin') local_env = { 'GOBIN': bindir, } pat = r'%s:(\d+)(?:[:](\d+))?\W+(.+)\s*' % re.escape(os.path.basename(fn)) pat = re.compile(pat, re.IGNORECASE) for c in gs.setting('comp_lint_commands'): try: cmd = c.get('cmd') if not cmd: continue cmd_domain = ' '.join(cmd) shell = c.get('shell') is True env = {} if c.get('global') is True else local_env out, err, _ = gsshell.run(cmd=cmd, shell=shell, cwd=dirname, env=env) if err: gs.notice(DOMAIN, err) out = out.replace('\r', '').replace('\n ', '\\n ').replace('\n\t', '\\n\t') for m in pat.findall(out): try: row, col, msg = m row = int(row) - 1 col = int(col) - 1 if col else 0 msg = msg.replace('\\n', '\n').strip() if row >= 0 and msg: msg = '%s: %s' % (cmd_domain, msg) if reports.get(row): reports[row].msg = '%s\n%s' % (reports[row].msg, msg) reports[row].col = max(reports[row].col, col) else: reports[row] = Report(row, col, msg) except: pass except: gs.notice(DOMAIN, gs.traceback()) def cb(): fr.reports = reports fr.state = 1 highlight(fr) sublime.set_timeout(cb, 0)
def do_comp_lint(dirname, fn): fr = ref(fn, False) reports = {} if not fr: return fn = gs.apath(fn, dirname) bindir, _ = gs.temp_dir('bin') local_env = { 'GOBIN': bindir, } pat = r'%s:(\d+)(?:[:](\d+))?\W+(.+)\s*' % re.escape(os.path.basename(fn)) pat = re.compile(pat, re.IGNORECASE) for c in gs.setting('comp_lint_commands'): try: cmd = c.get('cmd') if not cmd: continue cmd_domain = ' '.join(cmd) shell = c.get('shell') is True env = {} if c.get('global') is True else local_env out, err, _ = gsshell.run(cmd=cmd, shell=shell, cwd=dirname, env=env) if err: gs.notice(DOMAIN, err) out = out.replace('\r', '').replace('\n ', '\\n ').replace('\n\t', '\\n\t') for m in pat.findall(out): try: row, col, msg = m row = int(row)-1 col = int(col)-1 if col else 0 msg = msg.replace('\\n', '\n').strip() if row >= 0 and msg: msg = '%s: %s' % (cmd_domain, msg) if reports.get(row): reports[row].msg = '%s\n%s' % (reports[row].msg, msg) reports[row].col = max(reports[row].col, col) else: reports[row] = Report(row, col, msg) except: pass except: gs.notice(DOMAIN, gs.traceback()) def cb(): fr.reports = reports fr.state = 1 highlight(fr) sublime.set_timeout(cb, 0)
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*(.*)", }, )