Code Completion Goodie

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Code Completion Goodie

Postby jtuchel » Wed Apr 06, 2011 12:38 am

Hi,

TC just uploaded a code completion goodie to VASTGoodies.com - and it works really nicely.
I am surprised by how fast it comes up with suggestions and how fast it updates when I continue typing

Here's what I've found after playing with it for a hand full of minutes:

If I type and want to accept the top-most suggestion, pressing Enter does not always accept it. If I press BtnDown and press Enter, the second one is copied to the edit pane. If I press BtnDown and BtnUp, I can press enter to accept the first suggestion. But it seems I cannot accept the first one by default. Am I missing a key shortcut or is this a bug (I know it's alpha, so speaking of a bug is probably mean)?

So far it has problems with multiple keywords like perform:withArguments: once you've entered the first colon. It will make suggestions for the second keyword independently of the first one, meaning that when I type the letter w after the colon, I will get suggestions for all methods starting with w not perform:w*

Is there any sort order other than alphabetical for the suggestions? It seems to me that the list is just alphabetical. I am not sure if we can

Is there anything keeping us from changing the minimum of typed characters before it pops up to two or three? This thing is fast enough in my opinion. Maybe it could even start after the first character in case of operators like >=& etc...

I haven't looked into the code, so it is probably a dumb question with an obvious answer: is this thing portable?

I'd personally like its background color to be different from the color of the edit pane, but this is just a question of taste and has nothing to do with the functionality

An idea for enhancements: Do others think a hint as to what classes implement a method in the list of suggestions add to the usefulness of a code completer? I could imagine it helps, but am not sure. I am also not sure what a good way of presenting that info could be.

Another possible improvement on top of this: in Eclipse etc., there is some assistance with filling out the gaps for parameters, meaning once you accept a suggestion, the cursor will jump to the first parameter, and you can fill it in. Pressing Tab will jump to the next parameter etc. I guess it is way to early to ask for this, and it's probably on your own list anyways.

I want to repeat that I like this goodie very much.
It makes life much easier even in its early stage, so don't take my fedback as criticism. Thanks for sharing it this early!


Joachim
Last edited by jtuchel on Thu Apr 07, 2011 3:01 am, edited 1 time in total.
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany

Re: Code Completion Goodie

Postby tc » Wed Apr 06, 2011 3:40 am

Hello,

If I type and want to accept the top-most suggestion, pressing Enter does not always accept it.

I've been using it for over a month to develop but have never had that issue. I tried again now but I'm unable to reproduce it. Which version of ST are you using and what features are loaded? Also, can you try it with an out of the box image and see if the problem still occurs?

it has problems with multiple keywords like perform:withArguments: once you've entered the first colon. It will make suggestions for the second keyword independently of the first one

I can reproduce that and will look at it.

is this thing portable?

It uses low level window functionality/APIs. Look at the method 'createWorkRegion' for any of the tabbed browsers. In the last two lines or so, you can see where it is hooked up.

An idea for enhancements

I'll keep a list.

Thanks for the complements :D .

I'd like to track down the unreproducible error. I'd be interested if anyone else has the same issue and what features are loaded.

Also, the browsers are alpha because the biggest issue is widgets inside a tab control have no attachments. Attachments can be set but they have no effect. That means a resize event has to be called to keep them the right size. I found one issue already but please report any issues where a widget resizes, i.e. gets smaller.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Code Completion Goodie

Postby tc » Wed Apr 06, 2011 4:43 am

Hello,

it has problems with multiple keywords like perform:withArguments: once you've entered the first colon. It will make suggestions for the second keyword independently of the first one

I uploaded a new version to http://www.VASTGoodies.com which fixes the colon problem.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Code Completion Goodie

Postby jtuchel » Wed Apr 06, 2011 5:03 am

Hi TC,

I guess you can forget about the defaut selection bug I reported before. I've used the goodie for several hours now and haven't seen it any more. Maybe I was at the end of a keyword without noticing and an expected (but unnecessary) change to the keyword didn't show up. I will pop up a new post if I see it again.

Thanks for looking into it and taking care of the multi-keyword bug. I'll look at the new version later.

I somehow wanted to type something about the sorting of suggestions but had another idea that I wanted to type first and never got back to finishing my sentence. So what was I about to write in the incomplete sentence...?

I wanted to come up with the idea that maybe messages that are implemented within the hierarchy of the currently edited class should have preference before unrelated classes. But then there are other possibilities like trying to guess what the user is sending messages to in the same method and other terribly clever things. So maybe the sentence was unfinished by design of some higher-level being that took control of my thoughts in that moment. There surely is a lot of stuff that can be done to make the selection or sorting of suggestions even better, but that's something where the chance of failure is high anyways ;-)

Joachim
Last edited by jtuchel on Thu Apr 07, 2011 3:00 am, edited 1 time in total.
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany

Re: Code Completion Goodie

Postby marten » Wed Apr 06, 2011 7:44 am

jtuchel wrote:Hi,
TC just uploaded a code completion goodie to VASTGoodies.com - and it works really nicely.


Just a wish. When the event is triggered StsCodeAssist>>processKeySymbol: is executed. Would it be possible to extend the method in a way like:

Code: Select all
processKeySymbol: keySymbol

...
(str := self textEdit stsWordUnderCursor) size > self wordSize
  ifTrue: [
    | codeAssistInfo |
     codeAssistInfo :=  CodeAssistInfo new.
     codeAssistInfo
        wordUnderCursor: str ;
        cursorPosition: ... ;
        parseTree: (self textEdit parseTree) ;
        ... .
     self  displayListOfChoices: codeAssistInfo ]
...


where CodeAssistInfo is an instance of a class just to hold additional information for the mechanism finding the hits to show - and the mechanism in StsCodeAssist should be pluggable. Then this might be very powerful and extendable ...
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Code Completion Goodie

Postby jtuchel » Thu Apr 07, 2011 3:00 am

Hi

I just wanted to say that the new version now works fine for multi-keyword messages.

And of course add that Marten's idea is excellent because it opens lots of possibilities for improvements and extensions.

Joachim
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany

Re: Code Completion Goodie

Postby tc » Thu Apr 07, 2011 3:33 am

Hello,

I just wanted to say that the new version now works fine for multi-keyword messages.

Thanks. :D

I like Marten's idea also. What about having two class side variables, one is for background color, and the other is a block that code completion uses to generate choices. Passed into the block would be the method text, current position into the text, and I was thinking the current class. However the code completion object only knows about the text pane. I could change it if you (a collective you) feel that change would fill the bill?

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Code Completion Goodie

Postby marten » Thu Apr 07, 2011 3:47 am

The idea behind my wish is, that - at that position I showed - one has access to the source code of that message, the position of that cursor and one has access to the parseTree of that message and the class and application the method is located in. I think, that is pretty much enough to open any algorithm a better way ...

My first attempt to make it was as you mentioned it: look for the parameter and write the code specific to the numbers of parameters, but then I decided to use an instance of a class - which can be extended later on.

* the application gives you - through the prerequisites - the area of code you have to search in for method names
* the class gives you more information, what the receiver of self can be
* the parse tree can give you additional information about the usage of a variable name (may take time to generate on large methods)
* the method text is always needed
* the cursor position is always needed
* the text under cursor is a convenient data
* the compiled method (of the up to now active method) would be nice - if it is available



tc wrote:
I like Marten's idea also. What about having two class side variables, one is for background color, and the other is a block that code completion uses to generate choices. Passed into the block would be the method text, current position into the text, and I was thinking the current class. However the code completion object only knows about the text pane. I could change it if you (a collective you) feel that change would fill the bill?

--tc
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Code Completion Goodie

Postby tc » Thu Apr 07, 2011 4:47 am

Hello,

I decided to use an instance of a class - which can be extended later on

I see :idea: .

I like that approach.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Code Completion Goodie

Postby TriSebastian » Thu Apr 07, 2011 6:14 am

Hi tc,

great job! I like it! It works like a charm on VAST 8.0.3.

I'm not yet sure if I like the default "Object"-parameter. Maybe a single character param would save some keypresses, or mouse interaction....

Could it be that this alpha version doesn't run unter VAST 8.0.2?
I wnated to provide our developers with this, but I get a "doesNotUnderstand subMenu" error under VAST 8.0.2.

Thank again!
Sebastian
TriSebastian
 
Posts: 76
Joined: Sun Jul 20, 2008 9:40 pm
Location: Nanaimo, BC, Canada

Re: Code Completion Goodie

Postby jtuchel » Thu Apr 07, 2011 6:43 am

TriSebastian wrote:I'm not yet sure if I like the default "Object"-parameter. Maybe a single character param would save some keypresses, or mouse interaction....


If we have the source of the suggested method, why not fill in the name of the parameter from the method. Most of the times, this will even be a hint as to what parameter is expected - given that many people use parameter names like 'aBool' or 'shippingAddress'.

Just a thought. Again, these things are easier to add once the CodeAssistInfo is an object, so this is another argument in favor of Martens suggestion.

Joachim
jtuchel
[|]
 
Posts: 245
Joined: Fri Oct 05, 2007 1:05 am
Location: Ludwigsburg, Germany

Re: Code Completion Goodie

Postby TriSebastian » Thu Apr 07, 2011 6:57 am

Hi Joachim,

I don't think that this is a good idea.

We can ahve two cases here:

First path trough methods:

setSomething: aString

self instanceVariable setSomething: aString

Second normal method calls:

| string |

string := 'Hi Joachim'.

self setSomething: string

And there come the problem eith coding conventions. In out case method variables start with a small 'm'. I guess many VAST users have different conventions here....

Sebastian
TriSebastian
 
Posts: 76
Joined: Sun Jul 20, 2008 9:40 pm
Location: Nanaimo, BC, Canada

Re: Code Completion Goodie

Postby marten » Thu Apr 07, 2011 9:29 am

jtuchel wrote:If we have the source of the suggested method, why not fill in the name of the parameter from the method. Most of the times, this will even be a hint as to what parameter is expected - given that many people use parameter names like 'aBool' or 'shippingAddress'.


Yes, that would be nice. But we can see, that only working with simple strings is not enough here. The hints should also be capsulated within single objects - not only the method name, but also the name of the arguments should be included and perhaps (at a later time) a hint for the type of arguments .... but that is far in the future.
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Code Completion Goodie

Postby TriSebastian » Thu Apr 07, 2011 9:55 am

Hi Completers! ;-)

Can you please check hwo you ClassBrowsers behave when you open a Class/Part in the VisualOrganizer via doubleclick?

In my case the instance and class toggle button is missing since I loaded the CompletionMap.

Sebastian
TriSebastian
 
Posts: 76
Joined: Sun Jul 20, 2008 9:40 pm
Location: Nanaimo, BC, Canada

Re: Code Completion Goodie

Postby tc » Thu Apr 07, 2011 10:40 am

great job! I like it! It works like a charm on VAST 8.0.3

Thanks :D

I'm not yet sure if I like the default "Object"-parameter.

I originally did it with no params but quickly realized something should be there. I chose 'Object' because no errors show up and after a method name is inserted, I can double click to select it and fill in the real param.

Could it be that this alpha version doesn't run unter VAST 8.0.2? I wanted to provide our developers with this, but I get a "doesNotUnderstand subMenu" error under VAST 8.0.2.

Your best bet is to move things over by hand. Look at the end of 'createWorkRegion' for any of the tabbed browsers. Connect V 8.0.2 the same way and move over 'stsWordUnderCursor2'.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Next

Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest

cron