Skip to content

Commit

Permalink
External tool file modifications not registered (#1665)
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored Mar 5, 2021
1 parent 093f25e commit 1783bf3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal.handlers;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -97,6 +96,14 @@ public void run(IProgressMonitor monitor) throws CoreException {
}
if (unit != null) {
if (unit.isWorkingCopy()) {
try {
IResource resource = unit.getUnderlyingResource();
if (resource != null && resource.exists()) {
resource.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
continue;
}
if (changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CHANGED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Collections;
import java.util.List;

import com.google.common.io.Files;

import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
Expand All @@ -49,6 +49,8 @@
import org.junit.Test;
import org.mockito.Mock;

import com.google.common.io.Files;

public class WorkspaceEventHandlerTest extends AbstractProjectsManagerBasedTest {
private CoreASTProvider sharedASTProvider;
private DocumentLifeCycleHandler lifeCycleHandler;
Expand Down Expand Up @@ -77,6 +79,29 @@ public void tearDown() throws Exception {
}
}

@Test
public void testChangeWorkingCopy() throws Exception {
importProjects("eclipse/hello");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("hello");
// IJavaProject javaProject = JavaCore.create(project);
IFile file = project.getFile("src/org/sample/Foo.java");
ICompilationUnit unit = (ICompilationUnit) JavaCore.create(file);
String source = unit.getSource();
openDocument(unit, source, 1);
File projectFile = project.getRawLocation().toFile();
File classFile = new File(projectFile, "bin/org/sample/Foo.class");
long lastModified = classFile.lastModified();
assertTrue(lastModified > 0);
source = source.replace("world", "world2");
File javaFile = new File(projectFile, "src/org/sample/Foo.java");
FileUtils.writeStringToFile(javaFile, source);
String uri = JDTUtils.toURI(unit);
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(Arrays.asList(new FileEvent(uri, FileChangeType.Changed)));
new WorkspaceEventsHandler(projectsManager, javaClient, lifeCycleHandler).didChangeWatchedFiles(params);
waitForBackgroundJobs();
assertTrue(classFile.lastModified() > lastModified);
}

@Test
public void testDiscardStaleWorkingCopies() throws Exception {
IJavaProject javaProject = newEmptyProject();
Expand Down

0 comments on commit 1783bf3

Please sign in to comment.