Javascript support

General Discussion goes here.

Moderator: robert

Javascript support

Postby Guest » Mon Jan 30, 2012 11:09 am

Hi,

I am looking at the RSyntaxTextArea and I am integrating with our product as we need a javascript editor. The editor needs to be able to:

1) Show javascript syntax color coding
2) Have the ability of autocomplete support for variables (local to functions and global to document), functions.
3) Add my own functions (Java) as we are using Rhino as the backend.

I have written some of the code to add the functions and parse local/global variables. I now notice you have added the Javascript support into your trunk version of SVN.

I had written an extension to the Java language support to add additional Rhino methods (Java methods) and I will now look to use the new Javascript Language support classes within the project.

I am wondering how complete this is?

Kind regards

Steve Upton
Guest
 

Re: Javascript support

Postby robert » Tue Jan 31, 2012 3:28 am

Hi Steve,

JS support is just getting started. I just blogged about it, but the latest in Subversion already looks better. It currently should be squiggle underlining syntax errors, and allow code completion of local variables and functions. Ctrl+Shift+O opens a "go to member" window like Eclipse. It currently does not handle local variables in functions or variable scope yet though. Those two things are next on the list.

I must admit I'm in the "know just enough to be dangerous" category when it comes to JavaScript, so it's nice to know there's someone looking to use the functionality to double check the end result. :)

If you're interested in collaborating, feel free to check out what's in SVN and play with it. I'll gladly accept patches that would be beneficial to other users of the library. As you're aware, it's being actively developed, so it may change rather frequently over the next couple of weeks. It's currently basically a copy of the Java language support, but calls into Rhino for the parsing instead of using a custom parser.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Javascript support

Postby Guest » Tue Jan 31, 2012 11:43 am

Thanks Robert,

I have updated with SVN. Everything looks great, apart from I will be needing local variables when the caret position is within a function:

e.g
-------------------------------------------------------
var a = "myvar1";

//caret position 1

function callMe(b, c, d)
{
//do something with b, c and d
//caret position 2;
var e = "myvar2"
//caret position 3
}

//caret position 4
-------------------------------------------------------

1) caret position 1 and 4 I would expect to see variable a and function callMe in the autocomplete
2) caret position 2 I would expect to see variables a, b, c, d and function callMe in the autocomplete
3) caret position 3 I would expect to see variables a, b, c, d, e and function callMe in the autocomplete

In org.fife.rsta.ac.java.SourceCompletionProvider, I notice you parse the document using Scanner and create code blocks and then work out which variables you can see in the autocomplete based on the caret position etc....

I noticed that you have parsed the Javascript file using Rhino (SourceCompletionProvider within javascript package) and extracted the functions and variables from there. Looks like it will need a method:

loadCompletionsForCaretPosition(...)


Another BIG thing for me is types and whether the variables will support auto complete for Strings, Numbers and Java class types?

e.g
var str = "abc";
var num = 12;

typing str. should show autocomplete with all javascript String methods available.
typing num. should show autocomplete with all javascript Number methods available.



A lot of the code I have written is custom for our own usage. I will also start my project again and extend the Javascript completion provider so I can add our own functions and shorthand completions (e.g for loop etc...). I will see how I get on with the new javascript package. Looks like this is coming at the perfect time for me :D.

Kind regards

Steve Upton
Guest
 

Re: Javascript support

Postby robert » Tue Jan 31, 2012 2:08 pm

Aye, scoping for code completion will come; don't worry!

And yes, I had forgotten about variable types. Of course it's a little trickier than with Java, since JS uses dynamic typing. I believe we'd just have to try to determine the most recent type assigned to a variable from the caret position? It also looks like you can parse JSDoc to determine the expected types of function parameters. Well, baby steps...
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Javascript support

Postby steven_upton » Tue Jan 31, 2012 4:01 pm

Excellent, all sounds great to me. :D
steven_upton
 
Posts: 4
Joined: Mon Jan 30, 2012 11:06 am


Return to General

Who is online

Users browsing this forum: Exabot [Bot] and 9 guests

cron