Skip to content

Commit 814fabb

Browse files
committed
Adapt to new LSP4J v. 1.0.0 API
For the sake of simplicity, for now, we only use the left argument in Either tuples, i.e. the types that we used in earlier versions.
1 parent 13edd66 commit 814fabb

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/diagnostics/DiagnosticsTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.lsp4e.test.diagnostics;
1515

16-
import static org.eclipse.lsp4e.test.utils.TestUtils.waitForAndAssertCondition;
17-
import static org.hamcrest.CoreMatchers.is;
18-
import static org.hamcrest.MatcherAssert.assertThat;
19-
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
import static org.junit.jupiter.api.Assertions.assertNull;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
16+
import static org.eclipse.lsp4e.test.utils.TestUtils.*;
17+
import static org.hamcrest.CoreMatchers.*;
18+
import static org.hamcrest.MatcherAssert.*;
19+
import static org.junit.jupiter.api.Assertions.*;
2220

2321
import java.nio.file.Files;
2422
import java.nio.file.Path;
@@ -107,7 +105,7 @@ public void testDiagnostics() throws CoreException {
107105
assertEquals(markerCharStart, MarkerUtilities.getCharStart(marker.get()));
108106
assertEquals(markerCharEnd, MarkerUtilities.getCharEnd(marker.get()));
109107
assertEquals(markerLineIndex + 1, MarkerUtilities.getLineNumber(marker.get()));
110-
assertEquals(diagnostic.getMessage() + " [" + diagnostic.getCode().get() + "]",
108+
assertEquals(diagnostic.getMessage().getLeft() + " [" + diagnostic.getCode().get() + "]",
111109
MarkerUtilities.getMessage(marker.get()));
112110
}
113111

@@ -233,7 +231,7 @@ public void testDiagnosticsRangeAfterDocument() throws CoreException {
233231
Diagnostic diagnostic = diagnostics.get(i);
234232
IMarker marker = markers[i];
235233

236-
assertEquals(diagnostic.getMessage() + " [" + diagnostic.getCode().get() + "]",
234+
assertEquals(diagnostic.getMessage().getLeft() + " [" + diagnostic.getCode().get() + "]",
237235
MarkerUtilities.getMessage(marker));
238236
assertEquals(content.length(), MarkerUtilities.getCharStart(marker));
239237
assertEquals(content.length(), MarkerUtilities.getCharEnd(marker));

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/edit/LSPEclipseUtilsTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.lsp4e.test.edit;
1515

16-
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.junit.jupiter.api.Assertions.assertFalse;
18-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
19-
import static org.junit.jupiter.api.Assertions.assertNotNull;
20-
import static org.junit.jupiter.api.Assertions.assertNull;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.*;
17+
import static org.junit.jupiter.api.Assumptions.*;
2218

2319
import java.io.ByteArrayInputStream;
2420
import java.io.ByteArrayOutputStream;
@@ -138,8 +134,9 @@ public void testWorkspaceEdit_CreateAndPopulateFile() throws Exception {
138134
String uri = file.getLocation().toFile().toURI().toString();
139135
edits.add(Either.forRight(new CreateFile(uri)));
140136
edits.add(Either.forLeft(
141-
new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, null), List.of(
142-
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "abcHere\nabcHere2")))));
137+
new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, null),
138+
List.of(Either.forLeft(
139+
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "abcHere\nabcHere2"))))));
143140
final var workspaceEdit = new WorkspaceEdit(edits);
144141
// they should be applied from bottom to top
145142
LSPEclipseUtils.applyWorkspaceEdit(workspaceEdit);
@@ -358,8 +355,8 @@ public void testResourceOperations() throws Exception {
358355
assertTrue(targetFile.exists());
359356
LSPEclipseUtils.applyWorkspaceEdit(new WorkspaceEdit(List.of(Either.forLeft(
360357
new TextDocumentEdit(new VersionedTextDocumentIdentifier(targetFile.getLocationURI().toString(), 1),
361-
List.of(
362-
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "hello")))))));
358+
List.of(Either.forLeft(
359+
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "hello"))))))));
363360
assertEquals("hello", readContent(targetFile));
364361
IFile otherFile = project.getFile("another/folder/file.lol");
365362
LSPEclipseUtils.applyWorkspaceEdit(new WorkspaceEdit(List.of(Either.forRight(
@@ -386,7 +383,7 @@ public void editExternalFile(@TempDir Path tempDir) throws Exception {
386383
te.setNewText("abc\ndef");
387384
final var docEdit = new TextDocumentEdit(
388385
new VersionedTextDocumentIdentifier(file.toUri().toString(), null),
389-
List.of(te));
386+
List.of(Either.forLeft(te)));
390387
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
391388
LSPEclipseUtils.applyWorkspaceEdit(we);
392389
assertTrue(Files.isRegularFile(file));
@@ -425,7 +422,7 @@ public void testTextEditDoesntAutomaticallySaveOpenResourceFiles() throws Except
425422
te.setNewText("abc\ndef");
426423
final var docEdit = new TextDocumentEdit(
427424
new VersionedTextDocumentIdentifier(LSPEclipseUtils.toUri(targetFile).toString(), null),
428-
List.of(te));
425+
List.of(Either.forLeft(te)));
429426
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
430427
LSPEclipseUtils.applyWorkspaceEdit(we);
431428
assertEquals("abc\ndef", ((StyledText) ((AbstractTextEditor) editor).getAdapter(Control.class)).getText());
@@ -441,7 +438,7 @@ public void testTextEditDoesntAutomaticallySaveOpenExternalFiles(@TempDir Path t
441438
te.setNewText("abc\ndef");
442439
final var docEdit = new TextDocumentEdit(
443440
new VersionedTextDocumentIdentifier(file.toUri().toString(), null),
444-
List.of(te));
441+
List.of(Either.forLeft(te)));
445442
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
446443
LSPEclipseUtils.applyWorkspaceEdit(we);
447444
assertEquals("abc\ndef", ((StyledText) ((AbstractTextEditor) editor).getAdapter(Control.class)).getText());

org.eclipse.lsp4e/src/org/eclipse/lsp4e/IMarkerAttributeComputer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.eclipse.core.resources.IResource;
1717
import org.eclipse.jdt.annotation.Nullable;
1818
import org.eclipse.jface.text.IDocument;
19+
import org.eclipse.lsp4e.internal.NullSafetyHelper;
1920
import org.eclipse.lsp4j.Diagnostic;
2021
import org.eclipse.lsp4j.jsonrpc.messages.Either;
2122

@@ -48,8 +49,9 @@ void addMarkerAttributesForDiagnostic(Diagnostic diagnostic, @Nullable IDocument
4849
*/
4950
default String computeMarkerMessage(Diagnostic diagnostic) {
5051
final Either<String, Integer> code = diagnostic.getCode();
52+
String messageText = NullSafetyHelper.defaultIfNull(diagnostic.getMessage().getLeft(), ""); //$NON-NLS-1$
5153
return code == null //
52-
? diagnostic.getMessage()
53-
: diagnostic.getMessage() + " [" + code.get() + "]"; //$NON-NLS-1$//$NON-NLS-2$
54+
? messageText
55+
: messageText + " [" + code.get() + "]"; //$NON-NLS-1$//$NON-NLS-2$
5456
}
5557
}

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*******************************************************************************/
2222
package org.eclipse.lsp4e;
2323

24-
import static org.eclipse.lsp4e.internal.NullSafetyHelper.castNonNull;
24+
import static org.eclipse.lsp4e.internal.NullSafetyHelper.*;
2525

2626
import java.io.ByteArrayInputStream;
2727
import java.io.ByteArrayOutputStream;
@@ -120,6 +120,7 @@
120120
import org.eclipse.lsp4j.RenameFile;
121121
import org.eclipse.lsp4j.ResourceOperation;
122122
import org.eclipse.lsp4j.SignatureHelpParams;
123+
import org.eclipse.lsp4j.SnippetTextEdit;
123124
import org.eclipse.lsp4j.TextDocumentEdit;
124125
import org.eclipse.lsp4j.TextDocumentIdentifier;
125126
import org.eclipse.lsp4j.TextDocumentPositionParams;
@@ -1093,7 +1094,8 @@ private static boolean applyWorkspaceEditIfSingleOpenFile(WorkspaceEdit wsEdit)
10931094
.map(TextDocumentIdentifier::getUri)
10941095
.map(LSPEclipseUtils::toUri)
10951096
.forEach(documentUris::add);
1096-
firstDocumentEdits.addAll(wsEdit.getDocumentChanges().get(0).getLeft().getEdits());
1097+
firstDocumentEdits.addAll(toTextEditList(
1098+
wsEdit.getDocumentChanges().get(0).getLeft().getEdits()));
10971099
}
10981100
}
10991101
if (documentUris.size() != 1 || firstDocumentEdits.isEmpty()) {
@@ -1155,7 +1157,7 @@ private static CompositeChange toCompositeChange(WorkspaceEdit wsEdit, String na
11551157
TextDocumentEdit edit = action.getLeft();
11561158
VersionedTextDocumentIdentifier id = edit.getTextDocument();
11571159
URI uri = URI.create(id.getUri());
1158-
List<TextEdit> textEdits = edit.getEdits();
1160+
List<TextEdit> textEdits = toTextEditList(edit.getEdits());
11591161
change.add(toChanges(uri, textEdits));
11601162
collectChangedURI(uri, textEdits, collector);
11611163
} else if (action.isRight()) {
@@ -1253,6 +1255,13 @@ private static CompositeChange toCompositeChange(WorkspaceEdit wsEdit, String na
12531255
return change;
12541256
}
12551257

1258+
private static final List<TextEdit> toTextEditList(List<Either<TextEdit, SnippetTextEdit>> textEdits) {
1259+
return textEdits.stream()
1260+
.filter(e -> e.isLeft())
1261+
.map(e -> e.getLeft())
1262+
.toList();
1263+
}
1264+
12561265
private static final Range DEFAULT_RANGE = new Range(new Position(0, 0), new Position(0, 0));
12571266

12581267
/**

0 commit comments

Comments
 (0)