Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Collectors;
Expand All @@ -41,7 +42,12 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.ide.IDE;
Expand Down Expand Up @@ -70,12 +76,27 @@ public void setUpProject() throws CoreException {
project.open(null);
}

/**
* Waits until the language server has parsed the document as opened, so that
* a following edit does not race with the parse triggered by didOpen (which
* can leave LemMinX with a stale model and no diagnostics for the edit).
*/
private static void waitForDocumentParsed(IDocument document) throws Exception {
assertFalse(LanguageServers.forDocument(document) //
.withCapability(ServerCapabilities::getDocumentSymbolProvider) //
.collectAll(ls -> ls.getTextDocumentService().documentSymbol(new DocumentSymbolParams(
new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString())))) //
.get(5, TimeUnit.SECONDS).isEmpty(), "No language server answered for the document");
}

@Test
public void testXMLFile() throws Exception {
final IFile file = project.getFile("blah.xml");
file.create("FAIL".getBytes(), true, false, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<plugin></");
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
waitForDocumentParsed(document);
document.set("<plugin></");
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
Expand All @@ -88,9 +109,11 @@ public void testXMLFile() throws Exception {
@Test
public void testXSLFile() throws Exception {
final IFile file = project.getFile("blah.xsl");
file.create("FAIL".getBytes(), true, false, null);
file.create(new byte[0], true, false, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
waitForDocumentParsed(document);
document.set("FAIL");
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
Expand All @@ -103,9 +126,11 @@ public void testXSLFile() throws Exception {
@Test
public void testXSDFile() throws Exception {
final IFile file = project.getFile("blah.xsd");
file.create("FAIL".getBytes(), true, false, null);
file.create(new byte[0], true, false, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
waitForDocumentParsed(document);
document.set("a<");
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
Expand All @@ -120,7 +145,9 @@ public void testDTDFile() throws Exception {
final IFile file = project.getFile("blah.dtd");
file.create("FAIL".getBytes(), true, false, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<!--<!-- -->");
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
waitForDocumentParsed(document);
document.set("<!--<!-- -->");
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
Expand Down
Loading