use of org.eclipse.jface.text.contentassist.ContextInformation in project eclipse.platform.text by eclipse.
the class BarContentAssistProcessor method computeContextInformation.
/**
* Creates context info "idx= <word index in #PROPOSAL>" at the end of a word.
*/
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
try {
IDocument document = viewer.getDocument();
int begin = offset;
while (begin > 0 && Character.isLetterOrDigit(document.getChar(begin - 1))) {
begin--;
}
if (begin < offset) {
String word = document.get(begin, offset - begin);
int idx = Arrays.asList(completeString.split("\\W")).indexOf(word);
if (idx >= 0) {
return new IContextInformation[] { new ContextInformation(word, "idx= " + idx) };
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.jface.text.contentassist.ContextInformation in project bndtools by bndtools.
the class BndCompletionProcessor method proposals.
private static ICompletionProposal[] proposals(String prefix, int offset) {
ArrayList<ICompletionProposal> results = new ArrayList<ICompletionProposal>(Syntax.HELP.size());
for (Syntax s : Syntax.HELP.values()) {
if (prefix == null || s.getHeader().startsWith(prefix)) {
IContextInformation info = new ContextInformation(s.getHeader(), s.getHeader());
String text = prefix == null ? s.getHeader() : s.getHeader().substring(prefix.length());
// $NON-NLS-1$
results.add(new CompletionProposal(text + ": ", offset, 0, text.length() + 2, null, s.getHeader(), info, s.getLead()));
}
}
Collections.sort(results, new Comparator<ICompletionProposal>() {
@Override
public int compare(ICompletionProposal p1, ICompletionProposal p2) {
return p1.getDisplayString().compareTo(p2.getDisplayString());
}
});
return results.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.contentassist.ContextInformation in project bndtools by bndtools.
the class BundleClassCompletionProposalComputer method computeContextInformation.
@Override
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
List<IContextInformation> result = new LinkedList<IContextInformation>();
result.add(new ContextInformation("contextDisplayString", "informationDisplayString"));
return result;
}
use of org.eclipse.jface.text.contentassist.ContextInformation in project dbeaver by serge-rider.
the class SQLCompletionAnalyzer method createCompletionProposal.
/*
* Turns the vector into an Array of ICompletionProposal objects
*/
protected static SQLCompletionProposal createCompletionProposal(CompletionRequest request, String replaceString, String displayString, DBPKeywordType proposalType, @Nullable DBPImage image, boolean isObject, @Nullable DBPNamedObject object) {
DBPPreferenceStore store = request.editor.getActivePreferenceStore();
DBPDataSource dataSource = request.editor.getDataSource();
if (dataSource != null) {
if (isObject) {
// Escape replace string if required
replaceString = DBUtils.getQuotedIdentifier(dataSource, replaceString);
}
}
// If we have quoted string then ignore pref settings
boolean quotedString = request.wordDetector.isQuoted(replaceString);
if (!quotedString) {
final int proposalCase = store.getInt(SQLPreferenceConstants.PROPOSAL_INSERT_CASE);
switch(proposalCase) {
case SQLPreferenceConstants.PROPOSAL_CASE_UPPER:
replaceString = replaceString.toUpperCase();
break;
case SQLPreferenceConstants.PROPOSAL_CASE_LOWER:
replaceString = replaceString.toLowerCase();
break;
default:
// Do not convert case if we got it directly from object
if (!isObject) {
DBPIdentifierCase convertCase = dataSource instanceof SQLDataSource ? ((SQLDataSource) dataSource).getSQLDialect().storesUnquotedCase() : DBPIdentifierCase.MIXED;
replaceString = convertCase.transform(replaceString);
}
break;
}
}
Image img = image == null ? null : DBeaverIcons.getImage(image);
return new SQLCompletionProposal(request, displayString, // replacementString
replaceString, //cursorPosition the position of the cursor following the insert
replaceString.length(), //image to display
img, //the context information associated with this proposal
new ContextInformation(img, displayString, displayString), proposalType, null, object);
}
use of org.eclipse.jface.text.contentassist.ContextInformation in project eclipse.platform.text by eclipse.
the class JavaCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
for (int i = 0; i < fgProposals.length; i++) {
// $NON-NLS-1$
IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] }));
// $NON-NLS-1$
result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] }));
}
return result;
}
Aggregations