Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Use the cancelIndicator to stop creation of completion proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras committed Aug 24, 2022
1 parent 14b0026 commit 56d331d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -12,9 +12,12 @@
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.xtext.service.OperationCanceledManager;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.xbase.lib.Pair;

import com.google.common.collect.Iterables;
import com.google.inject.Inject;

/**
* @author Sven Efftinge - Initial contribution and API
Expand All @@ -24,11 +27,25 @@
public class IdeContentProposalAcceptor
implements IIdeContentProposalAcceptor, Comparator<Pair<Integer, ContentAssistEntry>> {

@Inject
private OperationCanceledManager operationCanceledManager;

protected CancelIndicator cancelIndicator;


protected final Set<Pair<Integer, ContentAssistEntry>> entries = new TreeSet<Pair<Integer, ContentAssistEntry>>(
this);

/**
* @since 2.28
*/
public void setCancelIndicator(CancelIndicator cancelIndicator) {
this.cancelIndicator = cancelIndicator;
}

@Override
public void accept(ContentAssistEntry entry, int priority) {
operationCanceledManager.checkCanceled(cancelIndicator);
if (entry != null) {
if (entry.getProposal() == null)
throw new IllegalArgumentException("Proposal must not be null.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016, 2021 TypeFox GmbH (http://www.typefox.io) and others.
* Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand Down Expand Up @@ -71,6 +71,7 @@ public CompletionList createCompletionList(Document document, XtextResource reso
CompletionList result = new CompletionList();
result.setIsIncomplete(true);
IdeContentProposalAcceptor acceptor = proposalAcceptorProvider.get();
acceptor.setCancelIndicator(cancelIndicator);
int caretOffset = document.getOffSet(params.getPosition());
Position caretPosition = params.getPosition();
TextRegion position = new TextRegion(caretOffset, 0);
Expand Down

0 comments on commit 56d331d

Please sign in to comment.