Sublime Forum

V8 Engine for sublime text 2 - writing your plugin use JS

#1

Hi

I compiled the Google V8 engine and PyV8 (https://github.com/okoye/PyV8) under the windows 32bit and the mac osx, build pyv8 as a plugin of sublime text 2.

Added a realtime syntax checking & jshint on js file
Added a javascript console like the python one
Wrote an example (test.js) shows how to writing your own plugin use JavaScript

You can download it here:

sublime-v8 for win32 -  [https://github.com/akira-cn/sublime-v8-win32](https://github.com/akira-cn/sublime-v8-win32)
sublime-v8 for osx - [https://github.com/akira-cn/sublime-v8-osx](https://github.com/akira-cn/sublime-v8-osx)

enjoy~ :smile:

0 Likes

#2

Interesting idea.

Doesn’t seem to work on mac.

Traceback (most recent call last): File "./sublime_plugin.py", line 110, in create_window_commands File "./jshint.py", line 15, in __init__ IOError: [Errno 2] No such file or directory: 'jshint.js'

Also ctrl+alt+j does not bring up a console.

0 Likes

#3

I fixed the “no such file or directory” error.

in jshint.py

def __init__(self, window): self.panel = window.get_output_panel(JSHINT_VIEW_NAME) self.panel.set_name(JSHINT_VIEW_NAME) self.window = window ctx = PyV8.JSContext() ctx.enter() jshint_file = file(os.path.join(sublime.packages_path(),"sublime-v8-osx", "jshint.js")) source = jshint_file.read() self.jshint = ctx.eval(source) jshint_file.close()

You need to run all of your python code through something like SublimeLinter. It would also be very helpful to be very consistant with tabs vs spaces. It is really hard to look at.

After I fixed this, it appears your plist for the console theme is borked as well.

0 Likes

#4

Sorry, I set the wrong file path.

Now, the bug had been fixed.

https://github.com/akira-cn/sublime-v8-osx/commit/c1929851dda2b118cd55d7039c7bb3ca962dc2fb

thanks

0 Likes

#5

Nice!

Seems to be working.

JS console is also now working. Not sure how I would use this yet, but I find it a pretty neat plugin.

0 Likes

#6

+1 for awesome! I might be able to make this a dependancy for my nodejs plugin to start doing some more debug features!

Thanks for the hard work

0 Likes

#7

This sounds freaking awesome!

0 Likes

#8

In the JS console I’ve noticed you don’t output loops fully: screencast.com/t/fOrXQdO7iz

In a loop it’s just outputting the last item (this is on MacOSX version, on 10.7.2 with the latest ST2 dev version)

0 Likes

#9

V8 is just the javascript engine yeah? Anyway, another colour on the palette :smile:

Dunno if I’d ever use javascript for plugins but I reckon avoiding subprocess for javascript linting is worth the fuss.

For a console I’d prefer some sort of browser integration. Only real context I’d want to evaluate javascript in.

0 Likes

#10

I’ve fixed this bug in the windows version:
https://github.com/akira-cn/sublime-v8-win32/commit/4c2b8ec177cffa15cad67ca1314f55252133b0a6

I think it’ll work fine at osx version as well
Since I cann’t tested in my macbook just now. I’ll update it later :smile:

thanks~

[quote=“tanepiper”]In the JS console I’ve noticed you don’t output loops fully: screencast.com/t/fOrXQdO7iz

In a loop it’s just outputting the last item (this is on MacOSX version, on 10.7.2 with the latest ST2 dev version)[/quote]

updated

https://github.com/akira-cn/sublime-v8-osx/commit/3fc67de3a1e90be4f9675284630c83b55e47e6f9

0 Likes

#11

And now a proper javascript autocompletion for custom objects and functions on top of this… Could this be possible without a window environment? Would be awesome though…

0 Likes

#12

It seems a portion of your code checks for a member that doesn’t always exist.

In jshint.py it sometimes checks for error.id, but id doesn’t always exist. I haven’t root caused the issue, but instead patched the symptom for now.

if(settings.get("warnings") or (hasattr(error, 'id') and re.compile("^error ").match(error.id))): self.panel.insert(edit, self.panel.size(), error.id + ' : ' + error.reason + ' ,'.join(details) + ' \n') if(hasattr(error, 'id') and re.compile("^warning ").match(error.id)): count_warnings = count_warnings + 1

This really is a fantastic plugin. Keep up the great work.

0 Likes

#13

bugfixed:

jshint error.id doesn’t exist sometimes
JSHINT.sublime-settings loading path fixed

github.com/akira-cn/sublime-v8-osx

thanks~

0 Likes

#14

icanhaz linux version?

0 Likes

#15

I haven’t tested sublime text2 on linux yet

I use to build a PyV8 linux_x86_64 version successfully on my linode ubuntu (I cannot build the trunk lastest version of PyV8 to my ubuntu, but I did build the v8 r6125 + pyv8 r316)

I guess it can work fine if you just build the PyV8.py and _PyV8.so on your own linux os and copy the release file to the sublime-v8-xxx plugin directory (replace the .py and the .so)

thanks~

0 Likes

#16

Great plugin Akira! Thanks for the hard work and bug fixes.
I was about to create my own javascript console yesterday evening and stumbled upon yours after looking around.
Why is this not on the community package page? wbond.net/sublime_packages/community

0 Likes

#17

Can i haz win64 version or if you don’t have access to a win64 machine, newbie instructions for compiling to win64 so I can give it a try. If I can get it to compile, I’ll gladly commit to your github if you like.

Also, +1 for community package idea wbond.net/sublime_packages/community

This is insanely awesome, Akira. Thank you!

0 Likes

#18

Thanks for the test.js file, the code seems easy to follow. I don’t know what to do with the file though. Where do I put it, how do I activate it?

Are there any other examples or related resources on the net?

0 Likes

#19

+1 for 64 bit version
+1 for community package

0 Likes

#20

Looks like it’s been added to the community package list… so that’s good. :smile: Now we just need a 64bit compatible library… :smiley:

0 Likes