Skip to content

Commit f1710e6

Browse files
kaloyan-raevVitalii Parfonov
authored andcommitted
Performance improvements and other fixes in code completion (eclipse-che#3146)
* Avoid overloading the DOM tree of the ContentAssistWidget Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Ensure the code assist widget is closed when applying proposal Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Respect isIncomplete flag in the completion result If the isIncomplete flag is false, i.e. the completion result is complete, then additional typing for the same word should not trigger a new completion request. The latest completion result should be reused. Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Fix flickering between keystrokes during code completion Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Fine tune the rules for making new completion request Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Set the correct offset when applying code completion * Force a completion request message on Ctrl+Space Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Fixed retrieval of CompletionItem document via Resolve request Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
1 parent 1652aef commit f1710e6

20 files changed

Lines changed: 609 additions & 228 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/codeassist/CodeAssistProcessor.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
public interface CodeAssistProcessor {
2626

2727
/**
28-
* Returns a list of completion proposals based on the
29-
* specified location within the document that corresponds
30-
* to the current cursor position within the text view.
28+
* Returns a list of completion proposals based on the specified location
29+
* within the document that corresponds to the current cursor position
30+
* within the text view.
3131
*
3232
* @param editor
33-
* the editor whose document is used to compute the proposals
33+
* the editor whose document is used to compute the proposals
3434
* @param offset
35-
* an offset within the document for which completions should be computed
36-
* @return an array of completion proposals or <code>null</code> if no proposals are possible
35+
* an offset within the document for which completions should be
36+
* computed
37+
* @param triggered
38+
* if triggered by the content assist key binding
39+
*
40+
* @return an array of completion proposals or <code>null</code> if no
41+
* proposals are possible
3742
*/
38-
void computeCompletionProposals(TextEditor editor, int offset, CodeAssistCallback callback);
43+
void computeCompletionProposals(TextEditor editor, int offset, boolean triggered, CodeAssistCallback callback);
3944

4045
/**
4146
* Returns the reason why this content assist processor

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/codeassist/CodeAssistant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public interface CodeAssistant {
5050
* appropriate content assist processor to invoke.
5151
*
5252
* @param offset a document offset
53+
* @param triggered if triggered by the content assist key binding
5354
* @param callback the callback to use once completions are ready
5455
*/
55-
void computeCompletionProposals(int offset, CodeAssistCallback callback);
56+
void computeCompletionProposals(int offset, boolean triggered, CodeAssistCallback callback);
5657

5758
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/codeassist/CodeAssistantImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public CodeAssistantImpl(@Assisted final DocumentPartitioner partitioner,
5252
}
5353

5454
@Override
55-
public void computeCompletionProposals(final int offset, final CodeAssistCallback callback) {
55+
public void computeCompletionProposals(final int offset, final boolean triggered, final CodeAssistCallback callback) {
5656
this.lastErrorMessage = "processing";
5757

5858
final CodeAssistProcessor processor = getProcessor(offset);
5959
if (processor != null) {
60-
processor.computeCompletionProposals(textEditor, offset, callback);
60+
processor.computeCompletionProposals(textEditor, offset, triggered, callback);
6161
this.lastErrorMessage = processor.getErrorMessage();
6262
if (this.lastErrorMessage != null) {
6363
notificationManager.notify("", lastErrorMessage, FAIL, EMERGE_MODE);
@@ -66,7 +66,7 @@ public void computeCompletionProposals(final int offset, final CodeAssistCallbac
6666
} else {
6767
final CodeAssistProcessor fallbackProcessor = getFallbackProcessor();
6868
if (fallbackProcessor != null) {
69-
fallbackProcessor.computeCompletionProposals(textEditor, offset, callback);
69+
fallbackProcessor.computeCompletionProposals(textEditor, offset, triggered, callback);
7070
this.lastErrorMessage = fallbackProcessor.getErrorMessage();
7171
if (this.lastErrorMessage != null) {
7272
this.textEditor.showMessage(this.lastErrorMessage);

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/codeassist/CompletionProposal.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.api.editor.codeassist;
1212

13+
import com.google.gwt.user.client.rpc.AsyncCallback;
1314
import com.google.gwt.user.client.ui.Widget;
1415

1516
import org.eclipse.che.ide.api.icon.Icon;
@@ -28,10 +29,10 @@ public interface CompletionProposal {
2829
/**
2930
* Returns optional additional information about the proposal. The additional information will be presented to assist the user
3031
* in deciding if the selected proposal is the desired choice.
31-
*
32-
* @return the additional information or <code>null</code>
32+
*
33+
* @param callback a callback to return a widget with additional information
3334
*/
34-
Widget getAdditionalProposalInfo();
35+
void getAdditionalProposalInfo(AsyncCallback<Widget> callback);
3536

3637
/**
3738
* Returns the string to be displayed in the list of completion proposals.

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/codeassist/DefaultChainedCodeAssistProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ protected void setProcessors(final Set<? extends CodeAssistProcessor> codeAssist
3636
}
3737

3838
@Override
39-
public void computeCompletionProposals(final TextEditor textEditor, final int offset, final CodeAssistCallback callback) {
39+
public void computeCompletionProposals(final TextEditor textEditor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
4040
if (!this.codeAssistProcessors.isEmpty()) {
4141
final List<CompletionProposal> proposalList = new ArrayList<>();
4242
final List<CodeAssistProcessor> expected = new ArrayList<>();
4343
for (final CodeAssistProcessor processor : this.codeAssistProcessors) {
4444
expected.add(processor);
45-
processor.computeCompletionProposals(textEditor, offset, new CodeAssistCallback() {
45+
processor.computeCompletionProposals(textEditor, offset, triggered, new CodeAssistCallback() {
4646
@Override
4747
public void proposalComputed(final List<CompletionProposal> processorProposals) {
4848
expected.remove(processor);

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/texteditor/TextEditorInit.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private void configureCodeAssist(final DocumentHandle documentHandle) {
191191
final KeyBindingAction action = new KeyBindingAction() {
192192
@Override
193193
public boolean action() {
194-
showCompletion(codeAssistant);
194+
showCompletion(codeAssistant, true);
195195
return true;
196196
}
197197
};
@@ -202,7 +202,7 @@ public boolean action() {
202202
documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {
203203
@Override
204204
public void onCompletionRequest(final CompletionRequestEvent event) {
205-
showCompletion(codeAssistant);
205+
showCompletion(codeAssistant, false);
206206
}
207207
});
208208
} else {
@@ -234,8 +234,9 @@ public void onCompletionRequest(final CompletionRequestEvent event) {
234234
* Show the available completions.
235235
*
236236
* @param codeAssistant the code assistant
237+
* @param triggered if triggered by the content assist key binding
237238
*/
238-
private void showCompletion(final CodeAssistant codeAssistant) {
239+
private void showCompletion(final CodeAssistant codeAssistant, final boolean triggered) {
239240
final int cursor = textEditor.getCursorOffset();
240241
if (cursor < 0) {
241242
return;
@@ -248,7 +249,7 @@ public void computeCompletions(final CompletionReadyCallback callback) {
248249
// cursor must be computed here again so it's original value is not baked in
249250
// the SMI instance closure - important for completion update when typing
250251
final int cursor = textEditor.getCursorOffset();
251-
codeAssistant.computeCompletionProposals(cursor, new CodeAssistCallback() {
252+
codeAssistant.computeCompletionProposals(cursor, triggered, new CodeAssistCallback() {
252253
@Override
253254
public void proposalComputed(final List<CompletionProposal> proposals) {
254255
callback.onCompletionReady(proposals);

plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/editor/ActionCompletionProposal.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.ext.java.client.editor;
1212

13+
import com.google.gwt.user.client.rpc.AsyncCallback;
1314
import com.google.gwt.user.client.ui.Widget;
1415

16+
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
1517
import org.eclipse.che.ide.api.icon.Icon;
1618
import org.eclipse.che.ide.ext.java.client.action.ProposalAction;
17-
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
1819
import org.eclipse.che.ide.util.loging.Log;
1920

2021
/**
@@ -35,8 +36,8 @@ public ActionCompletionProposal(String display, String actionId, ProposalAction
3536
}
3637

3738
@Override
38-
public Widget getAdditionalProposalInfo() {
39-
return null;
39+
public void getAdditionalProposalInfo(AsyncCallback<Widget> callback) {
40+
callback.onSuccess(null);
4041
}
4142

4243
@Override

plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/editor/JavaCodeAssistProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ public static Icon getIcon(final String image) {
155155
}
156156

157157
@Override
158-
public void computeCompletionProposals(final TextEditor textEditor, final int offset,
158+
public void computeCompletionProposals(final TextEditor textEditor,
159+
final int offset,
160+
final boolean triggered,
159161
final CodeAssistCallback callback) {
160162
if (errorMessage != null) {
161163
return;

plugins/plugin-java/che-plugin-java-ext-lang-client/src/main/java/org/eclipse/che/ide/ext/java/client/editor/JavaCompletionProposal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public JavaCompletionProposal(final int id,
7979

8080
/** {@inheritDoc} */
8181
@Override
82-
public Widget getAdditionalProposalInfo() {
82+
public void getAdditionalProposalInfo(AsyncCallback<Widget> callback) {
8383
Frame frame = new Frame();
8484
frame.setSize("100%", "100%");
8585
frame.getElement().getStyle().setBorderStyle(Style.BorderStyle.NONE);
8686
frame.getElement().setAttribute("sandbox", ""); // empty value, not null
8787
frame.getElement().getStyle().setProperty("resize", "both");
8888
frame.setUrl(client.getProposalDocUrl(id, sessionId));
89-
return frame;
89+
callback.onSuccess(frame);
9090
}
9191

9292
/** {@inheritDoc} */

plugins/plugin-languageserver/che-plugin-languageserver-ide/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@
120120
</testResource>
121121
</testResources>
122122
<plugins>
123+
<plugin>
124+
<groupId>com.mycila</groupId>
125+
<artifactId>license-maven-plugin</artifactId>
126+
<configuration>
127+
<excludes>
128+
<exclude>**/org/eclipse/che/plugin/languageserver/ide/editor/codeassist/LatestCompletionResult.java</exclude>
129+
</excludes>
130+
</configuration>
131+
</plugin>
123132
<plugin>
124133
<groupId>org.codehaus.mojo</groupId>
125134
<artifactId>build-helper-maven-plugin</artifactId>

0 commit comments

Comments
 (0)