Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #718 from eclipse/cd_issue716
Browse files Browse the repository at this point in the history
[#716] [LSP] Problems for a deleted file are shown after deletion
  • Loading branch information
cdietrich authored Apr 26, 2018
2 parents 64be133 + be7a958 commit 3dbf100
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ public void testIncrementalBuildWithError() {
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().values(), ","), IterableExtensions.<List<Diagnostic>>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.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>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.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
_workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
Assert.assertTrue(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()).isEmpty());
}

@Test
public void testMissingInitialize() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -285,10 +286,22 @@ public void testDelete_01() {
URI _uri = this.uri("src/B.indextestlanguage");
it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uri)));
final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri);
Assert.assertTrue(issues.toString(), IterableExtensions.<Issue>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.<Issue>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);
};
Expand Down Expand Up @@ -329,11 +342,23 @@ public void testDeleteClearsReusedResourceSet() {
URI _uri = this.uri("src/B.indextestlanguage");
it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uri)));
final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri);
String _string = issues.toString();
Assert.assertTrue(_string, ((!IterableExtensions.isEmpty(issues)) && IterableExtensions.<Issue>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.<Issue>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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public IncrementalBuilder.Result launch() {
}
}
final Consumer<URI> _function = (URI source) -> {
this.request.getAfterValidate().afterValidate(source, CollectionLiterals.<Issue>newArrayList());
final Consumer<URI> _function_1 = (URI generated) -> {
try {
boolean _isInfoEnabled = IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.isInfoEnabled();
Expand Down

0 comments on commit 3dbf100

Please sign in to comment.