diff --git a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend index 220da9f668..f3bcfae942 100644 --- a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend +++ b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend @@ -73,6 +73,23 @@ class ServerTest extends AbstractTestLangLanguageServerTest { assertTrue(diagnostics.values.join(','), diagnostics.values.forall[empty]) } + @Test + def void testIncrementalDeletion() { + val path = 'MyType1.testlang'.writeFile( ''' + type Test { + NonExisting foo + } + ''') + initialize + assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", + diagnostics.values.head.head.message) + 'MyType1.testlang'.deleteFile + languageServer.getWorkspaceService.didChangeWatchedFiles( + new DidChangeWatchedFilesParams(#[new FileEvent(path, FileChangeType.Deleted)]) + ) + assertTrue(diagnostics.values.head.empty) + } + @Test def void testMissingInitialize() { try { diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/ServerTest.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/ServerTest.java index 0f4740e6eb..0412ebbf0e 100644 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/ServerTest.java +++ b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/ServerTest.java @@ -104,6 +104,28 @@ public void testIncrementalBuildWithError() { Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().values(), ","), IterableExtensions.>forall(this.getDiagnostics().values(), _function)); } + @Test + public void testIncrementalDeletion() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("type Test {"); + _builder.newLine(); + _builder.append(" "); + _builder.append("NonExisting foo"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + final String path = this.writeFile("MyType1.testlang", _builder); + this.initialize(); + this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", + IterableExtensions.head(IterableExtensions.>head(this.getDiagnostics().values())).getMessage()); + this.deleteFile("MyType1.testlang"); + WorkspaceService _workspaceService = this.languageServer.getWorkspaceService(); + FileEvent _fileEvent = new FileEvent(path, FileChangeType.Deleted); + DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.unmodifiableList(CollectionLiterals.newArrayList(_fileEvent))); + _workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams); + Assert.assertTrue(IterableExtensions.>head(this.getDiagnostics().values()).isEmpty()); + } + @Test public void testMissingInitialize() { try { diff --git a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend index 44d35c23f0..a5a78caddd 100644 --- a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend +++ b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend @@ -210,6 +210,10 @@ abstract class AbstractLanguageServerTest implements Endpoint { return file.toURI.normalize.toUriString } + def void deleteFile(String path) { + new File(root, path).delete + } + def String getVirtualFile(String path) { val file = new File(root, path) return file.toURI.normalize.toUriString diff --git a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java index a3e06ccfc3..e63d9ac397 100644 --- a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java +++ b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java @@ -361,6 +361,10 @@ public String writeFile(final String path, final CharSequence contents) { } } + public void deleteFile(final String path) { + new File(this.root, path).delete(); + } + public String getVirtualFile(final String path) { final File file = new File(this.root, path); return this._uriExtensions.toUriString(file.toURI().normalize()); diff --git a/org.eclipse.xtext.tests/src/org/eclipse/xtext/build/IncrementalBuilderTest.xtend b/org.eclipse.xtext.tests/src/org/eclipse/xtext/build/IncrementalBuilderTest.xtend index b0a0e93fdf..27d2c678d8 100644 --- a/org.eclipse.xtext.tests/src/org/eclipse/xtext/build/IncrementalBuilderTest.xtend +++ b/org.eclipse.xtext.tests/src/org/eclipse/xtext/build/IncrementalBuilderTest.xtend @@ -209,10 +209,16 @@ class IncrementalBuilderTest extends AbstractIncrementalBuilderTest { build(newBuildRequest [ deletedFiles = #[uri('src/B.indextestlanguage')] afterValidate = [ uri, issues | - assertEquals(uri('src/A.indextestlanguage'), uri) - assertTrue(issues.toString, issues.head.message.contains("Couldn't resolve reference to Type 'foo.B'")) - validateCalled.set(true) - return false + if (uri('src/A.indextestlanguage') == uri) { + assertTrue(issues.toString, issues.head.message.contains("Couldn't resolve reference to Type 'foo.B'")) + validateCalled.set(true) + return false + } else if (uri('src/B.indextestlanguage') == uri) { + assertEquals("zero issues expected", 0, issues.size) + return true + } else { + throw new IllegalStateException("unexpected issues for " + uri) + } ] ]) assertTrue(validateCalled.get) @@ -241,10 +247,16 @@ class IncrementalBuilderTest extends AbstractIncrementalBuilderTest { build(newBuildRequest [ deletedFiles = #[uri('src/B.indextestlanguage')] afterValidate = [ uri, issues | - assertEquals(uri('src/A.indextestlanguage'), uri) - assertTrue(issues.toString, !issues.isEmpty && issues.head.message.contains("Couldn't resolve reference to Type 'foo.B'")) - validateCalled.set(true) - return false + if (uri('src/A.indextestlanguage') == uri) { + assertTrue(issues.toString, !issues.isEmpty && issues.head.message.contains("Couldn't resolve reference to Type 'foo.B'")) + validateCalled.set(true) + return false + } else if (uri('src/B.indextestlanguage') == uri) { + assertEquals("zero issues expected", 0, issues.size) + return true + } else { + throw new IllegalStateException("unexpected issues for " + uri) + } ] it.resourceSet = resourceSet val desc = ChunkedResourceDescriptions.findInEmfObject(it.resourceSet) diff --git a/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/build/IncrementalBuilderTest.java b/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/build/IncrementalBuilderTest.java index d47a4d3bcb..f19aa33e45 100644 --- a/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/build/IncrementalBuilderTest.java +++ b/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/build/IncrementalBuilderTest.java @@ -7,6 +7,7 @@ */ package org.eclipse.xtext.build; +import com.google.common.base.Objects; import com.google.inject.Inject; import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; @@ -285,10 +286,22 @@ public void testDelete_01() { URI _uri = this.uri("src/B.indextestlanguage"); it.setDeletedFiles(Collections.unmodifiableList(CollectionLiterals.newArrayList(_uri))); final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable issues) -> { - Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri); - Assert.assertTrue(issues.toString(), IterableExtensions.head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'")); - validateCalled.set(true); - return false; + URI _uri_1 = this.uri("src/A.indextestlanguage"); + boolean _equals = Objects.equal(_uri_1, uri); + if (_equals) { + Assert.assertTrue(issues.toString(), IterableExtensions.head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'")); + validateCalled.set(true); + return false; + } else { + URI _uri_2 = this.uri("src/B.indextestlanguage"); + boolean _equals_1 = Objects.equal(_uri_2, uri); + if (_equals_1) { + Assert.assertEquals("zero issues expected", 0, IterableExtensions.size(issues)); + return true; + } else { + throw new IllegalStateException(("unexpected issues for " + uri)); + } + } }; it.setAfterValidate(_function_2); }; @@ -329,11 +342,23 @@ public void testDeleteClearsReusedResourceSet() { URI _uri = this.uri("src/B.indextestlanguage"); it.setDeletedFiles(Collections.unmodifiableList(CollectionLiterals.newArrayList(_uri))); final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable issues) -> { - Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri); - String _string = issues.toString(); - Assert.assertTrue(_string, ((!IterableExtensions.isEmpty(issues)) && IterableExtensions.head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'"))); - validateCalled.set(true); - return false; + URI _uri_1 = this.uri("src/A.indextestlanguage"); + boolean _equals = Objects.equal(_uri_1, uri); + if (_equals) { + String _string = issues.toString(); + Assert.assertTrue(_string, ((!IterableExtensions.isEmpty(issues)) && IterableExtensions.head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'"))); + validateCalled.set(true); + return false; + } else { + URI _uri_2 = this.uri("src/B.indextestlanguage"); + boolean _equals_1 = Objects.equal(_uri_2, uri); + if (_equals_1) { + Assert.assertEquals("zero issues expected", 0, IterableExtensions.size(issues)); + return true; + } else { + throw new IllegalStateException(("unexpected issues for " + uri)); + } + } }; it.setAfterValidate(_function_2); it.setResourceSet(resourceSet); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/build/IncrementalBuilder.xtend b/org.eclipse.xtext/src/org/eclipse/xtext/build/IncrementalBuilder.xtend index 123b1f8adc..97f50c2988 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/build/IncrementalBuilder.xtend +++ b/org.eclipse.xtext/src/org/eclipse/xtext/build/IncrementalBuilder.xtend @@ -78,6 +78,7 @@ import org.eclipse.xtext.generator.GeneratorContext } } request.deletedFiles.forEach [ source | + request.afterValidate.afterValidate(source, newArrayList) newSource2GeneratedMapping.deleteSource(source).forEach [ generated | if (LOG.isInfoEnabled) LOG.info("Deleting " + generated) diff --git a/org.eclipse.xtext/xtend-gen/org/eclipse/xtext/build/IncrementalBuilder.java b/org.eclipse.xtext/xtend-gen/org/eclipse/xtext/build/IncrementalBuilder.java index b38fb16c25..a7974f6ef5 100644 --- a/org.eclipse.xtext/xtend-gen/org/eclipse/xtext/build/IncrementalBuilder.java +++ b/org.eclipse.xtext/xtend-gen/org/eclipse/xtext/build/IncrementalBuilder.java @@ -181,6 +181,7 @@ public IncrementalBuilder.Result launch() { } } final Consumer _function = (URI source) -> { + this.request.getAfterValidate().afterValidate(source, CollectionLiterals.newArrayList()); final Consumer _function_1 = (URI generated) -> { try { boolean _isInfoEnabled = IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.isInfoEnabled();