/** * Internally compute completion proposals. * * @param cursorPosition * the position of the cursor in the {@link IXtextDocument} * @param xtextDocument * the {@link IXtextDocument} * @return a pair of {@link ICompletionProposal}[] and {@link BadLocationException}. If the tail argument is not {@code null}, an exception occurred in the UI * thread. */ private Pair<ICompletionProposal[], BadLocationException> internalComputeCompletionProposals(final int cursorPosition, final IXtextDocument xtextDocument) { XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class); Shell shell = new Shell(); try { ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration); IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer); String contentType = xtextDocument.getContentType(cursorPosition); IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(contentType); if (processor != null) { return Tuples.create(processor.computeCompletionProposals(sourceViewer, cursorPosition), null); } return Tuples.create(new ICompletionProposal[0], null); } catch (BadLocationException e) { return Tuples.create(new ICompletionProposal[0], e); } finally { shell.dispose(); } }
/** * {@inheritDoc} Code copied from parent. Override required to run in UI because of getSourceViewer, which creates a new Shell. */ @Override public ContentAssistProcessorTestBuilder assertMatchString(final String matchString) throws Exception { BadLocationException exception = UiThreadDispatcher.dispatchAndWait(new Function<BadLocationException>() { @Override public BadLocationException run() { String currentModelToParse = getModel(); final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse)); final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse); XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class); Shell shell = new Shell(); try { ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration); IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer); String contentType = xtextDocument.getContentType(currentModelToParse.length()); if (contentAssistant.getContentAssistProcessor(contentType) != null) { ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class); ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource); for (ContentAssistContext context : contexts) { Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix()) || matchString.equals(context.getPrefix())); } } else { Assert.fail("No content assistant for content type " + contentType); } } catch (BadLocationException e) { return e; } finally { shell.dispose(); } return null; } }); if (exception != null) { throw exception; } return this; }
/** * Helper function to find the correct CompletionProposalComputer for the given offset. * * @param offset * offset in test file * @return language and offset specific content assist proposal computer */ private CompletionProposalComputer createCompletionProposalComputer(final int offset) { XtextSourceViewerConfiguration configuration = getEditor().getXtextSourceViewerConfiguration(); IContentAssistant contentAssistant = configuration.getContentAssistant(getViewer()); IContentAssistProcessor contentAssistProcessor; try { contentAssistProcessor = contentAssistant.getContentAssistProcessor(getDocument().getContentType(offset)); } catch (BadLocationException e) { contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class); } if (contentAssistProcessor == null) { contentAssistProcessor = getTestUtil().get(IContentAssistProcessor.class); } return new CompletionProposalComputer((State) contentAssistProcessor, (ITextViewer) getViewer(), offset); }
public DefaultMergeViewer(Composite parent, int styles, CompareConfiguration compareConfiguration, StreamContentDocumentProvider documentProvider, Provider<XtextSourceViewerConfiguration> sourceViewerConfigurationProvider) { super(parent, styles | SWT.LEFT_TO_RIGHT, compareConfiguration); this.documentProvider = documentProvider; this.sourceViewerConfigurationProvider = sourceViewerConfigurationProvider; }
public EmbeddedEditor(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, IEditedResourceProvider resourceProvider, Runnable afterSetDocumet) { this.document = document; this.viewer = viewer; this.configuration = configuration; this.resourceProvider = resourceProvider; this.afterSetDocument = afterSetDocumet; }
/** * @since 2.3 */ public void install(XtextSourceViewerConfiguration configuration, XtextSourceViewer sourceViewer) { fSourceViewer= sourceViewer; fConfiguration= configuration; if(sourceViewer != null && configuration != null){ fPresentationReconciler= (XtextPresentationReconciler) fConfiguration.getPresentationReconciler(sourceViewer); } else { fPresentationReconciler = null; fConfiguration = null; } preferenceStore = getPreferenceStoreAccessor().getPreferenceStore(); preferenceStore.addPropertyChangeListener(this); enable(); }
public XtextSourceViewerConfiguration getConfiguration() { return this.configuration; }
protected XtextSourceViewerConfiguration getXtextSourceViewerConfiguration() { return this.configuration; }
protected XtextSourceViewerConfiguration getXtextSourceViewerConfiguration() { return configuration; }
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() { return GamaSourceViewerConfiguration.class; }
public Class<? extends XtextSourceViewerConfiguration> bindXtextSourceViewerConfiguration() { return SadlSourceViewerConfiguration.class; }