Search in sources :

Example 1 with ContextInformation

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;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ContextInformation

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]);
}
Also used : ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) Syntax(aQute.bnd.help.Syntax)

Example 3 with ContextInformation

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;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) LinkedList(java.util.LinkedList)

Example 4 with ContextInformation

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);
}
Also used : ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) Image(org.eclipse.swt.graphics.Image) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 5 with ContextInformation

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;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation)

Aggregations

ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)7 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)6 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)3 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 ArrayList (java.util.ArrayList)2 Syntax (aQute.bnd.help.Syntax)1 LinkedList (java.util.LinkedList)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 STPFunctionCompletionProposal (org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPFunctionCompletionProposal)1 STPProbeCompletionProposal (org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPProbeCompletionProposal)1 STPProbevarCompletionProposal (org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPProbevarCompletionProposal)1 Image (org.eclipse.swt.graphics.Image)1 CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)1 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)1 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)1