org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext Java Examples
The following examples show how to use
org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void proposeProjectTypes(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) { if (namePath.size() >= 2) { String n4js = namePath.get(namePath.size() - 2); String projectType = namePath.get(namePath.size() - 1); if (PackageJsonProperties.PROJECT_TYPE.name.equals(projectType) || PackageJsonProperties.N4JS.name.equals(n4js)) { for (ProjectType type : ProjectType.values()) { String asString = PackageJsonUtils.getProjectTypeStringRepresentation(type); if (asString.equals(asString.toUpperCase())) { asString = asString.toLowerCase(); } ContentAssistEntry entryForProjectType = getProposalCreator().createProposal( '"' + asString + '"', context, ContentAssistEntry.KIND_KEYWORD, null); if (entryForProjectType != null) { acceptor.accept(entryForProjectType, getProposalPriorities().getDefaultPriority(entryForProjectType)); } } } } }
Example #2
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ContentAssistEntry createProposal(EReference reference, ITypeDescriptor typeDesc, ContentAssistContext context, XImportSection importSection, ITextRegion importSectionRegion) { boolean importDecl = isImportDeclaration(reference, context); String qualifiedName = qualifiedNameConverter.toString(typeDesc.getQualifiedName()); String proposal; if (importDecl) { proposal = qualifiedName; } else { proposal = typeDesc.getSimpleName(); } return proposalCreator.createProposal(proposal, context, (ContentAssistEntry it) -> { it.setKind(ContentAssistEntry.KIND_REFERENCE); if (importDecl) { it.setLabel(typeDesc.getSimpleName()); it.setDescription(proposal); } else { it.setDescription(qualifiedName); if (importSectionRegion != null && isImportDeclarationRequired(typeDesc, qualifiedName, context, importSection)) { addImportDeclaration(it, importSectionRegion, typeDesc, qualifiedName, context); } } }); }
Example #3
Source File: UiToIdeContentProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private ContentAssistContext getIdeContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext cac) { Builder builder = builderProvider.get(); Region replaceRegion = cac.getReplaceRegion(); builder // .setPrefix(cac.getPrefix()) // .setSelectedText(cac.getSelectedText()) // .setRootModel(cac.getRootModel()) // .setRootNode(cac.getRootNode()) // .setCurrentModel(cac.getCurrentModel()) // .setPreviousModel(cac.getPreviousModel()) // .setCurrentNode(cac.getCurrentNode()) // .setLastCompleteNode(cac.getLastCompleteNode()) // .setOffset(cac.getOffset()) // .setReplaceRegion(new TextRegion(replaceRegion.getOffset(), replaceRegion.getLength())) // .setResource(cac.getResource()); cac.getFirstSetGrammarElements().forEach(grammarElement -> builder.accept(grammarElement)); return builder.toContext(); }
Example #4
Source File: ContentAssistContextFactory.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void doCreateContexts( INode lastCompleteNode, INode currentNode, String prefix, EObject previousModel, Collection<FollowElement> followElements) { Set<AbstractElement> followElementAsAbstractElements = Sets.newLinkedHashSet(); followElementComputer.computeFollowElements(followElements, followElementAsAbstractElements); Multimap<EObject, AbstractElement> contextMap = computeCurrentModel(previousModel, lastCompleteNode, followElementAsAbstractElements); currentNode = getContainingDatatypeRuleNode(currentNode); for (Entry<EObject, Collection<AbstractElement>> entry : contextMap.asMap().entrySet()) { ContentAssistContext.Builder contextBuilder = doCreateContext(lastCompleteNode, entry.getKey(), previousModel, currentNode, prefix); for(AbstractElement element: entry.getValue()) { contextBuilder.accept(element); } contextBuilders.add(contextBuilder); } }
Example #5
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected ClassLoader getClassLoader(ContentAssistContext context) { ResourceSet resourceSet = context.getResource().getResourceSet(); if (resourceSet instanceof XtextResourceSet) { Object ctx = ((XtextResourceSet) resourceSet).getClasspathURIContext(); if (ctx != null) { if (ctx instanceof Class<?>) { return ((Class<?>) ctx).getClassLoader(); } if (ctx instanceof ClassLoader) { return (ClassLoader) ctx; } return ctx.getClass().getClassLoader(); } } return classLoader; }
Example #6
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void completeXFeatureCall(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { if ((model != null)) { boolean _hasExpressionScope = this.typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN); if (_hasExpressionScope) { return; } } if ((model instanceof XMemberFeatureCall)) { final ICompositeNode node = NodeModelUtils.getNode(model); boolean _isInMemberFeatureCall = this.isInMemberFeatureCall(model, node.getEndOffset(), context); if (_isInMemberFeatureCall) { return; } } this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor); }
Example #7
Source File: ClasspathBasedIdeTypesProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public void createTypeProposals(EReference reference, ContentAssistContext context, Predicate<? super ITypeDescriptor> filter, IIdeContentProposalAcceptor acceptor) { ITextRegion importSectionRegion = null; XImportSection importSection = null; if (!isImportDeclaration(reference, context)) { importSection = importsConfiguration.getImportSection(context.getResource()); importSectionRegion = importSectionRegionUtil.computeRegion(context.getResource()); } for (ITypeDescriptor typeDesc : getTypeDescriptors(context)) { if (!acceptor.canAcceptMoreProposals()) { return; } if (canPropose(typeDesc, context, filter)) { ContentAssistEntry entry = createProposal(reference, typeDesc, context, importSection, importSectionRegion); int priority = ((XbaseIdeContentProposalPriorities) proposalPriorities).getTypeRefPriority(typeDesc, entry); acceptor.accept(entry, priority); } } }
Example #8
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void addTemplateProposal( String proposal, String label, String description, String kind, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) { if (getProposalCreator().isValidProposal(label, context.getPrefix(), context)) { ContentAssistEntry entry = new ContentAssistEntry(); entry.setProposal(proposal); entry.setPrefix(context.getPrefix()); entry.setKind(ContentAssistEntry.KIND_SNIPPET + ":" + kind); entry.setLabel(label); entry.setDescription(description); acceptor.accept(entry, getProposalPriorities().getDefaultPriority(entry)); } }
Example #9
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void createLocalVariableAndImplicitProposals(final EObject model, final IExpressionScope.Anchor anchor, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { String prefix = context.getPrefix(); if (((prefix.length() > 0) && (!Character.isJavaIdentifierStart(prefix.charAt(0))))) { return; } IResolvedTypes _xifexpression = null; if ((model != null)) { _xifexpression = this.typeResolver.resolveTypes(model); } else { _xifexpression = this.typeResolver.resolveTypes(context.getResource()); } final IResolvedTypes resolvedTypes = _xifexpression; final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(model, anchor); final IScope scope = expressionScope.getFeatureScope(); this.getCrossrefProposalProvider().lookupCrossReference(scope, this._xbaseGrammarAccess.getXFeatureCallAccess().getFeatureJvmIdentifiableElementCrossReference_2_0(), context, acceptor, this.featureDescriptionPredicate); }
Example #10
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver); final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver); if (((receiverType == null) || receiverType.isPrimitiveVoid())) { return; } final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER); IScope scope = null; final EObject currentModel = context.getCurrentModel(); if ((currentModel != receiver)) { if (((currentModel instanceof XMemberFeatureCall) && (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference); } else { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference); } } else { scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference); } this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate); }
Example #11
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void proposeVersions(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) { if (namePath.size() >= 2) { // somewhat poor heuristic: propose all projects that are known in the current workspace String devOrDep = namePath.get(namePath.size() - 2); if (PackageJsonProperties.DEPENDENCIES.name.equals(devOrDep) || PackageJsonProperties.DEV_DEPENDENCIES.name.equals(devOrDep)) { NameValuePair pair = (NameValuePair) context.getCurrentModel(); IN4JSProject project = n4jsCore.findProject(new N4JSProjectName(pair.getName())).orNull(); if (project != null) { VersionNumber version = project.getVersion(); ContentAssistEntry versionEntry = getProposalCreator().createProposal( '"' + version.toString() + '"', context, ContentAssistEntry.KIND_VALUE, null); acceptor.accept(versionEntry, getProposalPriorities().getDefaultPriority(versionEntry)); } ContentAssistEntry wildcard = getProposalCreator().createProposal( "\"*\"", context, ContentAssistEntry.KIND_VALUE, null); acceptor.accept(wildcard, getProposalPriorities().getDefaultPriority(wildcard)); } } }
Example #12
Source File: JSONIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void proposeLocalPackages(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) { if (!namePath.isEmpty()) { // somewhat poor heuristic: propose all projects that are known in the current workspace String last = namePath.get(namePath.size() - 1); if (PackageJsonProperties.DEPENDENCIES.name.equals(last) || PackageJsonProperties.DEV_DEPENDENCIES.name.equals(last)) { for (IN4JSProject project : n4jsCore.findAllProjects()) { N4JSProjectName projectName = project.getProjectName(); ContentAssistEntry entryForModule = getProposalCreator().createProposal( '"' + projectName.getRawName() + '"', context, ContentAssistEntry.KIND_MODULE, null); if (entryForModule != null) { acceptor.accept(entryForModule, getProposalPriorities().getDefaultPriority(entryForModule)); } } } } }
Example #13
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public void createProposals(final AbstractElement assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { if (assignment instanceof Assignment) { _createProposals((Assignment)assignment, context, acceptor); return; } else if (assignment instanceof CrossReference) { _createProposals((CrossReference)assignment, context, acceptor); return; } else if (assignment instanceof Keyword) { _createProposals((Keyword)assignment, context, acceptor); return; } else if (assignment instanceof RuleCall) { _createProposals((RuleCall)assignment, context, acceptor); return; } else if (assignment != null) { _createProposals(assignment, context, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(assignment, context, acceptor).toString()); } }
Example #14
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 6 votes |
private ContentAssistEntry convertResolutionToContentAssistEntry(ReferenceResolution resolution, N4JSResource resource, ContentAssistContext context) { ContentAssistEntry cae = new ContentAssistEntry(); cae.setPrefix(context.getPrefix()); cae.setProposal(resolution.proposal); cae.setLabel(resolution.label); cae.setDescription(resolution.description); if (resolution.importToBeAdded != null) { ReplaceRegion textReplacement = importHelper.getReplacementForImport(resource.getScript(), resolution.importToBeAdded); cae.getTextReplacements().add(textReplacement); } cae.setSource(resolution.referencedElement); cae.setKind(getKind(resolution)); return cae; }
Example #15
Source File: ContentAssistService.java From xtext-web with Eclipse Public License 2.0 | 6 votes |
/** * Create content assist proposals at the given caret offset. This document read * operation is scheduled with higher priority, so currently running operations * may be canceled. The document processing is rescheduled as background work * afterwards. */ public ContentAssistResult createProposals(XtextWebDocumentAccess document, ITextRegion selection, int caretOffset, int proposalsLimit) throws InvalidRequestException { String[] stateIdWrapper = new String[1]; ContentAssistContext[] contexts = document .priorityReadOnly(new CancelableUnitOfWork<ContentAssistContext[], IXtextWebDocument>() { @Override public ContentAssistContext[] exec(IXtextWebDocument it, CancelIndicator cancelIndicator) throws Exception { stateIdWrapper[0] = it.getStateId(); return getContexts(it, selection, caretOffset); } }); List<ContentAssistContext> contextsList = Arrays.asList(contexts); return createProposals(contextsList, stateIdWrapper[0], proposalsLimit); }
Example #16
Source File: ImportsAwareReferenceProposalCreator.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content * assist requirements, instead filter here. * * @param filter * by default an instance of {@link N4JSCandidateFilter} will be provided here. */ public void lookupCrossReference( EObject model, EReference reference, ContentAssistContext context, IIdeContentProposalAcceptor acceptor, Predicate<IEObjectDescription> filter) { if (model == null) { return; } Resource resource = model.eResource(); if (!(resource instanceof N4JSResource)) { return; } N4JSResource resourceCasted = (N4JSResource) resource; ReferenceDescriptor referenceDesc = new ReferenceDescriptor(context.getPrefix(), model, reference, context.getCurrentNode()); Predicate<String> conflictChecker = (proposalToCheck) -> conflictHelper.existsConflict(proposalToCheck, context); referenceResolutionFinder.findResolutions(referenceDesc, false, false, conflictChecker, filter, new ResolutionToContentProposalAcceptor(resourceCasted, context, acceptor)); }
Example #17
Source File: ContentAssistService.java From xtext-web with Eclipse Public License 2.0 | 6 votes |
/** * Apply a text update and then create content assist proposals. This document * read operation is scheduled with higher priority, so currently running * operations may be canceled. The document processing is rescheduled as * background work afterwards. */ public ContentAssistResult createProposalsWithUpdate(XtextWebDocumentAccess document, String deltaText, int deltaOffset, int deltaReplaceLength, ITextRegion selection, int caretOffset, int proposalsLimit) throws InvalidRequestException { String[] stateIdWrapper = new String[1]; ContentAssistContext[] contexts = document .modify(new CancelableUnitOfWork<ContentAssistContext[], IXtextWebDocument>() { @Override public ContentAssistContext[] exec(IXtextWebDocument it, CancelIndicator cancelIndicator) throws Exception { it.setDirty(true); it.createNewStateId(); stateIdWrapper[0] = it.getStateId(); it.updateText(deltaText, deltaOffset, deltaReplaceLength); return getContexts(it, selection, caretOffset); } }); List<ContentAssistContext> contextsList = Arrays.asList(contexts); return createProposals(contextsList, stateIdWrapper[0], proposalsLimit); }
Example #18
Source File: StatemachineTemplateProposalProvider.java From xtext-web with Eclipse Public License 2.0 | 6 votes |
public void createStateProposal(ContentAssistContext context, IIdeContentProposalAcceptor acceptor) { StringConcatenationClient template = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation target) { target.append("state "); target.append(variable("name")); target.newLineIfNotEmpty(); target.append("\t"); target.append(cursor(), "\t"); target.newLineIfNotEmpty(); target.append("end"); target.newLine(); } }; acceptProposal("state", "Create a new state", template, context, acceptor); }
Example #19
Source File: N4JSIdeContentProposalProvider.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void _createProposals(Keyword keyword, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) { EObject currentModel = context.getCurrentModel(); EObject previousModel = context.getPreviousModel(); if (currentModel instanceof ParameterizedPropertyAccessExpression || previousModel instanceof ParameterizedPropertyAccessExpression) return; // filter out all keywords if we are in the context of a property access if (currentModel instanceof JSXElement || previousModel instanceof JSXElement) return; // filter out all keywords if we are in the context of a JSX element if (!Character.isAlphabetic(keyword.getValue().charAt(0))) return; // filter out operators if (keyword.getValue().length() < 5) return; // filter out short keywords super._createProposals(keyword, context, acceptor); }
Example #20
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public boolean filterKeyword(final Keyword keyword, final ContentAssistContext context) { final String value = keyword.getValue(); if (((value.length() > 1) && Character.isLetter(value.charAt(0)))) { if ((Objects.equal(value, "as") || Objects.equal(value, "instanceof"))) { final EObject previousModel = context.getPreviousModel(); if ((previousModel instanceof XExpression)) { if (((context.getPrefix().length() == 0) && (NodeModelUtils.getNode(previousModel).getEndOffset() > context.getOffset()))) { return false; } final LightweightTypeReference type = this.typeResolver.resolveTypes(previousModel).getActualType(((XExpression)previousModel)); if (((type == null) || type.isPrimitiveVoid())) { return false; } } } return true; } return false; }
Example #21
Source File: ContentAssistContextTestHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) { final int offset = this.document.indexOf(this.cursor); Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor"); final String doc = this.document.replace(this.cursor, ""); final XtextResource res = this.parse(doc); factory.setPool(Executors.newCachedThreadPool()); TextRegion _textRegion = new TextRegion(0, 0); final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res); final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule(); StringConcatenation _builder = new StringConcatenation(); { Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs))); for(final Pair<Integer, ContentAssistContext> ctx : _indexed) { _builder.append("context"); Integer _key = ctx.getKey(); _builder.append(_key); _builder.append(" {"); _builder.newLineIfNotEmpty(); { ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements(); for(final AbstractElement ele : _firstSetGrammarElements) { _builder.append("\t"); String _name = ele.eClass().getName(); _builder.append(_name, "\t"); _builder.append(": "); String _apply = f.apply(ele); _builder.append(_apply, "\t"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); } } return _builder.toString(); }
Example #22
Source File: ContentAssistService.java From xtext-web with Eclipse Public License 2.0 | 5 votes |
public ContentAssistContext[] getContexts(IXtextWebDocument document, ITextRegion selection, int caretOffset) { if (caretOffset > document.getText().length()) { return new ContentAssistContext[] {}; } ContentAssistContextFactory contextFactory = contextFactoryProvider.get(); contextFactory.setPool(executorService); return contextFactory.create(document.getText(), selection, caretOffset, document.getResource()); }
Example #23
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void completeXBasicForLoopInit(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { final ICompositeNode node = NodeModelUtils.getNode(model); int _offset = node.getOffset(); int _offset_1 = context.getOffset(); boolean _greaterEqualsThan = (_offset >= _offset_1); if (_greaterEqualsThan) { this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); return; } if ((model instanceof XBasicForLoopExpression)) { final EList<XExpression> children = ((XBasicForLoopExpression)model).getInitExpressions(); for (int i = (children.size() - 1); (i >= 0); i--) { { final XExpression child = children.get(i); final ICompositeNode childNode = NodeModelUtils.getNode(child); int _endOffset = childNode.getEndOffset(); int _offset_2 = context.getOffset(); boolean _lessEqualsThan = (_endOffset <= _offset_2); if (_lessEqualsThan) { this.createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor); return; } } } } this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); }
Example #24
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void completeXAssignment(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { final String ruleName = this.getConcreteSyntaxRuleName(assignment); boolean _isOperatorRule = this.isOperatorRule(ruleName); if (_isOperatorRule) { this.completeBinaryOperation(model, assignment, context, acceptor); } }
Example #25
Source File: ContentAssistService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void createProposals(String document, TextRegion selection, int caretOffset, XtextResource resource, IIdeContentProposalAcceptor acceptor) { if (caretOffset > document.length()) { return; } ContentAssistContextFactory contextFactory = contextFactoryProvider.get(); contextFactory.setPool(executorService); ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource); proposalProvider.createProposals(Arrays.asList(contexts), acceptor); }
Example #26
Source File: HoverService.java From xtext-web with Eclipse Public License 2.0 | 5 votes |
/** * Compute a hover result for a content assist proposal at the given offset. */ public HoverResult getHover(XtextWebDocumentAccess document, String proposal, ITextRegion selection, int offset) throws InvalidRequestException { return document.readOnly(new CancelableUnitOfWork<HoverResult, IXtextWebDocument>() { @Override public HoverResult exec(IXtextWebDocument it, CancelIndicator cancelIndicator) throws Exception { ContentAssistContext[] contexts = contentAssistService.getContexts(it, selection, offset); Wrapper<Object> proposedElement = new Wrapper<Object>(); Collection<ContentAssistContext> contextsList = Arrays.asList(contexts); contentAssistService.getProposalProvider().createProposals(contextsList, new IIdeContentProposalAcceptor() { @Override public void accept(ContentAssistEntry entry, int priority) { operationCanceledManager.checkCanceled(cancelIndicator); if (entry != null && entry.getSource() != null && Objects.equal(entry.getProposal(), proposal)) { proposedElement.set(entry.getSource()); } } @Override public boolean canAcceptMoreProposals() { return proposedElement.get() == null; } }); return createHover(proposedElement.get(), it.getStateId(), cancelIndicator); } }); }
Example #27
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void completeXMemberFeatureCall(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { if ((model instanceof XMemberFeatureCall)) { AbstractElement _terminal = assignment.getTerminal(); this.createReceiverProposals(((XMemberFeatureCall)model).getMemberCallTarget(), ((CrossReference) _terminal), context, acceptor); } else { if ((model instanceof XAssignment)) { AbstractElement _terminal_1 = assignment.getTerminal(); this.createReceiverProposals(((XAssignment)model).getAssignable(), ((CrossReference) _terminal_1), context, acceptor); } } }
Example #28
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isInMemberFeatureCall(final EObject model, final int endOffset, final ContentAssistContext context) { if (((model instanceof XMemberFeatureCall) && (endOffset >= context.getOffset()))) { final List<INode> featureNodes = NodeModelUtils.findNodesForFeature(model, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); boolean _isEmpty = featureNodes.isEmpty(); boolean _not = (!_isEmpty); if (_not) { final INode featureNode = IterableExtensions.<INode>head(featureNodes); if (((featureNode.getTotalOffset() < context.getOffset()) && (featureNode.getTotalEndOffset() >= context.getOffset()))) { return true; } } } return false; }
Example #29
Source File: XContentAssistService.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Create a single proposal. */ protected void createProposals(String document, TextRegion selection, int caretOffset, XtextResource resource, IIdeContentProposalAcceptor acceptor) { if (caretOffset > document.length()) { return; } ContentAssistContextFactory contextFactory = contextFactoryProvider.get(); contextFactory.setPool(executorService); ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource); proposalProvider.createProposals(Arrays.asList(contexts), acceptor); }
Example #30
Source File: ContentAssistContextFactory.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void handleLastCompleteNodeHasNoGrammarElement(List<Builder> contextBuilderToCheck, EObject previousModel) { List<ContentAssistContext> newContexts = Lists.transform(contextBuilderToCheck, this); boolean wasValid = isLikelyToBeValidProposal(lastCompleteNode, newContexts); if (wasValid && !(lastCompleteNode instanceof ILeafNode && ((ILeafNode) lastCompleteNode).isHidden())) { createContextsForLastCompleteNode(previousModel, false); } }