Skip to content
Merged
Show file tree
Hide file tree
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 @@ -84,22 +84,18 @@ void testAngularTs() throws Exception {
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return Arrays
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
IResource.DEPTH_ZERO))
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> {
try {
return Arrays
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
IResource.DEPTH_ZERO))
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"Diagnostic not published in standalone component file");
}), "Diagnostic not published in standalone component file");
editor.close(false);
}

Expand All @@ -118,21 +114,17 @@ void testAngularHtml() throws Exception {
// then make an edit
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.set(document.get() + "\n");
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
IMarker[] markers;
try {
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
return Arrays.stream(markers)
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> {
IMarker[] markers;
try {
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
return Arrays.stream(markers)
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"No error found on erroneous HTML component file");
}), "No error found on erroneous HTML component file");
// test completion
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,24 @@ void testESLintDiagnosticsInTSX() throws Exception {

private void assertESLintIndentMarkerExists(IFile file) throws PartInitException {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
e.printStackTrace();
return false;
}
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 10000), "Diagnostic not published");

assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO))
.stream().filter(Objects::nonNull)
.anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}), "Diagnostic not published");

assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return Arrays.asList(file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO))
.stream().filter(Objects::nonNull)
.anyMatch(m -> m.getAttribute(IMarker.MESSAGE, null).toLowerCase().contains("indentation"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic content is incorrect");
}), "Diagnostic content is incorrect");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,96 +35,81 @@
@ExtendWith(AllCleanRule.class)
public class TestHTML {

@Test
public void testHTMLFile() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published");
}
@Test
public void testHTMLFile() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}), "Diagnostic not published");
}

@Test
public void testFormat() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.setFocus();
editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
@Test
public void testFormat() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.setFocus();
editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
// assertTrue(PlatformUI.getWorkbench().getService(ICommandService.class).getCommand("org.eclipse.lsp4e.format")
// .isEnabled());
new DisplayHelper() {
@Override
protected boolean condition() {
try {
return PlatformUI.getWorkbench().getService(ICommandService.class)
.getCommand("org.eclipse.lsp4e.format").isEnabled();
} catch (Exception e) {
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, () -> {
try {
return PlatformUI.getWorkbench().getService(ICommandService.class)
.getCommand("org.eclipse.lsp4e.format").isEnabled();
} catch (Exception e) {
return false;
}
});

// AtomicReference<Exception> ex = new AtomicReference<>();
new DisplayHelper() {
@Override
protected boolean condition() {
try {
handlerService.executeCommand("org.eclipse.lsp4e.format", null);
return true;
} catch (Exception e) {
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, () -> {
try {
handlerService.executeCommand("org.eclipse.lsp4e.format", null);
return true;
} catch (Exception e) {
return false;
}
});
// if (ex.get() != null) {
// throw ex.get();
// }
new DisplayHelper() {
@Override
protected boolean condition() {
return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1;
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
}
DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000,
() -> editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1);
}

@Test
public void autoCloseTags() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("autoCloseTags.html");
file.create(new ByteArrayInputStream("<foo".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.replace(4, 0, ">");
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return "<foo></foo>".equals(document.get());
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Autoclose not done");
}
@Test
public void autoCloseTags() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("autoCloseTags.html");
file.create(new ByteArrayInputStream("<foo".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.replace(4, 0, ">");
assertTrue(
DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000,
() -> "<foo></foo>".equals(document.get())),
"Autoclose not done");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,24 @@
@ExtendWith(AllCleanRule.class)
public class TestJSON {

@Test
public void testFormatEnabled() throws IOException, PartInitException, CoreException {
File file = File.createTempFile("test", ".json");
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditorOnFileStore(activePage, EFS.getStore(file.toURI()));
ICommandService service = activePage.getWorkbenchWindow().getService(ICommandService.class);
Command formatCommand = service.getCommand("org.eclipse.lsp4e.format");
assertNotNull(formatCommand, "Format command not found");
assertTrue(formatCommand.isDefined(), "Format command not defined");
@Test
public void testFormatEnabled() throws IOException, PartInitException, CoreException {
File file = File.createTempFile("test", ".json");
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditorOnFileStore(activePage, EFS.getStore(file.toURI()));
ICommandService service = activePage.getWorkbenchWindow().getService(ICommandService.class);
Command formatCommand = service.getCommand("org.eclipse.lsp4e.format");
assertNotNull(formatCommand, "Format command not found");
assertTrue(formatCommand.isDefined(), "Format command not defined");
// assertTrue(formatCommand.isEnabled(), "Format command not enabled");
new DisplayHelper() {
@Override
protected boolean condition() {
try {
return formatCommand.isEnabled();
} catch (Exception e) {
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
assertTrue(formatCommand.isHandled(), "Format command not handled");
}
DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, () -> {
try {
return formatCommand.isEnabled();
} catch (Exception e) {
return false;
}
});
assertTrue(formatCommand.isHandled(), "Format command not handled");
}

}
Loading
Loading