blob: 7eb9c1afc0e2a7c337f2dee836478993fb92ff34 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2005, 2017 IBM Corporation and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*******************************************************************************/
package org.eclipse.dltk.ruby.internal.ui.text.completion;
import org.eclipse.dltk.core.CompletionProposal;
import org.eclipse.dltk.core.IScriptProject;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.ruby.core.RubyNature;
import org.eclipse.dltk.ui.text.completion.IScriptCompletionProposal;
import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal;
import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector;
import org.eclipse.swt.graphics.Image;
public class RubyCompletionProposalCollector extends
ScriptCompletionProposalCollector {
protected final static char[] VAR_TRIGGER = new char[] { '\t', ' ', '=',
';', '.' };
@Override
protected char[] getVarTrigger() {
return VAR_TRIGGER;
}
public RubyCompletionProposalCollector(ISourceModule module) {
super(module);
}
// Specific proposals creation. May be use factory?
@Override
protected ScriptCompletionProposal createScriptCompletionProposal(
String completion, int replaceStart, int length, Image image,
String displayString, int i) {
return new RubyCompletionProposal(completion, replaceStart, length,
image, displayString, i);
}
@Override
protected ScriptCompletionProposal createScriptCompletionProposal(
String completion, int replaceStart, int length, Image image,
String displayString, int i, boolean isInDoc) {
return new RubyCompletionProposal(completion, replaceStart, length,
image, displayString, i, isInDoc);
}
@Override
protected ScriptCompletionProposal createOverrideCompletionProposal(
IScriptProject scriptProject, ISourceModule compilationUnit,
String name, String[] paramTypes, int start, int length,
String displayName, String completionProposal) {
return new RubyOverrideCompletionProposal(compilationUnit, name, start, length, displayName,
completionProposal);
}
@Override
protected IScriptCompletionProposal createKeywordProposal(
CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
String label = getLabelProvider().createSimpleLabel(proposal);
Image img = getImage(getLabelProvider().createImageDescriptor(proposal));
int relevance = computeRelevance(proposal);
return createScriptCompletionProposal(completion, start, length, img,
label, relevance);
}
@Override
protected String getNatureId() {
return RubyNature.NATURE_ID;
}
}