1 package org.simantics.scl.ui.editor.completion;
3 import org.eclipse.jface.text.BadLocationException;
4 import org.eclipse.jface.text.IDocument;
5 import org.eclipse.jface.text.ITextSelection;
6 import org.eclipse.jface.text.ITextViewer;
7 import org.eclipse.jface.text.contentassist.ICompletionProposal;
8 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
9 import org.eclipse.jface.text.contentassist.IContextInformation;
10 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
12 public class SCLCompletionAssistProcessor implements IContentAssistProcessor {
14 // private String lastPrefix = null;
15 private String lastError = "";
16 private SCLTextEditorEnvironment sclTextEditorEnvironment;
18 public SCLCompletionAssistProcessor(SCLTextEditorEnvironment sclTextEditorEnvironment) {
19 this.sclTextEditorEnvironment = sclTextEditorEnvironment;
23 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) {
24 ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();
25 // adjust offset to end of normalized selection
26 if (selection.getOffset() == tmpOffset)
27 tmpOffset = selection.getOffset() + selection.getLength();
28 final int offset = tmpOffset;
29 IDocument document = viewer.getDocument();
30 String tmpPrefix = "";
32 tmpPrefix = getPrefix(document, offset);
33 } catch (BadLocationException e) {
36 sclTextEditorEnvironment.updateEnvironment(document);
37 return sclTextEditorEnvironment.getCompletionProposals(tmpPrefix, offset);
40 private static String getPrefix(IDocument doc, int offset) throws BadLocationException {
41 int docLen = doc.getLength();
42 if (doc == null || offset > docLen || docLen == 0)
46 while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.')
49 return doc.get(offset + 1, length);
53 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
57 private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' };
60 public char[] getCompletionProposalAutoActivationCharacters() {
61 return AUTO_ACTIVATION_CHARS;
65 public char[] getContextInformationAutoActivationCharacters() {
70 public String getErrorMessage() {
75 public IContextInformationValidator getContextInformationValidator() {