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
6 changes: 4 additions & 2 deletions org.eclipse.lsp4e.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Bundle-Vendor: Eclipse LSP4E
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.junit,
org.eclipse.ui,
org.eclipse.ui.workbench,
org.eclipse.ui.ide,
Expand All @@ -29,5 +28,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.ui.workbench,
org.eclipse.tm4e.ui,
org.eclipse.core.filesystem
org.eclipse.core.filesystem,
junit-jupiter-api,
org.hamcrest,
org.opentest4j
Automatic-Module-Name: org.eclipse.lsp4e.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*******************************************************************************/
package org.eclipse.lsp4e.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

Expand All @@ -21,22 +21,22 @@
import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4e.test.utils.AbstractTest;
import org.eclipse.lsp4e.test.utils.TestUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class ContentTypeToLanguageServerDefinitionTest extends AbstractTest {

public static final String SERVER_TO_DISABLE = "org.eclipse.lsp4e.test.server.disable";
public static final String DISABLED_CONTENT_TYPE = "org.eclipse.lsp4e.test.content-type-disabled";
public static final String DISABLED_SERVER_PREF = SERVER_TO_DISABLE + "/" + DISABLED_CONTENT_TYPE;

@BeforeClass
@BeforeAll
public static void setup() {
LanguageServerPlugin.getDefault().getPreferenceStore().setValue(DISABLED_SERVER_PREF, "false");
}

@AfterClass
@AfterAll
public static void cleanup() {
TestUtils.getDisabledLS().setUserEnabled(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import static org.eclipse.lsp4e.test.utils.TestUtils.waitForAndAssertCondition;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;
Expand All @@ -31,14 +32,14 @@
import org.eclipse.lsp4e.test.utils.TestUtils;
import org.eclipse.lsp4e.tests.mock.MockConnectionProviderMultiRootFolders;
import org.eclipse.ui.IEditorPart;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class LanguageServerWrapperTest extends AbstractTestWithProject {

private IProject project2;

@Before
@BeforeEach
public void setUp() throws Exception {
project2 = TestUtils.createProject("LanguageServerWrapperTestProject2" + System.currentTimeMillis());
}
Expand Down Expand Up @@ -134,7 +135,7 @@ public void testStartStopAndActive() throws CoreException, AssertionError {
Integer cpStartCount= MockConnectionProviderMultiRootFolders.getStartCount();
Integer cpStopCount= MockConnectionProviderMultiRootFolders.getStopCount();

assertEquals("startCount == stopCount", cpStartCount, cpStopCount);
assertEquals(cpStartCount, cpStopCount, "startCount == stopCount");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
package org.eclipse.lsp4e.test;

import static org.eclipse.lsp4e.LanguageServiceAccessor.hasActiveLanguageServers;
import static org.eclipse.lsp4e.test.utils.TestUtils.*;
import static org.junit.Assert.*;
import static org.eclipse.lsp4e.test.utils.TestUtils.createUniqueTestFile;
import static org.eclipse.lsp4e.test.utils.TestUtils.openEditor;
import static org.eclipse.lsp4e.test.utils.TestUtils.waitForCondition;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -55,8 +63,7 @@
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LanguageServersTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -172,11 +179,11 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
.withCapability(ServerCapabilities::getHoverProvider)
.computeAll(ls -> ls.getTextDocumentService().hover(params).thenApply(h -> h.getContents().getLeft().get(0).getLeft()));

assertEquals("Should have had two responses", 2, result.size());
assertEquals(2, result.size(), "Should have had two responses");

final Object first = CompletableFuture.anyOf(result.get(0), result.get(1)).join();

assertEquals("HoverContent1 should have returned first, independently", "HoverContent1", first);
assertEquals("HoverContent1", first, "HoverContent1 should have returned first, independently");

List<String> hovers = result.stream().map(CompletableFuture::join).toList();

Expand All @@ -195,7 +202,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
@Test
public void testCollectAllUserCannotBlockListener() throws Exception {
// This test will only work if a minimum of two tasks can be run in the common pool without blocking!
Assume.assumeTrue("Test skipped as common thread pool does not have multiple executors", ForkJoinPool.commonPool().getParallelism() >= 2);
assumeTrue(ForkJoinPool.commonPool().getParallelism() >= 2, "Test skipped as common thread pool does not have multiple executors");
final var hoverResponse = new Hover(List.of(Either.forLeft("HoverContent")), new Range(new Position(0, 0), new Position(0, 10)));
MockLanguageServer.INSTANCE.setHover(hoverResponse);

Expand Down Expand Up @@ -235,8 +242,8 @@ public void testCollectAllUserCannotBlockListener() throws Exception {

final String resultThread = resultThreadFuture.join();

assertTrue("Second hover response should not have been blocked by the first but took " + secondResponseTime + " ms", secondResponseTime < 1000);
assertTrue("Result should not have run on an LS listener thread but ran on " + resultThread, !resultThread.startsWith("LS"));
assertTrue(secondResponseTime < 1000, "Second hover response should not have been blocked by the first but took " + secondResponseTime + " ms");
assertTrue(!resultThread.startsWith("LS"), "Result should not have run on an LS listener thread but ran on " + resultThread);
}

@Test
Expand Down Expand Up @@ -283,7 +290,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
Optional<String> result = response.join();
assertTrue(result.isPresent());

assertEquals("HoverContent1 should have arrived first", "HoverContent1", result.get());
assertEquals("HoverContent1", result.get(), "HoverContent1 should have arrived first");

// It won't *normally) matter in production but because the tests run quickly, make sure the test teardown doesn't
// occur before the slower, ignored result has completed, otherwise will get a load of console noise
Expand Down Expand Up @@ -331,9 +338,9 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
.computeFirst(ls -> ls.getTextDocumentService().hover(params).thenApply(h -> h == null ? null : h.getContents().getLeft().get(0).getLeft()));

Optional<String> result = response.join();
assertTrue("Should have returned a result", result.isPresent());
assertTrue(result.isPresent(), "Should have returned a result");

assertEquals("HoverContent2 should have been the result", "HoverContent2", result.get());
assertEquals("HoverContent2", result.get(), "HoverContent2 should have been the result");

}

Expand Down Expand Up @@ -366,7 +373,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
.computeFirst(ls -> ls.getTextDocumentService().hover(params).thenApply(h -> h == null ? null : h.getContents().getLeft().get(0).getLeft()));

Optional<String> result = response.join();
assertTrue("Should not have returned a result", result.isEmpty());
assertTrue(result.isEmpty(), "Should not have returned a result");
}

@Test
Expand Down Expand Up @@ -410,9 +417,9 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
.computeFirst(ls -> ls.getTextDocumentService().hover(params).thenApply(h -> h == null ? Collections.emptyList() : List.of(h.getContents().getLeft().get(0).getLeft())));

Optional<List<String>> result = response.join();
assertTrue("Should have returned a result", result.isPresent());
assertTrue(result.isPresent(), "Should have returned a result");

assertEquals("HoverContent2 should have been the result", "HoverContent2", result.get().get(0));
assertEquals("HoverContent2", result.get().get(0), "HoverContent2 should have been the result");
}

/**
Expand Down Expand Up @@ -492,7 +499,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
message.append(" Too Late " );message.append(i);
message.append(System.lineSeparator());
});
assertTrue(message.toString(), tooEarlyHover.isEmpty() && tooLateHover.isEmpty());
assertTrue(tooEarlyHover.isEmpty() && tooLateHover.isEmpty(), message.toString());
}

/**
Expand Down Expand Up @@ -580,8 +587,8 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {

final long finishTime = System.currentTimeMillis() - startTime;

assertTrue(String.format("Dispatch should not have blocked but took %d ms vs overall test time of %d ms", dispatchTime, finishTime), dispatchTime < 1000);
assertEquals("Should not have been any messages dispatched on UI thread", 0, uiDispatchCount.get());
assertTrue(dispatchTime < 1000, String.format("Dispatch should not have blocked but took %d ms vs overall test time of %d ms", dispatchTime, finishTime));
assertEquals(0, uiDispatchCount.get(), "Should not have been any messages dispatched on UI thread");
}

@Test
Expand All @@ -590,7 +597,7 @@ public void testAnyMatchingIsNonBlocking() throws Exception {
long start = System.currentTimeMillis();
assertFalse(LanguageServers.forProject(project).anyMatching());
long duration = System.currentTimeMillis() - start;
assertTrue("LanguageServers.anyMatching() took too long: " + duration + "ms", duration < 100);
assertTrue(duration < 100, "LanguageServers.anyMatching() took too long: " + duration + "ms");

// test with one slow LS available
MockLanguageServer.INSTANCE.setTimeToProceedQueries(5_000);
Expand All @@ -600,7 +607,7 @@ public void testAnyMatchingIsNonBlocking() throws Exception {
try {
assertTrue(LanguageServers.forProject(project).anyMatching());
duration = System.currentTimeMillis() - start;
assertTrue("LanguageServers.anyMatching() took too long: " + duration + "ms", duration < 100);
assertTrue(duration < 100, "LanguageServers.anyMatching() took too long: " + duration + "ms");
} finally {
editor1.getSite().getPage().closeEditor(editor1, false);
}
Expand All @@ -617,7 +624,7 @@ public void testNoMatchingServers() throws Exception {

LanguageServerDocumentExecutor executor = LanguageServers.forDocument(document).withFilter(sc -> false);

assertFalse("Should not have been any valid LS", executor.anyMatching());
assertFalse(executor.anyMatching(), "Should not have been any valid LS");

final var params = new HoverParams();
final var position = new Position();
Expand All @@ -626,10 +633,10 @@ public void testNoMatchingServers() throws Exception {
params.setPosition(position);

Optional<?> result = executor.computeFirst(ls -> ls.getTextDocumentService().hover(params)).get(10, TimeUnit.SECONDS);
assertFalse("Should not have had a result", result.isPresent());
assertFalse(result.isPresent(), "Should not have had a result");

List<?> collectedResult = executor.collectAll(ls -> ls.getTextDocumentService().hover(params)).get(10, TimeUnit.SECONDS);
assertTrue("Should not have had a result", collectedResult.isEmpty());
assertTrue(collectedResult.isEmpty(), "Should not have had a result");

List<CompletableFuture<Hover>> allResults = executor.computeAll(ls -> ls.getTextDocumentService().hover(params));
for (CompletableFuture<Hover> f : allResults) {
Expand All @@ -638,7 +645,7 @@ public void testNoMatchingServers() throws Exception {
}
}

@Test(expected=CompletionException.class)
@Test
public void testComputeFirstBubblesException() throws Exception {
MockLanguageServer.INSTANCE.setTextDocumentService(new MockTextDocumentService(MockLanguageServer.INSTANCE::buildMaybeDelayedFuture) {
@Override
Expand All @@ -664,11 +671,14 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
position.setLine(0);
params.setPosition(position);

CompletableFuture<Optional<String>> response = LanguageServers.forDocument(document)
.withCapability(ServerCapabilities::getHoverProvider)
.computeFirst(ls -> ls.getTextDocumentService().hover(params).thenApply(h -> h == null ? null : h.getContents().getLeft().get(0).getLeft()));
assertThrows(CompletionException.class, () -> {
CompletableFuture<Optional<String>> response = LanguageServers.forDocument(document)
.withCapability(ServerCapabilities::getHoverProvider)
.computeFirst(ls -> ls.getTextDocumentService().hover(params)
.thenApply(h -> h == null ? null : h.getContents().getLeft().get(0).getLeft()));

response.join();
response.join();
});
}

/**
Expand Down Expand Up @@ -700,8 +710,8 @@ public void testWrapperWrapsSameLS() throws Exception {

final var matching = new AtomicInteger();

assertEquals("Should have had two responses", 2, result.size());
assertNotEquals("LS should have been different proxies", result.get(0).second(), result.get(1).second());
assertEquals(2, result.size(), "Should have had two responses");
assertNotEquals(result.get(0).second(), result.get(1).second(), "LS should have been different proxies");
result.forEach(p -> {
p.first().execute(ls -> {
if (ls == p.second()) {
Expand All @@ -711,7 +721,7 @@ public void testWrapperWrapsSameLS() throws Exception {
}).join();
});

assertEquals("Wrapper should have used same LS", 2, matching.get());
assertEquals(2, matching.get(), "Wrapper should have used same LS");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,26 @@
*******************************************************************************/
package org.eclipse.lsp4e.test;

import static org.eclipse.lsp4e.LSPEclipseUtils.*;
import static org.eclipse.lsp4e.LanguageServiceAccessor.*;
import static org.eclipse.lsp4e.test.utils.TestUtils.*;
import static org.junit.Assert.*;
import static org.eclipse.lsp4e.LSPEclipseUtils.getDocument;
import static org.eclipse.lsp4e.LSPEclipseUtils.getTextViewer;
import static org.eclipse.lsp4e.LanguageServiceAccessor.getLSPDocumentInfosFor;
import static org.eclipse.lsp4e.LanguageServiceAccessor.getLSWrapper;
import static org.eclipse.lsp4e.LanguageServiceAccessor.getLSWrappers;
import static org.eclipse.lsp4e.LanguageServiceAccessor.hasActiveLanguageServers;
import static org.eclipse.lsp4e.test.utils.TestUtils.createFile;
import static org.eclipse.lsp4e.test.utils.TestUtils.createProject;
import static org.eclipse.lsp4e.test.utils.TestUtils.createTempFile;
import static org.eclipse.lsp4e.test.utils.TestUtils.createUniqueTestFile;
import static org.eclipse.lsp4e.test.utils.TestUtils.createUniqueTestFileMultiLS;
import static org.eclipse.lsp4e.test.utils.TestUtils.openEditor;
import static org.eclipse.lsp4e.test.utils.TestUtils.openTextViewer;
import static org.eclipse.lsp4e.test.utils.TestUtils.waitForAndAssertCondition;
import static org.eclipse.lsp4e.test.utils.TestUtils.waitForCondition;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
Expand All @@ -41,7 +57,7 @@
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LanguageServiceAccessorTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -130,8 +146,8 @@ public void testReuseSameLSforMultiContentType() throws Exception {
var file1LS = file1LanguageServers.get(0).serverDefinition;
assertTrue(file2LanguageServers.contains(file1LS)); // LS from file1 is reused

assertEquals("Not right amount of language servers bound to project", 2,
LanguageServers.forProject(project).computeAll(ls -> CompletableFuture.completedFuture(null)).size());
assertEquals(2, LanguageServers.forProject(project).computeAll(ls -> CompletableFuture.completedFuture(null)).size(),
"Not right amount of language servers bound to project");
}

@Test
Expand Down Expand Up @@ -317,7 +333,7 @@ public void testLanguageServerHierarchy_parentContentTypeUsed() throws Exception
var servers = getLSWrappers(testFile, MATCH_ALL);
var iterator = servers.iterator();
assertEquals("org.eclipse.lsp4e.test.server", iterator.next().serverDefinition.id);
assertFalse("Should only be a single LS", iterator.hasNext());
assertFalse(iterator.hasNext(), "Should only be a single LS");
}

@Test
Expand Down
Loading
Loading