Search in sources :

Example 1 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-xtend by eclipse.

the class DirtyStateEditorValidationTest method testAddedInterfaceMethod.

@Test
public void testAddedInterfaceMethod() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("interface Foo {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String interface_ = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("interface Foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void bar(String b)");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final String interfaceChanged = _builder_1.toString();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("class Bar implements Foo {");
        _builder_2.newLine();
        _builder_2.append("}");
        _builder_2.newLine();
        final String class_ = _builder_2.toString();
        final IFile interfaceFile = this.helper.createFile("Foo.xtend", interface_);
        final IFile classFile = this.helper.createFile("Bar.xtend", class_);
        this._syncUtil.waitForBuild(null);
        Assert.assertEquals(0, classFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE).length);
        final XtextEditor interfaceEditor = this.helper.openEditor(interfaceFile);
        final XtextEditor classEditor = this.helper.openEditor(classFile);
        this.assertNumberOfErrorAnnotations(classEditor, 0);
        interfaceEditor.getDocument().set(interfaceChanged);
        this._syncUtil.waitForReconciler(interfaceEditor);
        this._syncUtil.waitForReconciler(classEditor);
        final IUnitOfWork<Object, XtextResource> _function = (XtextResource it) -> {
            final CancelIndicator _function_1 = () -> {
                return false;
            };
            final List<Issue> issues = this.validator.validate(it, CheckMode.NORMAL_AND_FAST, _function_1);
            Assert.assertEquals(issues.toString(), 1, issues.size());
            return null;
        };
        classEditor.getDocument().<Object>readOnly(_function);
        interfaceEditor.getDocument().set(interface_);
        this._syncUtil.waitForReconciler(interfaceEditor);
        this._syncUtil.waitForReconciler(classEditor);
        final IUnitOfWork<Object, XtextResource> _function_1 = (XtextResource it) -> {
            final CancelIndicator _function_2 = () -> {
                return false;
            };
            final List<Issue> issues = this.validator.validate(it, CheckMode.NORMAL_AND_FAST, _function_2);
            Assert.assertTrue(issues.toString(), issues.isEmpty());
            return null;
        };
        classEditor.getDocument().<Object>readOnly(_function_1);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Test(org.junit.Test)

Example 2 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class LanguageServerImpl method rename.

@Override
public CompletableFuture<WorkspaceEdit> rename(final RenameParams params) {
    final Function1<CancelIndicator, WorkspaceEdit> _function = (CancelIndicator cancelIndicator) -> {
        WorkspaceEdit _xblockexpression = null;
        {
            final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
            final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
            IRenameService _get = null;
            if (resourceServiceProvider != null) {
                _get = resourceServiceProvider.<IRenameService>get(IRenameService.class);
            }
            final IRenameService renameService = _get;
            if ((renameService == null)) {
                return new WorkspaceEdit();
            }
            _xblockexpression = renameService.rename(this.workspaceManager, params, cancelIndicator);
        }
        return _xblockexpression;
    };
    return this.requestManager.<WorkspaceEdit>runRead(_function);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IRenameService(org.eclipse.xtext.ide.server.rename.IRenameService) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) URI(org.eclipse.emf.common.util.URI)

Example 3 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class WorkspaceManager method didChange.

public BuildManager.Buildable didChange(final URI uri, final int version, final Iterable<TextEdit> changes) {
    boolean _containsKey = this.openDocuments.containsKey(uri);
    boolean _not = (!_containsKey);
    if (_not) {
        WorkspaceManager.LOG.error((("The document " + uri) + " has not been opened."));
        final BuildManager.Buildable _function = (CancelIndicator it) -> {
            return null;
        };
        return _function;
    }
    final Document contents = this.openDocuments.get(uri);
    this.openDocuments.put(uri, contents.applyChanges(changes));
    return this.didChangeFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(uri)), CollectionLiterals.<URI>newArrayList());
}
Also used : BuildManager(org.eclipse.xtext.ide.server.BuildManager) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI)

Example 4 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class ResourceValidatorImpl method validate.

@Override
public List<Issue> validate(Resource resource, final CheckMode mode, CancelIndicator mon) throws OperationCanceledError {
    StoppedTask task = Stopwatches.forTask("ResourceValidatorImpl.validation");
    try {
        task.start();
        final CancelIndicator monitor = mon == null ? CancelIndicator.NullImpl : mon;
        resolveProxies(resource, monitor);
        operationCanceledManager.checkCanceled(monitor);
        final List<Issue> result = Lists.newArrayListWithExpectedSize(resource.getErrors().size() + resource.getWarnings().size());
        try {
            IAcceptor<Issue> acceptor = createAcceptor(result);
            if (mode.shouldCheck(CheckType.FAST)) {
                collectResourceDiagnostics(resource, monitor, acceptor);
            }
            operationCanceledManager.checkCanceled(monitor);
            boolean syntaxDiagFail = !result.isEmpty();
            logCheckStatus(resource, syntaxDiagFail, "Syntax");
            validate(resource, mode, monitor, acceptor);
            operationCanceledManager.checkCanceled(monitor);
        } catch (RuntimeException e) {
            operationCanceledManager.propagateAsErrorIfCancelException(e);
            log.error(e.getMessage(), e);
        }
        return result;
    } finally {
        task.stop();
    }
}
Also used : StoppedTask(org.eclipse.xtext.util.internal.Stopwatches.StoppedTask) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 5 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class LazyLinkingResource method resolveLazyCrossReferences.

/**
 * resolves any lazy cross references in this resource, adding Issues for unresolvable elements to this resource.
 * This resource might still contain resolvable proxies after this method has been called.
 *
 * @param mon a {@link CancelIndicator} can be used to stop the resolution.
 */
public void resolveLazyCrossReferences(final CancelIndicator mon) {
    final CancelIndicator monitor = mon == null ? CancelIndicator.NullImpl : mon;
    TreeIterator<Object> iterator = EcoreUtil.getAllContents(this, true);
    while (iterator.hasNext()) {
        operationCanceledManager.checkCanceled(monitor);
        InternalEObject source = (InternalEObject) iterator.next();
        EStructuralFeature[] eStructuralFeatures = ((EClassImpl.FeatureSubsetSupplier) source.eClass().getEAllStructuralFeatures()).crossReferences();
        if (eStructuralFeatures != null) {
            for (EStructuralFeature crossRef : eStructuralFeatures) {
                operationCanceledManager.checkCanceled(monitor);
                resolveLazyCrossReference(source, crossRef);
            }
        }
    }
}
Also used : EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Aggregations

CancelIndicator (org.eclipse.xtext.util.CancelIndicator)18 URI (org.eclipse.emf.common.util.URI)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 BuildManager (org.eclipse.xtext.ide.server.BuildManager)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 ICodeLensResolver (org.eclipse.xtext.ide.server.codelens.ICodeLensResolver)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)2 Binder (com.google.inject.Binder)1 AnnotatedBindingBuilder (com.google.inject.binder.AnnotatedBindingBuilder)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1