Skip to content
Closed
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 @@ -25,8 +25,6 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.link.LinkedModeModel;
import org.eclipse.jface.text.link.LinkedPosition;
import org.eclipse.jface.text.link.LinkedPositionGroup;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -120,20 +118,27 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
"Linked rename mode did not start"
);

LinkedModeModel model = LinkedModeModel.getModel(document, offset);

// Replace the text at the primary linked position
// LinkedModeModel will automatically propagate this to other linked positions
display.syncExec(() -> {
try {
for (LinkedPositionGroup group : getLinkedPositionGroups(model)) {
for (LinkedPosition pos : group.getPositions()) {
document.replace(pos.getOffset(), pos.getLength(), newName);
}
}
document.replace(offset, oldName.length(), newName);
} catch (Exception e) {
throw new RuntimeException(e);
}
});

// Wait for linked editing to propagate changes to all occurrences
assertTrue(
DisplayHelper.waitForCondition(display, 3000, () -> {
String currentContent = document.get();
// Check if all occurrences of oldName have been replaced with newName
return !currentContent.contains(oldName) && currentContent.contains(newName);
}),
"Linked editing did not propagate changes to all occurrences"
);

// Press Enter to confirm the rename
display.syncExec(() -> {
ITextViewer viewer = editor.getAdapter(ITextViewer.class);
Event enter = new Event();
Expand All @@ -147,32 +152,5 @@ private void internalTestRename(IFile file, String content, String oldName, Stri
"Rename not applied to document"
);
}

// LinkedModeModel has no public API to access position groups at this JFace Text level, so tests must use reflection.
@SuppressWarnings("unchecked")
private static LinkedPositionGroup[] getLinkedPositionGroups(LinkedModeModel model) {
try {
for (String fieldName : new String[] { "fGroups", "fPositionGroups" }) {
try {
var field = LinkedModeModel.class.getDeclaredField(fieldName);
field.setAccessible(true);
Object value = field.get(model);

if (value instanceof LinkedPositionGroup[]) {
return (LinkedPositionGroup[]) value;
}
if (value instanceof java.util.List<?>) {
return ((java.util.List<LinkedPositionGroup>) value)
.toArray(new LinkedPositionGroup[0]);
}
} catch (NoSuchFieldException e) {
// try next name
}
}
throw new IllegalStateException("No linked position groups found in LinkedModeModel");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.lsp4j.DocumentDiagnosticParams;
import org.eclipse.lsp4j.DocumentDiagnosticReport;
import org.eclipse.lsp4j.FullDocumentDiagnosticReport;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.RelatedFullDocumentDiagnosticReport;
import org.eclipse.lsp4j.TextDocumentIdentifier;
Expand Down Expand Up @@ -248,7 +249,7 @@ private static synchronized void applyMarkers(final IFile file, final List<Diagn
}

for (final Diagnostic d : diagnostics) {
final String msg = d.getMessage();
final String msg = getMessageString(d);
final int severity = toIMarkerSeverity(d.getSeverity());
final int line = d.getRange() != null ? d.getRange().getStart().getLine() + 1 : 1;
int charStart = -1, charEnd = -1;
Expand Down Expand Up @@ -291,6 +292,19 @@ private static synchronized void applyMarkers(final IFile file, final List<Diagn
}
}

private static String getMessageString(final Diagnostic diagnostic) {
final Either<String, MarkupContent> message = diagnostic.getMessage();
if (message == null) {
return "";
}
if (message.isLeft()) {
return message.getLeft();
}
// Right side is MarkupContent
final MarkupContent markup = message.getRight();
return markup != null ? markup.getValue() : "";
}

private static void clearMarkers(final IFile file) throws CoreException {
file.deleteMarkers(MARKDOWN_MARKER_TYPE, true, IResource.DEPTH_ZERO);
}
Expand Down
2 changes: 1 addition & 1 deletion target-platform/target-platform.target
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<unit id="org.eclipse.lsp4j.debug" version="0.0.0"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/cbi/updates/license/"/>
<repository location="https://download.eclipse.org/cbi/updates/license/"/>
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
</location>
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" label="Apache Commons Compress" missingManifest="error" type="Maven">
Expand Down
Loading