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 @@ -21,7 +21,6 @@
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;
Expand All @@ -34,6 +33,8 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
Expand All @@ -58,6 +59,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class LanguageServiceAccessorTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -368,10 +370,10 @@ public void testLanguageServerEnablementTester() throws Exception {
}

@Test
public void testLSforExternalThenLocalFile() throws Exception {
public void testLSforExternalThenLocalFile(@TempDir Path tempDir) throws Exception {
var wb = UI.getActiveWindow();
var local = createTempFile("testLSforExternalThenLocalFile", ".lspt");
var editor = (ITextEditor) IDE.openEditorOnFileStore(wb.getActivePage(), EFS.getStore(local.toURI()));
var local = Files.createFile(tempDir.resolve("testLSforExternalThenLocalFile.lspt"));
var editor = (ITextEditor) IDE.openEditorOnFileStore(wb.getActivePage(), EFS.getStore(local.toUri()));

Predicate<ServerCapabilities> hasHoverCapabilities = capabilities -> {
var hoverProvider = capabilities.getHoverProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import static org.eclipse.lsp4e.test.utils.TestUtils.waitForAndAssertCondition;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.eclipse.core.filesystem.EFS;
Expand All @@ -37,6 +37,7 @@
import org.eclipse.ui.ide.IDE;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class ColorTest extends AbstractTestWithProject {

Expand All @@ -56,12 +57,9 @@ public void testColorProvider() throws Exception {
}

@Test
public void testColorProviderExternalFile() throws Exception {
File file = TestUtils.createTempFile("testColorProviderExternalFile", ".lspt");
try (var out = new FileOutputStream(file)) {
out.write("\u2588\u2588\u2588\u2588\u2588".getBytes());
}
ITextViewer viewer = LSPEclipseUtils.getTextViewer(IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI())));
public void testColorProviderExternalFile(@TempDir Path tempDir) throws Exception {
Path file = Files.write(tempDir.resolve("testColorProviderExternalFile.lspt"), "\u2588\u2588\u2588\u2588\u2588".getBytes());
ITextViewer viewer = LSPEclipseUtils.getTextViewer(IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri())));
StyledText widget = viewer.getTextWidget();
waitForAndAssertCondition(3_000, widget.getDisplay(), () -> containsColor(widget, color, 10));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -56,6 +57,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class IncompleteCompletionTest extends AbstractCompletionTest {
/*
Expand Down Expand Up @@ -566,13 +568,13 @@ public void testCompletionWithAdditionalTextEditInsertion() throws Exception {
}

@Test
public void testCompletionExternalFile() throws Exception {
public void testCompletionExternalFile(@TempDir Path tempDir) throws Exception {
final var items = new ArrayList<CompletionItem>();
items.add(createCompletionItem("FirstClassExternal", CompletionItemKind.Class));
MockLanguageServer.INSTANCE.setCompletionList(new CompletionList(true, items));

File file = TestUtils.createTempFile("testCompletionExternalFile", ".lspt");
final var editor = (ITextEditor) IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
Path file = Files.createFile(tempDir.resolve("testCompletionExternalFile.lspt"));
final var editor = (ITextEditor) IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(viewer, 0);
assertEquals(1, proposals.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -41,6 +42,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DefinitionTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -82,12 +84,12 @@ public void testDefinitionAndTypeDefinition() throws Exception {
}

@Test
public void testDefinitionOneLocationExternalFile() throws Exception {
public void testDefinitionOneLocationExternalFile(@TempDir Path tempDir) throws Exception {
final var location = new Location("file://test", new Range(new Position(0, 0), new Position(0, 10)));
MockLanguageServer.INSTANCE.setDefinition(List.of(location));

File file = TestUtils.createTempFile("testDocumentLinkExternalFile", ".lspt");
final var editor = (ITextEditor) IDE.openInternalEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
Path file = Files.createFile(tempDir.resolve("testDocumentLinkExternalFile.lspt"));
final var editor = (ITextEditor) IDE.openInternalEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);

IHyperlink[] hyperlinks = hyperlinkDetector.detectHyperlinks(viewer, new Region(0, 0), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -62,6 +62,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DiagnosticsTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -336,15 +337,12 @@ public void testDiagnosticRedrawingCalls() throws CoreException {
}

@Test
public void testDiagnosticsOnExternalFile() throws Exception {
public void testDiagnosticsOnExternalFile(@TempDir Path tempDir) throws Exception {
MockLanguageServer.INSTANCE.setDiagnostics(List.of(new Diagnostic(new Range(new Position(0, 0), new Position(0, 1)), "This is a warning", DiagnosticSeverity.Warning, null)));
File file = TestUtils.createTempFile("testDiagnosticsOnExternalFile", ".lspt");
Path file = Files.writeString(tempDir.resolve("testDiagnosticsOnExternalFile.lspt"), "a");
Font font = null;
try {
try (var out = new FileOutputStream(file);) {
out.write('a');
}
ITextViewer viewer = LSPEclipseUtils.getTextViewer(IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI())));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri())));
StyledText widget = viewer.getTextWidget();
final var biggerFont = new FontData(); // bigger font to keep color intact in some pixel (not altered by anti-aliasing)
biggerFont.setHeight(40);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;

import org.eclipse.core.filesystem.EFS;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DocumentLinkTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -63,13 +65,13 @@ public void testDocumentLink() throws Exception {
}

@Test
public void testDocumentLinkExternalFile() throws Exception {
public void testDocumentLinkExternalFile(@TempDir Path tempDir) throws Exception {
final var links = new ArrayList<DocumentLink>();
links.add(new DocumentLink(new Range(new Position(0, 9), new Position(0, 15)), "file://test0"));
MockLanguageServer.INSTANCE.setDocumentLinks(links);

File file = TestUtils.createTempFile("testDocumentLinkExternalFile", ".lspt");
final var editor = (ITextEditor) IDE.openInternalEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
Path file = Files.createFile(tempDir.resolve("testDocumentLinkExternalFile.lspt"));
final var editor = (ITextEditor) IDE.openInternalEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);
viewer.getDocument().set("Long enough dummy content to match ranges");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;

Expand All @@ -39,6 +40,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ide.IDE;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DocumentDidChangeTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -193,12 +195,12 @@ public boolean test(ServerCapabilities t) {
}

@Test
public void testFullSyncExternalFile() throws Exception {
public void testFullSyncExternalFile(@TempDir Path tempDir) throws Exception {
MockLanguageServer.INSTANCE.getInitializeResult().getCapabilities()
.setTextDocumentSync(TextDocumentSyncKind.Full);

File file = TestUtils.createTempFile("testFullSyncExternalFile", ".lspt");
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
Path file = Files.createFile(tempDir.resolve("testFullSyncExternalFile.lspt"));
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);
LanguageServers.forDocument(viewer.getDocument()).withFilter(new Predicate<ServerCapabilities>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -31,6 +32,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ide.IDE;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DocumentDidCloseTest extends AbstractTestWithProject {

Expand All @@ -54,9 +56,9 @@ public void testClose() throws Exception {
}

@Test
public void testCloseExternalFile() throws Exception {
File testFile = TestUtils.createTempFile("testCloseExternalFile", ".lspt");
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(testFile.toURI()));
public void testCloseExternalFile(@TempDir Path tempDir) throws Exception {
Path testFile = Files.createFile(tempDir.resolve("testCloseExternalFile.lspt"));
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(testFile.toUri()));

// Force LS to initialize and open file
LanguageServers.forDocument(LSPEclipseUtils.getDocument(editor.getEditorInput())).anyMatching();
Expand All @@ -68,6 +70,6 @@ public void testCloseExternalFile() throws Exception {

DidCloseTextDocumentParams lastChange = didCloseExpectation.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(lastChange.getTextDocument());
assertEquals(LSPEclipseUtils.toUri(testFile).toString(), lastChange.getTextDocument().getUri());
assertEquals(LSPEclipseUtils.toUri(testFile.toFile()).toString(), lastChange.getTextDocument().getUri());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -32,6 +33,7 @@
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DocumentDidOpenTest extends AbstractTestWithProject {

Expand All @@ -55,11 +57,11 @@ public void testOpen() throws Exception {
}

@Test
public void testOpenExternalFile() throws Exception {
File file = TestUtils.createTempFile("testOpenExternalFile", ".lspt");
public void testOpenExternalFile(@TempDir Path tempDir) throws Exception {
Path file = Files.createFile(tempDir.resolve("testOpenExternalFile.lspt"));
final var didOpenExpectation = new CompletableFuture<DidOpenTextDocumentParams>();
MockLanguageServer.INSTANCE.setDidOpenCallback(didOpenExpectation);
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
// Force LS to initialize and open file
LanguageServers.forDocument(LSPEclipseUtils.getDocument(editor.getEditorInput())).anyMatching();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -35,6 +36,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ide.IDE;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DocumentDidSaveTest extends AbstractTestWithProject {

Expand Down Expand Up @@ -67,9 +69,9 @@ public void testSave() throws Exception {
}

@Test
public void testSaveExternalFile() throws Exception {
File file = TestUtils.createTempFile("testSaveExternalFile", ".lspt");
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toURI()));
public void testSaveExternalFile(@TempDir Path tempDir) throws Exception {
Path file = Files.createFile(tempDir.resolve("testSaveExternalFile.lspt"));
IEditorPart editor = IDE.openEditorOnFileStore(UI.getActivePage(), EFS.getStore(file.toUri()));
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);

// make sure that timestamp after save will differ from creation time (no better idea at the moment)
Expand All @@ -87,7 +89,7 @@ public void testSaveExternalFile() throws Exception {
waitForAndAssertCondition(2_000, () -> {
DidSaveTextDocumentParams lastChange = didSaveExpectation.get(10, TimeUnit.MILLISECONDS);
assertNotNull(lastChange.getTextDocument());
assertEquals(LSPEclipseUtils.toUri(file).toString(), lastChange.getTextDocument().getUri());
assertEquals(LSPEclipseUtils.toUri(file.toFile()).toString(), lastChange.getTextDocument().getUri());
return true;
});
}
Expand Down
Loading