Skip to content

Commit 47ec245

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 c820a83 commit 47ec245

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +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;
22-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
23-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
16+
import static org.junit.jupiter.api.Assertions.*;
17+
import static org.junit.jupiter.api.Assumptions.*;
2418

2519
import java.io.ByteArrayInputStream;
2620
import java.io.ByteArrayOutputStream;
@@ -138,8 +132,9 @@ public void testWorkspaceEdit_CreateAndPopulateFile() throws Exception {
138132
String uri = file.getLocation().toFile().toURI().toString();
139133
edits.add(Either.forRight(new CreateFile(uri)));
140134
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")))));
135+
new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, null),
136+
List.of(Either.forLeft(
137+
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "abcHere\nabcHere2"))))));
143138
final var workspaceEdit = new WorkspaceEdit(edits);
144139
// they should be applied from bottom to top
145140
LSPEclipseUtils.applyWorkspaceEdit(workspaceEdit);
@@ -358,8 +353,8 @@ public void testResourceOperations() throws Exception {
358353
assertTrue(targetFile.exists());
359354
LSPEclipseUtils.applyWorkspaceEdit(new WorkspaceEdit(List.of(Either.forLeft(
360355
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")))))));
356+
List.of(Either.forLeft(
357+
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "hello"))))))));
363358
assertEquals("hello", readContent(targetFile));
364359
IFile otherFile = project.getFile("another/folder/file.lol");
365360
LSPEclipseUtils.applyWorkspaceEdit(new WorkspaceEdit(List.of(Either.forRight(
@@ -388,7 +383,7 @@ public void editExternalFile() throws Exception {
388383
te.setNewText("abc\ndef");
389384
final var docEdit = new TextDocumentEdit(
390385
new VersionedTextDocumentIdentifier(file.toURI().toString(), null),
391-
List.of(te));
386+
List.of(Either.forLeft(te)));
392387
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
393388
LSPEclipseUtils.applyWorkspaceEdit(we);
394389
assertTrue(file.isFile());
@@ -428,7 +423,7 @@ public void testTextEditDoesntAutomaticallySaveOpenResourceFiles() throws Except
428423
te.setNewText("abc\ndef");
429424
final var docEdit = new TextDocumentEdit(
430425
new VersionedTextDocumentIdentifier(LSPEclipseUtils.toUri(targetFile).toString(), null),
431-
List.of(te));
426+
List.of(Either.forLeft(te)));
432427
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
433428
LSPEclipseUtils.applyWorkspaceEdit(we);
434429
assertEquals("abc\ndef", ((StyledText) ((AbstractTextEditor) editor).getAdapter(Control.class)).getText());
@@ -444,7 +439,7 @@ public void testTextEditDoesntAutomaticallySaveOpenExternalFiles() throws Except
444439
te.setNewText("abc\ndef");
445440
final var docEdit = new TextDocumentEdit(
446441
new VersionedTextDocumentIdentifier(file.toURI().toString(), null),
447-
List.of(te));
442+
List.of(Either.forLeft(te)));
448443
final var we = new WorkspaceEdit(List.of(Either.forLeft(docEdit)));
449444
LSPEclipseUtils.applyWorkspaceEdit(we);
450445
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)