Home Download Buy Blog Forum Support

JavaScript completions

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 1:10 pm

Hello. My work here is done :D and I've attached my final JS completions file, enjoy!

There is a lot of good stuff in it, but I'm not foolish enough to say it's complete. I think it is as comprehensive as it can be, for a single file.
Of course, the advantage of it being a completions file, rather than a complex Python script, is that you are free to add, delete, move items as you wish.

As mentioned previously, I don't think it will work well with CodeIntel, unless you are able to turn that off just for JavaScript(?).

Please let me know if you discover any mistakes :lol: or obvious omissions.

The object names you can use to try and narrow a search are:
Anchor, Area, Array, Attr, Body, Canvas, Date, Document, Event, Form, Frame, Frameset, Function, History, Image, Input, JSON, Link, Location, Math, Meta, Navigator, Number, Object, object, Option, RegExp, Screen, Select, String, Table, TD,H,R, TextArea, Window. (And an underscore '_' for style properties.)

I removed the term Element, as everything is an element and it won't help narrow a search;
Rather than Date it might work better to type day, month, etc., get, set, or to;
If manipulating the DOM try words like node, create, append, child, sibling.

All the best and, as before, I would very much appreciate any feedback. Andy.
Attachments
AndyJS3.zip
Part 3 Final
(10.1 KiB) Downloaded 139 times
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby senzo on Fri Feb 03, 2012 1:35 pm

Have been looking at version 2 just the moment you released version 3 ;)

The first thing I stumbled upon is the completion after typing "if" which is "mimeTypes FF ..." (somewhere down the list). Any Ideas why this is happening? If I complete with TAB, undo and TAB again I get "if (true) {};" as expected.
senzo
 
Posts: 106
Joined: Tue May 24, 2011 9:17 am

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 2:40 pm

Hello senzo.

I haven't got your exact behaviour in version 2 or 3. I think it's because ST takes a semi-intelligent approach to suggesting completions. That is, it remembers what you've used previously. To resolve this:

type 'if' and scroll in the completion to select 'if () { }';
perhaps start a new js file in the same project and try the first step in this file;
type 'if', press escape to dismiss the completions list, and press tab a couple of times.

I notice in the project's workspace file it maintains a list of 'selected-items' for 'auto-complete'. You could try carefully! deleting this to start over, or just the bits that you know are not useful. But make sure that you close the project (or use a different editor) before you amend this file.

Of course, it's possible to remove items, or move them further down, within the completions file - but I would always treat this as a last resort.

Let me know, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 2:50 pm

Actually, this has resolved a problem I was having when trying to replace text :D (it was replacing it with a chunk of text from a previous file).

I closed my Project, and open the workspace file that's in my project folder. I delete all of the auto-complete history (leaving just [ ] ) and did the same for the replace history.
Then I closed ST and re-started - Great!

There are other things that can be deleted (carefully) in the workspace file, such as file_history items, which can fix and speed-up things, whe'hay.

Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 5:50 pm

Sorry to be a pain, but I noticed a small error with 'parse()' and 'UTC()' and have corrected this in the attached. I'm fairly confident that there aren't too many such errors :o, but let me know pl.

I've managed to make a start with GitHub, but I haven't fully sussed it yet. I'll post the link when I've defeated it!

Andy.
Attachments
AndyJS3.zip
Correct parse and UTC
(10.1 KiB) Downloaded 117 times
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 6:03 pm

Managed to upload the corrected version, whe'hay:

https://github.com/agibsonsw/AndySublime
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Fri Feb 03, 2012 8:22 pm

Hello again.

I thought everything was going to well, and I've discovered and issue that needs to be raised. My expression
${TM_CURRENT_LINE/.+\\.$|(.*)/(?1:document\\.)/}

works well, in that:
alink
becomes
document.alinkColor
and
myDocu.alink
becomes
myDocu.alinkColor

That's fine, but if anything at all occurs after the text that you're typing it will always put in 'document' :o. So if you are typing within brackets ( ) then we have an issue. To get around it for the moment we can just type 'alink' and let 'document' be added, or type what we need directly.

I'll need to work on my regex so that it only reads upto the current cursor position. It shouldn't be too tricky, but it might take me a little while. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Sat Feb 04, 2012 12:02 am

Well that was hard work :shock: but I've finally got the expression I need:

Code: Select all
${TM_CURRENT_WORD/\.\W*|(.*)/(?1:document\.)/}testThis


I'll need to test it a bit more and then I'll update my file tomorrow.

Basically, it means that typing 'something.testt' should become 'something.testThis', not matter where you type it; that is, even if nested deeply within a statement or brackets. The only time it will (should!) become 'document.testThis' is if you type 'testt' without an initial dot.

Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Sat Feb 04, 2012 5:14 am

Attached is the corrected version 3. I'll update GitHub to reflect this tomorrow.

Andy.
Attachments
AndyJS3.zip
Corrected version 3
(10.11 KiB) Downloaded 119 times
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: JavaScript completions

Postby agibsonsw on Sat Feb 04, 2012 12:35 pm

My github is now updated with the latest version. Andy.

https://github.com/agibsonsw/AndySublime
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Google [Bot] and 7 guests