Skip to content

Commit fdcf0fd

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 2133c7b commit fdcf0fd

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.io.File;
2422
import java.io.FileOutputStream;
@@ -106,7 +104,7 @@ public void testDiagnostics() throws CoreException {
106104
assertEquals(markerCharStart, MarkerUtilities.getCharStart(marker.get()));
107105
assertEquals(markerCharEnd, MarkerUtilities.getCharEnd(marker.get()));
108106
assertEquals(markerLineIndex + 1, MarkerUtilities.getLineNumber(marker.get()));
109-
assertEquals(diagnostic.getMessage() + " [" + diagnostic.getCode().get() + "]",
107+
assertEquals(diagnostic.getMessage().getLeft() + " [" + diagnostic.getCode().get() + "]",
110108
MarkerUtilities.getMessage(marker.get()));
111109
}
112110

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

235-
assertEquals(diagnostic.getMessage() + " [" + diagnostic.getCode().get() + "]",
233+
assertEquals(diagnostic.getMessage().getLeft() + " [" + diagnostic.getCode().get() + "]",
236234
MarkerUtilities.getMessage(marker));
237235
assertEquals(content.length(), MarkerUtilities.getCharStart(marker));
238236
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(
@@ -388,7 +385,7 @@ public void editExternalFile() throws Exception {
388385
te.setNewText("abc\ndef");
389386
final var docEdit = new TextDocumentEdit(
390387
new VersionedTextDocumentIdentifier(file.toURI().toString(), null),
391-
List.of(te));
388+
List.of(Either.forLeft(te)));
392389
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
393390
LSPEclipseUtils.applyWorkspaceEdit(we);
394391
assertTrue(file.isFile());
@@ -428,7 +425,7 @@ public void testTextEditDoesntAutomaticallySaveOpenResourceFiles() throws Except
428425
te.setNewText("abc\ndef");
429426
final var docEdit = new TextDocumentEdit(
430427
new VersionedTextDocumentIdentifier(LSPEclipseUtils.toUri(targetFile).toString(), null),
431-
List.of(te));
428+
List.of(Either.forLeft(te)));
432429
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
433430
LSPEclipseUtils.applyWorkspaceEdit(we);
434431
assertEquals("abc\ndef", ((StyledText) ((AbstractTextEditor) editor).getAdapter(Control.class)).getText());
@@ -444,7 +441,7 @@ public void testTextEditDoesntAutomaticallySaveOpenExternalFiles() throws Except
444441
te.setNewText("abc\ndef");
445442
final var docEdit = new TextDocumentEdit(
446443
new VersionedTextDocumentIdentifier(file.toURI().toString(), null),
447-
List.of(te));
444+
List.of(Either.forLeft(te)));
448445
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
449446
LSPEclipseUtils.applyWorkspaceEdit(we);
450447
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;
@@ -121,6 +121,7 @@
121121
import org.eclipse.lsp4j.RenameFile;
122122
import org.eclipse.lsp4j.ResourceOperation;
123123
import org.eclipse.lsp4j.SignatureHelpParams;
124+
import org.eclipse.lsp4j.SnippetTextEdit;
124125
import org.eclipse.lsp4j.TextDocumentEdit;
125126
import org.eclipse.lsp4j.TextDocumentIdentifier;
126127
import org.eclipse.lsp4j.TextDocumentPositionParams;
@@ -1078,7 +1079,8 @@ private static boolean applyWorkspaceEditIfSingleOpenFile(WorkspaceEdit wsEdit)
10781079
.map(TextDocumentIdentifier::getUri)
10791080
.map(LSPEclipseUtils::toUri)
10801081
.forEach(documentUris::add);
1081-
firstDocumentEdits.addAll(wsEdit.getDocumentChanges().get(0).getLeft().getEdits());
1082+
firstDocumentEdits.addAll(toTextEditList(
1083+
wsEdit.getDocumentChanges().get(0).getLeft().getEdits()));
10821084
}
10831085
}
10841086
if (documentUris.size() != 1 || firstDocumentEdits.isEmpty()) {
@@ -1140,7 +1142,7 @@ private static CompositeChange toCompositeChange(WorkspaceEdit wsEdit, String na
11401142
TextDocumentEdit edit = action.getLeft();
11411143
VersionedTextDocumentIdentifier id = edit.getTextDocument();
11421144
URI uri = URI.create(id.getUri());
1143-
List<TextEdit> textEdits = edit.getEdits();
1145+
List<TextEdit> textEdits = toTextEditList(edit.getEdits());
11441146
change.add(toChanges(uri, textEdits));
11451147
collectChangedURI(uri, textEdits, collector);
11461148
} else if (action.isRight()) {
@@ -1238,6 +1240,13 @@ private static CompositeChange toCompositeChange(WorkspaceEdit wsEdit, String na
12381240
return change;
12391241
}
12401242

1243+
private static final List<TextEdit> toTextEditList(List<Either<TextEdit, SnippetTextEdit>> textEdits) {
1244+
return textEdits.stream()
1245+
.filter(e -> e.isLeft())
1246+
.map(e -> e.getLeft())
1247+
.toList();
1248+
}
1249+
12411250
private static final Range DEFAULT_RANGE = new Range(new Position(0, 0), new Position(0, 0));
12421251

12431252
/**

0 commit comments

Comments
 (0)