예제 #1
0
 def act_jump_to(self, loc):
     view = gs.active_valid_go_view(self.window)
     if view:
         row, col = gs.rowcol(view)
         if loc.row != row:
             self.log_bookmark(Loc(view.file_name(), row, col))
         self.goto(loc)
예제 #2
0
파일: gscommands.py 프로젝트: ski/GoSublime
    def run(self):
        default_file_name = "untitled.go"
        pkg_name = "main"
        view = gs.active_valid_go_view()
        try:
            basedir = gs.basedir_or_cwd(view and view.file_name())
            for fn in os.listdir(basedir):
                if fn.endswith(".go"):
                    name, _ = mg9.pkg_name(os.path.join(basedir, fn), "")
                    if name:
                        pkg_name = name
                        break
        except Exception:
            gs.error_traceback("GsNewGoFile")

        view = self.window.new_file()
        view.set_name(default_file_name)
        view.set_syntax_file("Packages/GoSublime/GoSublime.tmLanguage")
        edit = view.begin_edit()
        try:
            view.replace(edit, sublime.Region(0, view.size()), "package %s\n" % pkg_name)
            view.sel().clear()
            view.sel().add(view.find(pkg_name, 0, sublime.LITERAL))
        finally:
            view.end_edit(edit)
예제 #3
0
    def jump_to_imports(self):
        view = gs.active_valid_go_view()
        if not view:
            return

        last_import = last_import_path.get(view.file_name())
        r = None
        if last_import:
            offset = len(last_import) + 2
            last_import = re.escape(last_import)
            pat = '(?s)import.*?(?:"%s"|`%s`)' % (last_import, last_import)
            r = view.find(pat, 0)

        if not r:
            offset = 1
            pat = '(?s)import.*?["`]'
            r = view.find(pat, 0)

        if not r:
            gs.notice(DOMAIN, "cannot find import declarations")
            return

        pt = r.end() - offset
        row, col = view.rowcol(pt)
        loc = Loc(view.file_name(), row, col)
        self.jump_to((view, loc))
예제 #4
0
    def show_palette(self):
        view = gs.active_valid_go_view(self.window)
        if view:
            items = [[" ", "GoSublime Palette"]]
            actions = {}
            if len(self.bookmarks) > 0:
                loc = self.bookmarks[-1]
                line = "line %d" % (loc.row + 1)
                if view.file_name() == loc.fn:
                    fn = ""
                else:
                    fn = relpath(loc.fn, dirname(loc.fn))
                    if fn.startswith(".."):
                        fn = loc.fn
                    fn = "%s " % fn
                items[0][0] = u"\u2190 Go Back (%s%s)" % (fn, line)
                actions[0] = (self.act_jump_back, None)

            for tup in self.items:
                item, action, args = tup
                actions[len(items)] = (action, args)
                items.append(item)
            self.items = []

            def on_done(i):
                action, args = actions.get(i, (None, None))
                if i >= 0 and action:
                    action(args)

            self.window.show_quick_panel(items, on_done)
예제 #5
0
파일: gspalette.py 프로젝트: ski/GoSublime
	def jump_to_imports(self):
		view = gs.active_valid_go_view()
		if not view:
			return

		last_import = last_import_path.get(view.file_name())
		r = None
		if last_import:
			offset = len(last_import) + 2
			last_import = re.escape(last_import)
			pat = '(?s)import.*?(?:"%s"|`%s`)' % (last_import, last_import)
			r = view.find(pat, 0)

		if not r:
			offset = 1
			pat = '(?s)import.*?["`]'
			r = view.find(pat, 0)

		if not r:
			gs.notice(DOMAIN, "cannot find import declarations")
			return

		pt = r.end() - offset
		row, col = view.rowcol(pt)
		loc = Loc(view.file_name(), row, col)
		self.jump_to((view, loc))
예제 #6
0
    def run(self):
        default_file_name = 'untitled.go'
        pkg_name = 'main'
        view = gs.active_valid_go_view()
        try:
            basedir = gs.basedir_or_cwd(view and view.file_name())
            for fn in os.listdir(basedir):
                if fn.endswith('.go'):
                    name, _ = margo.package(os.path.join(basedir, fn), '')
                    if name and name.get('Name'):
                        pkg_name = name.get('Name')
                        break
        except Exception:
            pass

        view = self.window.new_file()
        view.set_name(default_file_name)
        view.set_syntax_file('Packages/Go/Go.tmLanguage')
        edit = view.begin_edit()
        try:
            view.replace(edit, sublime.Region(0, view.size()),
                         'package %s\n' % pkg_name)
            view.sel().clear()
            view.sel().add(view.find(pkg_name, 0, sublime.LITERAL))
        finally:
            view.end_edit(edit)
예제 #7
0
파일: gscommands.py 프로젝트: d3z/GoSublime
	def run(self):
		default_file_name = 'untitled.go'
		pkg_name = 'main'
		view = gs.active_valid_go_view()
		try:
			basedir = gs.basedir_or_cwd(view and view.file_name())
			for fn in os.listdir(basedir):
				if fn.endswith('.go'):
					name, _ = margo.package(os.path.join(basedir, fn), '')
					if name and name.get('Name'):
						pkg_name = name.get('Name')
						break
		except Exception:
			pass

		view = self.window.new_file()
		view.set_name(default_file_name)
		view.set_syntax_file('Packages/Go/Go.tmLanguage')
		edit = view.begin_edit()
		try:
			view.replace(edit, sublime.Region(0, view.size()), 'package %s\n' % pkg_name)
			view.sel().clear()
			view.sel().add(view.find(pkg_name, 0, sublime.LITERAL))
		finally:
			view.end_edit(edit)
예제 #8
0
파일: gslint.py 프로젝트: teejae/GoSublime
def describe_errors():
    view = gs.active_valid_go_view()
    if view:
        sel = view.sel()[0].begin()
        row, _ = view.rowcol(sel)
        gs.l_lsyncs[view.id()] = row
        er = gs.l_errors.get(view.id(), {}).get(row, ErrorReport(0, 0, ""))
        view.set_status("GsLint", ("GsLint: " + er.err) if er.err else "")
예제 #9
0
	def run(self):
		view = gs.active_valid_go_view(self.window)
		if not view:
			gs.notice("GsShell", "this not a source.go view")
			return

		p = Prompt(view)
		p.panel = self.window.show_input_panel("GsShell", "go ", p.on_done, p.on_change, None)
예제 #10
0
def watch():
	global file_refs
	global th

	view = gs.active_valid_go_view()

	if view is not None and (view.file_name() and gs.setting('comp_lint_enabled') is True):
		fn = view.file_name()
		fr = ref(fn)
		with sem:
			if fr:
				fr.view = view
				highlight(fr)
		sublime.set_timeout(watch, 500)
		return


	if gs.setting('gslint_enabled') is not True:
		if view:
			with sem:
				for fn in file_refs:
					fr = file_refs[fn]
					cleanup(fr.view)
				file_refs = {}
		sublime.set_timeout(watch, 2000)
		return

	if view and not view.is_loading():
		fn = view.file_name()
		fr = ref(fn)
		with sem:
			if fr:
				# always use the active view (e.g in split-panes)
				fr.view = view
				highlight(fr)
			else:
				fr = FileRef(view)

			file_refs[fn] = fr
			if fr.state == 0:
				src = view.substr(sublime.Region(0, view.size()))
				if src != fr.src:
					fr.src = src
					fr.tm = time.time()

				if fr.tm > 0.0:
					timeout = int(gs.setting('gslint_timeout', 500))
					delta = int((time.time() - fr.tm) * 1000.0)
					if delta >= timeout:
						fr.tm = 0.0
						fr.state = -1
						if not th:
							th = GsLintThread()
							th.start()
						th.putq(fn)

	sublime.set_timeout(watch, 500)
예제 #11
0
def watch():
    global file_refs
    global th

    view = gs.active_valid_go_view()

    if view is not None and (view.file_name()
                             and gs.setting('comp_lint_enabled') is True):
        fn = view.file_name()
        fr = ref(fn)
        with sem:
            if fr:
                fr.view = view
                highlight(fr)
        sublime.set_timeout(watch, 500)
        return

    if gs.setting('gslint_enabled') is not True:
        if view:
            with sem:
                for fn in file_refs:
                    fr = file_refs[fn]
                    cleanup(fr.view)
                file_refs = {}
        sublime.set_timeout(watch, 2000)
        return

    if view and not view.is_loading():
        fn = view.file_name()
        fr = ref(fn)
        with sem:
            if fr:
                # always use the active view (e.g in split-panes)
                fr.view = view
                highlight(fr)
            else:
                fr = FileRef(view)

            file_refs[fn] = fr
            if fr.state == 0:
                src = view.substr(sublime.Region(0, view.size()))
                if src != fr.src:
                    fr.src = src
                    fr.tm = time.time()

                if fr.tm > 0.0:
                    timeout = int(gs.setting('gslint_timeout', 500))
                    delta = int((time.time() - fr.tm) * 1000.0)
                    if delta >= timeout:
                        fr.tm = 0.0
                        fr.state = -1
                        if not th:
                            th = GsLintThread()
                            th.start()
                        th.putq(fn)

    sublime.set_timeout(watch, 500)
예제 #12
0
 def act_show_main_palette(self, _=None):
     view = gs.active_valid_go_view(self.window)
     if view:
         errors = gs.l_errors.get(view.id(), {})
         for k in sorted(errors.keys()):
             er = errors[k]
             loc = Loc(view.file_name(), er.row, er.col)
             self.add_item(["Error on line %d" % (er.row + 1), er.err], self.act_jump_to, loc)
         if gs.setting("margo_addr"):
             self.add_item("List Declarations", self.act_list_declarations)
         self.show_palette()
예제 #13
0
	def run(self, prompt="go ", run="", fmt_save=True):
		view = gs.active_valid_go_view(self.window)
		if not view:
			gs.notice(DOMAIN, "this not a source.go view")
			return

		run = run.strip()
		p = Prompt(view, run == "")
		if run:
			p.on_done(run, fmt_save)
		else:
			p.panel = self.window.show_input_panel("GsShell", prompt, p.on_done, p.on_change, None)
예제 #14
0
	def run(self, prompt="go ", run=""):
		view = gs.active_valid_go_view(self.window)
		if not view:
			gs.notice(DOMAIN, "this not a source.go view")
			return

		run = run.strip()
		p = Prompt(view, run == "")
		if run:
			p.on_done(run)
		else:
			p.panel = self.window.show_input_panel("GsShell", prompt, p.on_done, p.on_change, None)
예제 #15
0
	def present_current(self):
		pkg_dir = ''
		view = gs.active_valid_go_view(win=self.window, strict=False)
		if view:
			if view.file_name():
				pkg_dir = os.path.dirname(view.file_name())
			vfn = gs.view_fn(view)
			src = gs.view_src(view)
		else:
			vfn = ''
			src = ''
		self.present(vfn, src, pkg_dir)
예제 #16
0
    def show_palette(self, palette, direct=False):
        view = gs.active_valid_go_view(self.window)
        if not view:
            return

        palette = palette.lower().strip()
        if palette == 'auto':
            palette = self.last_activate_palette
        elif palette == 'main':
            palette = ''

        pcb = None
        if palette:
            pcb = self.palettes.get(palette)
            if pcb:
                self.last_activate_palette = palette
            else:
                gs.notice(DOMAIN, 'Invalid palette `%s`' % palette)
                palette = ''

        if not direct and len(self.bookmarks) > 0:
            loc = self.bookmarks[-1]
            line = 'line %d' % (loc.row + 1)
            if view.file_name() == loc.fn:
                fn = ''
            else:
                fn = relpath(loc.fn, dirname(loc.fn))
                if fn.startswith('..'):
                    fn = loc.fn
                fn = '%s ' % fn
            self.add_item(u'\u2190 Go Back (%s%s)' % (fn, line),
                          self.jump_back, None)

        if not direct and palette:
            self.add_item(u'@%s \u21B5' % palette.title(), self.show_palette,
                          'main')

        li1 = len(self.items)
        if pcb:
            pcb(view, direct)

        if not direct:
            for k in sorted(self.palettes.keys()):
                if k:
                    if k != palette:
                        ttl = '@' + k.title()
                        if k == 'errors':
                            fr = gslint.ref(view.file_name())
                            if not fr or len(fr.reports) == 0:
                                continue
                            ttl = '%s (%d)' % (ttl, len(fr.reports))
                        itm = ttl
                        self.add_item(itm, self.show_palette, k)
예제 #17
0
파일: gspalette.py 프로젝트: ski/GoSublime
	def show_palette(self, palette, direct=False):
		view = gs.active_valid_go_view(self.window)
		if not view:
			return

		palette = palette.lower().strip()
		if palette == 'auto':
			palette = self.last_activate_palette
		elif palette == 'main':
			palette = ''

		pcb = None
		if palette:
			pcb = self.palettes.get(palette)
			if pcb:
				self.last_activate_palette = palette
			else:
				gs.notice(DOMAIN, 'Invalid palette `%s`' % palette)
				palette = ''

		if not direct and len(self.bookmarks) > 0:
			loc = self.bookmarks[-1]
			line = 'line %d' % (loc.row + 1)
			if view.file_name() == loc.fn:
				fn = ''
			else:
				fn = relpath(loc.fn, dirname(loc.fn))
				if fn.startswith('..'):
					fn = loc.fn
				fn = '%s ' % fn
			self.add_item(u'\u2190 Go Back (%s%s)' % (fn, line), self.jump_back, None)

		if not direct and palette:
			self.add_item(u'@%s \u21B5' % palette.title(), self.show_palette, 'main')

		li1 = len(self.items)
		if pcb:
			pcb(view, direct)

		if not direct:
			for k in sorted(self.palettes.keys()):
				if k:
					if k != palette:
						ttl = '@' + k.title()
						if k == 'errors':
							fr = gslint.ref(view.file_name())
							if not fr or len(fr.reports) == 0:
								continue
							ttl = '%s (%d)' % (ttl, len(fr.reports))
						itm = ttl
						self.add_item(itm, self.show_palette, k)
예제 #18
0
 def act_list_declarations(self, _=None):
     view = gs.active_valid_go_view(self.window)
     if view:
         m = margo.request(
             "/declarations", {"filename": view.file_name(), "src": view.substr(sublime.Region(0, view.size()))}
         )
         if m:
             if m.has_key("error"):
                 gs.notice("GsPalette", m["error"])
             decls = m.get("declarations", [])
             decls.sort(key=lambda v: v["line"])
             for i, v in enumerate(decls):
                 if v["name"] in ("main", "init", "_"):
                     continue
                 loc = Loc(v["filename"], v["line"] - 1, v["column"] - 1)
                 prefix = u" %s \u00B7   " % gs.CLASS_PREFIXES.get(v["kind"], "")
                 self.add_item([prefix + v["name"], v["doc"]], self.act_jump_to, loc)
             self.show_palette()
예제 #19
0
파일: gslint.py 프로젝트: teejae/GoSublime
def vsync():
    delay = 1000
    view = gs.active_valid_go_view()
    if view:
        if gs.setting("gslint_enabled", False):
            delay = 250
            vid = view.id()
            size = view.size()
            tm, sz = gs.l_vsyncs.get(vid, (0.0, -1))
            if sz != size:
                gs.l_vsyncs[vid] = (time.time(), size)
            elif tm > 0.0 and sz == size:
                timeout = int(gs.setting("gslint_timeout", 500))
                delta = int((time.time() - tm) * 1000.0)
                if delta >= timeout:
                    gs.l_vsyncs[vid] = (0.0, size)
                    with gs.l_lt.sem:
                        gs.l_lt.view_real_path = view.file_name()
                        gs.l_lt.view_src = view.substr(sublime.Region(0, size))
                        gs.l_lt.view_id = vid
                        gs.l_lt.view = view
                        gs.l_lt.notify()
                        gs.l_lt.cmd = gs.setting("gslint_cmd", [])
                    return

            row, _ = view.rowcol(view.sel()[0].begin())
            rw = gs.l_lsyncs.get(vid, -1)
            if row != rw:
                gs.l_lsyncs[vid] = row
                describe_errors()
        else:
            delay = 5000
            gs.l_errors = {}
            describe_errors()
            view.erase_regions("GsLint-errors")
    set_timeout(vsync, delay)
예제 #20
0
 def is_enabled(self):
     view = gs.active_valid_go_view(self.window)
     return bool(view)
예제 #21
0
 def is_enabled(self):
     view = gs.active_valid_go_view(self.window)
     return view is not None
예제 #22
0
 def log_bookmark(self, loc):
     view = gs.active_valid_go_view(self.window)
     if view:
         bks = self.bookmarks
         if len(bks) == 0 or (bks[-1].row != loc.row and bks[-1].fn != view.file_name()):
             bks.append(loc)
예제 #23
0
파일: gspalette.py 프로젝트: ski/GoSublime
	def is_enabled(self):
		return bool(gs.active_valid_go_view(self.window))
예제 #24
0
 def is_enabled(self):
     return bool(gs.active_valid_go_view(self.window))
예제 #25
0
	def is_enabled(self):
		view = gs.active_valid_go_view(self.window)
		return view is not None
예제 #26
0
	def is_enabled(self):
		view = gs.active_valid_go_view(self.window)
		return bool(view)