TemplateCompletion Clarifications

Questions on using RSyntaxTextArea should go here.

Moderator: robert

TemplateCompletion Clarifications

Postby Guest » Fri Aug 03, 2012 3:23 pm

I have added TemplateCompletions to KojoLite with pretty good success. The only areas I am having issues are:

(1) Templates with multiple parameters.
Kojo has an arc command. The template for this is:
arc(${radius}, ${angle})

So I type in 'a', hit Ctrl+Space, see arc in the completion drop down, select it, and hit Enter. The template shows great, with boxes around the radius and angle slots. The cursor is on the radius slot. I type in a number - and this goes into the radius slot. But now the angle slot loses its box. I can't tab into it to enter a number for the angle parameter.

Is this an issue with multiple parameter templates?

(2) Templates with no parameters
I have certain templates with no parameters, e.g:
animate {
${cursor}
}

These currently don't work for me, (I think) because I have not specified the correct paramterListStart and paramterListEnd strings for my TemplateCompletions. What I did instead was to comment out the block of code that handles the zero parameter case (AutoComplete.java, line 991)
// if (pc.getParamCount()==0) {

Now things work great, except that I have to hit enter (or tab) once to get to the cursor slot. Is there any way that I can have the cursor show up in the right place without having to hit enter/tab?

Also, what would it take to relax the check above (AutoComplete.java, line 991), for official inclusion in AutoComplete, to do something like:
if (param count is zero and not (pc is a template completion and pc has a ${cursor} piece))

Note - all my zero parameter templates have a ${cursor}, as I suspect most zero parameter templates will.

PS. If needed, I can (a) check in my current (Scala) code that does code-completion and send out a link to the source within the KojoLite project on googlecode, and (b) upload the compiled code to the KojoLite Webstart app so that its available 'live' to play with.

Thanks,
- Lalit
::
Lalit Pant
Creator and Lead Dev,
The Kojo Project (http://www.kogics.net/kojo)
Guest
 

Re: TemplateCompletion Clarifications

Postby Guest » Fri Aug 03, 2012 6:25 pm

Also, what would it take to relax the check above (AutoComplete.java, line 991), for official inclusion in AutoComplete, to do something like:
if (param count is zero and not (pc is a template completion and pc has a ${cursor} piece))


Just to clarify, I did not mean that in a literal sense. In actual terms, this could be something like:

java code:

if (pc.needsTooltip()) {
// AutoComplete.java, line 992 onwards here
}


where needsTooltip is a new method in ParameterizedCompletion, and TemplateCompletion provides an appropriate implementation that accounts for the case where there are zero parameters, but there's a ${cursor}.

Thanks,
- Lalit
Guest
 

Re: TemplateCompletion Clarifications

Postby Guest » Sat Aug 04, 2012 4:03 pm

Quick update:

You can see code completion working (pretty well) within KojoLite by Webstarting it from this page:
http://www.kogics.net/kojolite

You can also see the couple of issues I mentioned...

Thanks,
- Lalit
Guest
 

Re: TemplateCompletion Clarifications

Postby robert » Mon Aug 06, 2012 3:32 am

(1) Templates with multiple parameters.


I can't reproduce this one. Do you see the same behavior with the AutoCompletionDemo project? I tried selecting 2-arg functions such as difftime and had no trouble tabbing through parameters.

(2) Templates with no parameters


Good find; this is probably just a scenario I hadn't really tested. I'll look into it and probably end up doing something like you suggest.

BTW, I tried the demo just now and got this stack trace:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at com.sun.deploy.security.CPCallbackHandler.isAuthenticated(Unknown Source)
   at com.sun.deploy.security.CPCallbackHandler.access$1300(Unknown Source)
   at com.sun.deploy.security.CPCallbackHandler$ChildElement.checkResource(Unknown Source)
   at com.sun.deploy.security.DeployURLClassPath$JarLoader.checkResource(Unknown Source)
   at com.sun.deploy.security.DeployURLClassPath$JarLoader.getResource(Unknown Source)
   at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at bibliothek.gui.dock.control.focus.DefaultMouseFocusObserver.check(DefaultMouseFocusObserver.java:249)
   at bibliothek.gui.dock.control.focus.DefaultMouseFocusObserver.check(DefaultMouseFocusObserver.java:171)
   at bibliothek.gui.dock.control.focus.DefaultMouseFocusObserver.check(DefaultMouseFocusObserver.java:136)
   at bibliothek.gui.dock.control.focus.DefaultMouseFocusObserver$GlobalMouseListener.mousePressed(DefaultMouseFocusObserver.java:330)
   at bibliothek.gui.dock.control.DefaultGlobalMouseDispatcher.dispatch(DefaultGlobalMouseDispatcher.java:111)
   at bibliothek.gui.dock.control.DefaultGlobalMouseDispatcher$3.eventDispatched(DefaultGlobalMouseDispatcher.java:232)
   at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Unknown Source)
   ...
User avatar
robert
 
Posts: 805
Joined: Sat May 10, 2008 5:16 pm

Re: TemplateCompletion Clarifications

Postby Guest » Mon Aug 06, 2012 2:29 pm

Hi Robert,

BTW, I tried the demo just now and got this stack trace:


Whoa, that's not good!

On digging further - I think you might have hit this webstart bug:
http://bugs.sun.com/view_bug.do?bug_id=6967414

Just try loading the app again. It should most likely work (I have not run into this one in the many times I have run the app).
In the meantime I'll dig into the workaround that is mentioned in the comments on the bug page above.

I can't reproduce this one. Do you see the same behavior with the AutoCompletionDemo project?


I will try the AutoCompletionDemo project and let you know.
In the meantime, here's something interesting. The issue shows up only on the first line of a script. If I do the completion on the second line of a script, things work fine.

So, fire up KojoLite (I'm betting it's gonna work for you on the second try): http://www.kogics.net/runkojolite
Then type in 'ar' in the Script Editor and hit Ctrl+Space.
Then try to cycle through the two parameters of the arc command. It won't work.
Now add an empty line at the beginng of the Script Editor.
Type in 'ar' again (on the second line in the script), and try the test again. Things work just fine!

Thanks,
- Lalit
Guest
 

Re: TemplateCompletion Clarifications

Postby Guest » Tue Aug 07, 2012 2:23 am

I can't reproduce this one. Do you see the same behavior with the AutoCompletionDemo project?


I do not see the problem with the AutoComplete demo.

To try to get to the bottom of this, I have cooked up a small little Scala program that shows the problem.

Steps to reproduce problem:
  • Copy the program below into the KojoLite Script Editor and click on the Run button (or run the program within your favourite dev environment). (Btw, I fixed the webstart startup issue with KojoLite, so you should not see that startup exception again).
  • Type in 'ar' in the text area and hit Ctrl+Space.
  • Try to cycle through the two parameters of the arc command. It won't work.
  • Add an empty line at the beginng of the text area.
  • Type in 'ar' again (on the second line in the script), and try the test again. Things work just fine!


scala code:

import java.awt._
import javax.swing._
import javax.swing.text._
import org.fife.ui.rsyntaxtextarea._
import org.fife.ui.autocomplete._
import org.fife.ui.rtextarea._

class TestCompletionProvider extends CompletionProviderBase {
override def getCompletionsImpl(comp: JTextComponent) = {
val proposals = new java.util.ArrayList[Completion]
proposals.add(
new TemplateCompletion(this, "arc", "arc", "arc(${radius}, ${angle})")
)
proposals
}

override def getParameterizedCompletions(comp: JTextComponent) = throw new UnsupportedOperationException
override def getCompletionsAt(comp: JTextComponent, pt: Point) = throw new UnsupportedOperationException
override def getAlreadyEnteredText(comp: JTextComponent) = {
"ar"
}
}

val frame = new JFrame
val se = new JPanel
val codePane = new RSyntaxTextArea(20, 80)

codePane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SCALA)
codePane.setAntiAliasingEnabled(true)

val provider = new TestCompletionProvider
val ac = new AutoCompletion(provider)
ac.setParameterAssistanceEnabled(true)
ac.setAutoActivationEnabled(true)
ac.setShowDescWindow(true)
ac.install(codePane)

val sp = new RTextScrollPane(codePane)
se.setLayout(new BorderLayout)
se.add(sp, BorderLayout.CENTER)

frame.getContentPane.add(se)
frame.setBounds(100, 100, 500, 400)
frame.pack()
frame.setVisible(true)
Guest
 

Re: TemplateCompletion Clarifications

Postby Guest » Tue Aug 07, 2012 5:19 pm

I discovered that the test program I included in my previous post did not work with KojoLite on Windows (because of a missing jar on the Scala interpreter classpath). That is fixed now...

Thanks,
- Lalit
Guest
 

Re: TemplateCompletion Clarifications

Postby robert » Sat Aug 11, 2012 4:07 pm

I believe I've fixed the issue with 0-param template completions. Can you check out the latest from Subversion and try it out?

As for the problem with completions on the first line of the editor, I'm having a hard time reproducing it outside of Kojo. I also noticed that your application hides the completion windows if I type another letter after making them visible, rather than just narrowing down the completion choices. Could the two problems be related? Do you have a DocumentListener or CaretListener registered that is doing something to confuse AutoComplete?

If you try out the latest from SVN, I've also modified the completion code a little to be more like Eclipse (an extra "param" at the end of the completion text), so it might be worth trying it out just to see if using it affects the first problem in any way.
User avatar
robert
 
Posts: 805
Joined: Sat May 10, 2008 5:16 pm

Re: TemplateCompletion Clarifications

Postby robert » Sun Aug 12, 2012 4:57 am

Okay, I finally reproduced your issue with template completions on the first line. The good news is: it's now mostly fixed! The bad news is: it's not fixed in one corner case. Expanding a template completion when the cursor is at offset 0 still does not work.

<gory-details>
This is because we get a Position from the Document and expect it to track the "last" offset we can navigate to before exiting parameter assistance mode. When the replacement is inserted at offset 0, Swing returns Positions that "track" offset 0 - but these never move around like Positions tracking offsets > 0. So the first time you hit tab (or any key), we bail.
</gory-details>

This is probably the best I can do for now. It's pretty unlikely I think for someone to insert a template completion at offset 0, and they should work everywhere else now.

I also found another minor bug while tracking down this one, so thanks for that! Hopefully I didn't break anything else while making these changes...
User avatar
robert
 
Posts: 805
Joined: Sat May 10, 2008 5:16 pm

Re: TemplateCompletion Clarifications

Postby Guest » Sun Aug 12, 2012 7:21 am

I believe I've fixed the issue with 0-param template completions. Can you check out the latest from Subversion and try it out?


Thanks!
It's almost there now ;). The one thing that's a litte suboptimal is this:
- you type in cl and hit Ctrl+Space
- clear shows up in the list of completions
- you hit Enter to select it
- clear() is inserted into the text area, and the cursor is placed right at the end (which is great)
- but now you need to hit Enter twice to move to the next line

I actually worked around this (and got the cursor to move to the end of the template) with a terrible hack (and this hack is currently live on the KojoLite page/site). Here's a diff of the changes I have made so far:

Code: Select all
Index: src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
===================================================================
--- src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java   (revision 604)
+++ src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java   (working copy)
@@ -1113,15 +1113,18 @@
             // Listen for document events AFTER we insert
             tc.getDocument().addDocumentListener(this);
 
+            // Add listeners to the text component, AFTER text insertion.
+            tc.addCaretListener(this);
+            tc.addFocusListener(this);
+            installKeyBindings();
+
+            if (info.noParamsCursor) {
+               new GotoEndAction().actionPerformed(null);
+            }
+            
          } catch (BadLocationException ble) {
             ble.printStackTrace(); // Never happens
          }
-
-         // Add listeners to the text component, AFTER text insertion.
-         tc.addCaretListener(this);
-         tc.addFocusListener(this);
-         installKeyBindings();
-
       }
 
 
Index: src/org/fife/ui/autocomplete/ParameterizedCompletionInsertionInfo.java
===================================================================
--- src/org/fife/ui/autocomplete/ParameterizedCompletionInsertionInfo.java   (revision 604)
+++ src/org/fife/ui/autocomplete/ParameterizedCompletionInsertionInfo.java   (working copy)
@@ -33,8 +33,8 @@
    private String textToInsert;
    private List replacementLocations;
    private List replacementCopies;
+   boolean noParamsCursor;
 
-
    public ParameterizedCompletionInsertionInfo() {
       defaultEnd = -1;
    }
Index: src/org/fife/ui/autocomplete/AutoCompletion.java
===================================================================
--- src/org/fife/ui/autocomplete/AutoCompletion.java   (revision 604)
+++ src/org/fife/ui/autocomplete/AutoCompletion.java   (working copy)
@@ -988,16 +988,16 @@
       hideParameterCompletionPopups();
 
       // Don't bother with a tooltip if there are no parameters.
-      if (pc.getParamCount()==0) {
-         CompletionProvider p = pc.getProvider();
-         char end = p.getParameterListEnd(); // Might be '\0'
-         String text = end=='\0' ? "" : Character.toString(end);
-         if (addParamListStart) {
-            text = p.getParameterListStart() + text;
-         }
-         textComponent.replaceSelection(text);
-         return;
-      }
+//      if (pc.getParamCount()==0) {
+//         CompletionProvider p = pc.getProvider();
+//         char end = p.getParameterListEnd(); // Might be '\0'
+//         String text = end=='\0' ? "" : Character.toString(end);
+//         if (addParamListStart) {
+//            text = p.getParameterListStart() + text;
+//         }
+//         textComponent.replaceSelection(text);
+//         return;
+//      }
 
       pcc = new ParameterizedCompletionContext(parentWindow, this, pc);
       pcc.activate(addParamListStart);
Index: src/org/fife/ui/autocomplete/TemplateCompletion.java
===================================================================
--- src/org/fife/ui/autocomplete/TemplateCompletion.java   (revision 604)
+++ src/org/fife/ui/autocomplete/TemplateCompletion.java   (working copy)
@@ -187,6 +187,7 @@
          leadingWS = "";
       }
 
+      boolean hasCursor = false;
       // Create the text to insert (keep it one completion for
       // performance and simplicity of undo/redo).
       int start = dot;
@@ -198,6 +199,7 @@
                start = possiblyReplaceTabsWithSpaces(sb, tc, start);
             }
             defaultEndOffs = start;
+            hasCursor = true;
          }
          else {
             int end = start + text.length();
@@ -217,6 +219,10 @@
          }
       }
 
+      if (params.size() == 0 && hasCursor) {
+         info.noParamsCursor = true;
+      }
+      
       info.setInitialSelection(selStart, selEnd);
       if (defaultEndOffs>-1) {
          // Keep this location "after" all others when tabbing


Hopefully there's a nice clean way for you to take away the need for two Enters to move to the next line?

Thanks!!
- Lalit

PS. The more I work with RSTA/Autocomplete, the more I'm glad that I stumbled upon your project. Great work!
After some digging around inside RSTA/Autocomplete, I'm confident that the KojoLite Script Editor will soon have all the bells and whistles of the Kojo Script Editor (which gets these things from the Netbeans Platform).
Guest
 

Next

Return to Help

Who is online

Users browsing this forum: No registered users and 7 guests

cron