// TODO func Init() { l := py.NewLock() defer l.Unlock() m, err := py.Import("sublime_plugin") if err != nil { panic(err) } sys, err := py.Import("sys") if err != nil { log4go.Debug(err) } else { defer sys.Decref() } watcher, err = fsnotify.NewWatcher() if err != nil { log4go.Error("Could not create watcher due to: %v", err) } watchedPlugins = make(map[string]*backend.WatchedPackage) go observePlugins(m) plugins := packages.ScanPlugins(backend.LIME_USER_PACKAGES_PATH, ".py") for _, p := range plugins { // TODO: add all plugins after supporting all commands if p.Name() == path.Join("..", "..", "3rdparty", "bundles", "Vintageous") { loadPlugin(p, m) } } }
// TODO func Init() { l := py.NewLock() defer l.Unlock() m, err := py.Import("sublime_plugin") if err != nil { panic(err) } sys, err := py.Import("sys") if err != nil { log.Debug(err) } else { defer sys.Decref() } if watcher, err = watch.NewWatcher(); err != nil { log.Error("Couldn't create watcher: %s", err) } plugins := packages.ScanPlugins(backend.LIME_USER_PACKAGES_PATH, ".py") for _, p := range plugins { // TODO: add all plugins after supporting all commands if p.Name() == path.Join("..", "..", "3rdparty", "bundles", "Vintageous") { pl := newPlugin(p, m) pl.reload() if err := watcher.Watch(pl.Name(), pl); err != nil { log.Error("Couldn't watch %s: %s", pl.Name(), err) } } } go watcher.Observe() }
func TestSublime(t *testing.T) { ed := backend.GetEditor() ed.SetClipboardFuncs(func(n string) (err error) { dummyClipboard = n return nil }, func() (string, error) { return dummyClipboard, nil }) defer ed.Init() ed.Console().Buffer().AddCallback(func(b text.Buffer, pos, delta int) { t.Logf("%s", b.Substr(text.Region{pos, pos + delta})) }) w := ed.NewWindow() Init() l := py.NewLock() py.AddToPath("testdata") py.AddToPath("testdata/plugins") if m, err := py.Import("sublime_plugin"); err != nil { t.Fatal(err) } else { plugins := packages.ScanPlugins("testdata/", ".py") for _, p := range plugins { pl := newPlugin(p, m) pl.reload() if err := watcher.Watch(pl.Name(), pl); err != nil { t.Fatalf("Couldn't watch %s: %s", pl.Name(), err) } } } subl, err := py.Import("sublime") if err != nil { t.Fatal(err) } if w, err := _windowClass.Alloc(1); err != nil { t.Fatal(err) } else { (w.(*Window)).data = &backend.Window{} subl.AddObject("test_window", w) } // Testing plugin reload data := []byte(`import sublime, sublime_plugin class TestToxt(sublime_plugin.TextCommand): def run(self, edit): print("my view's id is: %d" % self.view.id()) self.view.insert(edit, 0, "Tada") `) if err := ioutil.WriteFile("testdata/plugins/reload.py", data, 0644); err != nil { t.Fatalf("Couldn't write testdata/plugins/reload.py: %s", err) } defer os.Remove("testdata/plugins/reload.py") time.Sleep(time.Millisecond * 50) if dir, err := os.Open("testdata"); err != nil { t.Error(err) } else if files, err := dir.Readdirnames(0); err != nil { t.Error(err) } else { for _, fn := range files { if filepath.Ext(fn) == ".py" { log.Debug("Running %s", fn) if _, err := py.Import(fn[:len(fn)-3]); err != nil { log.Error(err) t.Error(err) } else { log.Debug("Ran %s", fn) } } } } var f func(indent string, v py.Object, buf *bytes.Buffer) f = func(indent string, v py.Object, buf *bytes.Buffer) { b := v.Base() if dir, err := b.Dir(); err != nil { t.Error(err) } else { if l, ok := dir.(*py.List); ok { sl := l.Slice() if indent == "" { for _, v2 := range sl { if item, err := b.GetAttr(v2); err != nil { t.Error(err) } else { ty := item.Type() line := fmt.Sprintf("%s%s\n", indent, v2) buf.WriteString(line) if ty == py.TypeType { f(indent+"\t", item, buf) } item.Decref() } } } else { for _, v2 := range sl { buf.WriteString(fmt.Sprintf("%s%s\n", indent, v2)) } } } else { ty := dir.Type() t.Error("Unexpected type:", ty) } dir.Decref() } } buf := bytes.NewBuffer(nil) f("", subl, buf) l.Unlock() const expfile = "testdata/api.txt" if d, err := ioutil.ReadFile(expfile); err != nil { if err := ioutil.WriteFile(expfile, buf.Bytes(), 0644); err != nil { t.Error(err) } } else if diff := util.Diff(string(d), buf.String()); diff != "" { t.Error(diff) } ed.LogCommands(true) tests := []string{ "state", "registers", "settings", "constants", "registers", "cmd_data", "marks", } for _, test := range tests { ed.CommandHandler().RunWindowCommand(w, "vintage_ex_run_data_file_based_tests", backend.Args{"suite_name": test}) } for _, w := range ed.Windows() { for _, v := range w.Views() { if strings.HasSuffix(v.Buffer().FileName(), "sample.txt") { continue } if strings.Index(v.Buffer().Substr(text.Region{0, v.Buffer().Size()}), "FAILED") != -1 { t.Error(v.Buffer()) } } } var v *backend.View for _, v2 := range w.Views() { if v == nil || v2.Buffer().Size() > v.Buffer().Size() { v = v2 } } }