cvs -q diff -u -N editor java html web Index: editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateCompletionItem.java =================================================================== RCS file: /cvs/editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateCompletionItem.java,v retrieving revision 1.10 diff -u -r1.10 CodeTemplateCompletionItem.java --- editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateCompletionItem.java 26 Oct 2005 15:21:47 -0000 1.10 +++ editor/codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateCompletionItem.java 8 Nov 2005 13:58:21 -0000 @@ -176,6 +176,15 @@ return ""; } + public CharSequence getInsertPrefix() { + String insertPrefix = codeTemplate.getParametrizedText(); + int dollarIndex = insertPrefix.indexOf("${"); + if (dollarIndex >= 0) { + insertPrefix = insertPrefix.substring(0, dollarIndex); + } + return insertPrefix; + } + private static final class DocQuery extends AsyncCompletionQuery { private CodeTemplate codeTemplate; Index: editor/completion/apichanges.xml =================================================================== RCS file: /cvs/editor/completion/apichanges.xml,v retrieving revision 1.1 diff -u -r1.1 apichanges.xml --- editor/completion/apichanges.xml 6 Sep 2005 13:54:58 -0000 1.1 +++ editor/completion/apichanges.xml 8 Nov 2005 13:58:21 -0000 @@ -91,6 +91,29 @@ + + + + Editor Code Completion API created + + + + + +

+ CompletionTask.refresh(CompletionResultSet resultSet) now allows + null parameter. +
+ void AsyncCompletionQuery.preQueryUpdate(JTextComponent component) + was added. +
+ void CompletionResultSet.setWaitText(String waitText) was added. +
+ CharSequence CompletionItem.getInsertPrefix() was added. +

+
+ +
Index: editor/completion/manifest.mf =================================================================== RCS file: /cvs/editor/completion/manifest.mf,v retrieving revision 1.3 diff -u -r1.3 manifest.mf --- editor/completion/manifest.mf 24 Sep 2005 00:37:05 -0000 1.3 +++ editor/completion/manifest.mf 8 Nov 2005 13:58:21 -0000 @@ -2,4 +2,4 @@ OpenIDE-Module: org.netbeans.modules.editor.completion/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/completion/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/editor/completion/CompletionModule.class -OpenIDE-Module-Specification-Version: 1.2 +OpenIDE-Module-Specification-Version: 1.3 Index: editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java,v retrieving revision 1.25 diff -u -r1.25 CompletionImpl.java --- editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java 8 Nov 2005 13:10:26 -0000 1.25 +++ editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java 8 Nov 2005 13:58:21 -0000 @@ -148,7 +148,8 @@ Registry.addChangeListener(this); completionAutoPopupTimer = new Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { - showCompletion(); + queryResultSets(completionResult.getResultSets()); + completionResult.queryInvoked(); } }); completionAutoPopupTimer.setRepeats(false); @@ -207,7 +208,7 @@ } if (completionResultNull && (type & CompletionProvider.COMPLETION_QUERY_TYPE) != 0 && CompletionSettings.INSTANCE.completionAutoPopup()) { - restartCompletionAutoPopupTimer(); + showCompletion(false, true); } boolean tooltipResultNull; @@ -448,7 +449,7 @@ } } - void completionQuery() { + void completionQuery(boolean delayQuery) { pleaseWaitTimer.restart(); refreshedQuery = false; @@ -471,8 +472,12 @@ } // Query the tasks - queryResultSets(completionResultSets); - newCompletionResult.queryInvoked(); + if (delayQuery) { + restartCompletionAutoPopupTimer(); + } else { + queryResultSets(completionResultSets); + newCompletionResult.queryInvoked(); + } } /** @@ -510,10 +515,10 @@ * May be called from any thread but it will be rescheduled into AWT. */ public void showCompletion() { - showCompletion(false); + showCompletion(false, false); } - private void showCompletion(boolean explicitQuery) { + private void showCompletion(boolean explicitQuery, boolean delayQuery) { if (!SwingUtilities.isEventDispatchThread()) { // Re-call this method in AWT if necessary SwingUtilities.invokeLater(new ParamRunnable(ParamRunnable.SHOW_COMPLETION)); @@ -523,7 +528,7 @@ this.explicitQuery = explicitQuery; if (activeProviders != null) { completionCancel(); // cancel possibly pending query - completionQuery(); + completionQuery(delayQuery); } } @@ -1042,7 +1047,7 @@ private final class CompletionShowAction extends AbstractAction { public void actionPerformed(ActionEvent e) { - showCompletion(true); + showCompletion(true, false); } } @@ -1125,11 +1130,11 @@ } } - private static void refreshResultSets(List resultSets) { + private static void refreshResultSets(List resultSets, boolean beforeQuery) { int size = resultSets.size(); for (int i = 0; i < size; i++) { CompletionResultSetImpl result = (CompletionResultSetImpl)resultSets.get(i); - result.getTask().refresh(result.getResultSet()); + result.getTask().refresh(beforeQuery ? null : result.getResultSet()); } } @@ -1171,9 +1176,9 @@ private final List/**/ resultSets; - private boolean invoked; - + private boolean invoked; private boolean cancelled; + private boolean beforeQuery = true; Result(int resultSetsSize) { resultSets = new ArrayList(resultSetsSize); @@ -1221,6 +1226,7 @@ assert (!invoked); invoked = true; canc = cancelled; + beforeQuery = false; } if (canc) { cancelResultSets(resultSets); @@ -1237,10 +1243,14 @@ if (cancelled) { return null; } + if (beforeQuery) { + return this; + } assert (invoked); // had to be invoked invoked = false; } Result refreshResult = new Result(getResultSets().size()); + refreshResult.beforeQuery = beforeQuery; createRefreshResultSets(resultSets, refreshResult); return refreshResult; } @@ -1251,8 +1261,9 @@ * {@link #createRefreshResult()}. */ void invokeRefresh() { - refreshResultSets(getResultSets()); - queryInvoked(); + refreshResultSets(getResultSets(), beforeQuery); + if (!beforeQuery) + queryInvoked(); } } Index: editor/completion/src/org/netbeans/modules/editor/completion/CompletionResultSetImpl.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/modules/editor/completion/CompletionResultSetImpl.java,v retrieving revision 1.4 diff -u -r1.4 CompletionResultSetImpl.java --- editor/completion/src/org/netbeans/modules/editor/completion/CompletionResultSetImpl.java 15 Sep 2005 09:30:16 -0000 1.4 +++ editor/completion/src/org/netbeans/modules/editor/completion/CompletionResultSetImpl.java 8 Nov 2005 13:58:21 -0000 @@ -235,4 +235,8 @@ } } + public void setWaitText(String waitText) { + throw new UnsupportedOperationException("Not yet implemented"); + } + } Index: editor/completion/src/org/netbeans/spi/editor/completion/CompletionItem.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/CompletionItem.java,v retrieving revision 1.3 diff -u -r1.3 CompletionItem.java --- editor/completion/src/org/netbeans/spi/editor/completion/CompletionItem.java 11 Aug 2005 20:43:34 -0000 1.3 +++ editor/completion/src/org/netbeans/spi/editor/completion/CompletionItem.java 8 Nov 2005 13:58:22 -0000 @@ -120,6 +120,31 @@ /** * Returns a text used to sort items alphabetically. */ - CharSequence getSortText(); + CharSequence getSortText(); + + /** + * Returns a text used for finding of a longest common prefix + * after the TAB gets pressed or when the completion is opened explicitly. + *
+ * The completion infrastructure will evaluate the insert prefixes + * of all the items present in the visible result and finds the longest + * common prefix. + * + *

+ * Generally the returned text does not need to contain all the information + * that gets inserted when the item is selected. + *
+ * For example in java completion the field name should be returned for fields + * or a method name for methods (but not parameters) + * or a non-FQN name for classes. + * + * @return non-null character sequence containing the insert prefix. + *
+ * Returning an empty string will effectively disable the TAB completion + * as the longest common prefix will be empty. + * + * @since 1.3 + */ + CharSequence getInsertPrefix(); } Index: editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java,v retrieving revision 1.3 diff -u -r1.3 CompletionResultSet.java --- editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java 21 Jun 2005 15:37:29 -0000 1.3 +++ editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java 8 Nov 2005 13:58:22 -0000 @@ -202,6 +202,20 @@ public int getSortType() { return impl.getSortType(); } + + /** + * Set the explicit value displayed in a label when the completion results + * do not get computed during a certain timeout (e.g. 250ms). + *
+ * If not set explicitly the completion infrastructure will use + * the default "Please wait..." text. + * + * @param waitText non-null + * @since 1.3 + */ + public void setWaitText(String waitText) { + impl.setWaitText(waitText); + } private static final class SpiAccessor extends CompletionSpiPackageAccessor { Index: editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java,v retrieving revision 1.4 diff -u -r1.4 CompletionTask.java --- editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java 15 Sep 2005 09:30:17 -0000 1.4 +++ editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java 8 Nov 2005 13:58:22 -0000 @@ -52,8 +52,14 @@ *
* This method can be called multiple times on a single task instance. *
+ * Typically it is called AFTER the query() was invoked + * but it may also be invoked BEFORE the query() in case + * the user types even before the query() + * was called by the infrastructure. In such + * case the resultSet parameter will be null. + *
* It is guaranteed that this method will not be invoked in case - * the document of the component would change since the last invocation + * the document instance set in the component would change since the last invocation * of either the query() or refresh(). * *

@@ -63,6 +69,11 @@ * * @param resultSet non-null result set to which the results * of the refreshing must be added. + *
+ * Null result set may be passed in case the query() + * was not invoked yet and user has typed a character. In this case + * the provider may hide the completion if the character is inappropriate + * e.g. ";" for java completion. */ public void refresh(CompletionResultSet resultSet); Index: editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java,v retrieving revision 1.3 diff -u -r1.3 AsyncCompletionQuery.java --- editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java 21 Jun 2005 15:37:29 -0000 1.3 +++ editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java 8 Nov 2005 13:58:22 -0000 @@ -34,6 +34,22 @@ public abstract class AsyncCompletionQuery { private AsyncCompletionTask task; + + /** + * Called in response to CompletionTask.refresh(null). + *
+ * The method gets invoked once the the user types a character + * but the CompletionTask.query() was not yet invoked. + *
+ * The method may want to inspect the typed character before the caret + * position and decide whether the completion should be hidden + * if the typed character is inappropriate e.g. ";" for java completion. + * + * @since 1.3 + */ + protected void preQueryUpdate(JTextComponent component) { + // Always done in AWT thread - by default do nothing + } /** * Perform the query and add results to the given result set. Index: editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java =================================================================== RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java,v retrieving revision 1.3 diff -u -r1.3 AsyncCompletionTask.java --- editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java 21 Jun 2005 15:37:29 -0000 1.3 +++ editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java 8 Nov 2005 13:58:22 -0000 @@ -51,6 +51,9 @@ /** Whether this task is cancelled. */ private boolean cancelled; + + /** Whether query was already invoked on this task. */ + private boolean queryInvoked; /** * Construct asynchronous task for the given component. @@ -89,6 +92,7 @@ } else { doc = null; } + queryInvoked = true; synchronized (this) { performQuery(resultSet); @@ -103,11 +107,15 @@ * The results should be fired into the newly provided completion listener. */ public void refresh(CompletionResultSet resultSet) { - assert (resultSet != null); assert (SwingUtilities.isEventDispatchThread()); assert !cancelled : "refresh() called on canceled task"; // NOI18N - refreshResultSet = resultSet; - refreshImpl(); + if (queryInvoked) { + assert (resultSet != null); + refreshResultSet = resultSet; + refreshImpl(); + } else { + query.preQueryUpdate(component); + } } /** Index: java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java =================================================================== RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java,v retrieving revision 1.6 diff -u -r1.6 ElementCreatingCompletionProvider.java --- java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java 7 Nov 2005 16:05:55 -0000 1.6 +++ java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java 8 Nov 2005 13:58:24 -0000 @@ -350,6 +350,10 @@ return 300; } + public CharSequence getInsertPrefix() { + return getItemText(); + } + public void create(int offset) { BaseDocument bdoc = (BaseDocument) document; Position position = null; @@ -615,6 +619,11 @@ public int getSortPriority() { return isImplement ? 0 : 500; } + + public CharSequence getInsertPrefix() { + return getItemText(); + } + } private static class NbOverrideMethodPaintComponent extends NbJMIPaintComponent.NbMethodPaintComponent { Index: java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java =================================================================== RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java,v retrieving revision 1.12 diff -u -r1.12 JavaCompletionProvider.java --- java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java 4 Nov 2005 21:48:59 -0000 1.12 +++ java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java 8 Nov 2005 13:58:24 -0000 @@ -58,7 +58,7 @@ public CompletionTask createTask(int queryType, JTextComponent component) { if (queryType == COMPLETION_QUERY_TYPE) - return new AsyncCompletionTask(new Query(), component); + return new AsyncCompletionTask(new Query(component.getCaret().getDot()), component); else if (queryType == DOCUMENTATION_QUERY_TYPE) return new AsyncCompletionTask(new DocQuery(null), component); else if (queryType == TOOLTIP_QUERY_TYPE) @@ -72,11 +72,29 @@ private NbJavaJMICompletionQuery.JavaResult queryResult; + private int creationCaretOffset; private int queryCaretOffset; private int queryAnchorOffset; private String filterPrefix; + + Query(int caretOffset) { + this.creationCaretOffset = caretOffset; + } + + protected void preQueryUpdate(JTextComponent component) { + int caretOffset = component.getCaretPosition(); + Document doc = component.getDocument(); + if (caretOffset >= creationCaretOffset) { + try { + if (isJavaIdentifierPart(doc.getText(creationCaretOffset, caretOffset - creationCaretOffset))) + return; + } catch (BadLocationException e) { + } + } + Completion.get().hideCompletion(); + } protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) { NbJavaJMICompletionQuery query = new NbJavaJMICompletionQuery(true); Index: java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java =================================================================== RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java,v retrieving revision 1.34 diff -u -r1.34 NbJMIResultItem.java --- java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java 4 Nov 2005 22:15:54 -0000 1.34 +++ java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java 8 Nov 2005 13:58:26 -0000 @@ -176,6 +176,10 @@ public CharSequence getSortText() { return getItemText(); } + + public CharSequence getInsertPrefix() { + return getItemText(); + } public CompletionTask createDocumentationTask() { return new AsyncCompletionTask(new JavaCompletionProvider.DocQuery(this), Index: html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java =================================================================== RCS file: /cvs/html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java,v retrieving revision 1.23 diff -u -r1.23 HTMLCompletionQuery.java --- html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java 1 Nov 2005 09:54:04 -0000 1.23 +++ html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java 8 Nov 2005 13:58:31 -0000 @@ -457,6 +457,10 @@ return HTMLResultItem.this.getItemText(); } + public CharSequence getInsertPrefix() { + return getItemText(); + } + public Component getPaintComponent(boolean isSelected) { //TODO: the paint component should be caches somehow HTMLCompletionResultItemPaintComponent component = new HTMLCompletionResultItemPaintComponent.StringPaintComponent(getPaintColor()); Index: web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java =================================================================== RCS file: /cvs/web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java,v retrieving revision 1.9 diff -u -r1.9 JspCompletionItem.java --- web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java 4 Nov 2005 14:51:34 -0000 1.9 +++ web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java 8 Nov 2005 13:58:35 -0000 @@ -76,6 +76,10 @@ return DEFAULT_SORT_PRIORITY; } + public CharSequence getInsertPrefix() { + return getItemText(); + } + public Component getPaintComponent(boolean isSelected) { if (component == null) { component = new ResultItemPaintComponent.StringPaintComponent();