Skip to content

Commit bbbe1fe

Browse files
RedeemerSKrubenporras
authored andcommitted
Fix disabled test in DocumentLinkReconcilingTest
Also adds new test that considers visible region alignment by ProjectionViewer. Fixes #1470
1 parent 9e91838 commit bbbe1fe

1 file changed

Lines changed: 54 additions & 4 deletions

File tree

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkReconcilingTest.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.eclipse.lsp4j.Range;
3737
import org.eclipse.swt.custom.StyleRange;
3838
import org.eclipse.swt.graphics.Color;
39-
import org.junit.jupiter.api.Disabled;
4039
import org.junit.jupiter.api.Test;
4140

4241
public class DocumentLinkReconcilingTest extends AbstractTestWithProject {
@@ -138,16 +137,16 @@ public void testFullDocumentLinkReconciling() throws Exception {
138137
}
139138

140139
@Test
141-
@Disabled("Test faling because of SWT Exception due to invalid ranges")
142-
public void testClippedDocumentLinkReconciling() throws Exception {
140+
public void testMidLineClippedDocumentLinkReconciling() throws Exception {
143141
MockLanguageServer.INSTANCE.setDocumentLinks(CONTENT_LINKS);
144142

145-
TextViewer viewer = (TextViewer) TestUtils.openTextViewer(TestUtils.createUniqueTestFile(project, CONTENT));
143+
ProjectionViewer viewer = (ProjectionViewer) TestUtils.openTextViewer(TestUtils.createUniqueTestFile(project, CONTENT));
146144
IDocument doc = viewer.getDocument();
147145
int line5visibleLength = 21;
148146
int line3Start = doc.getLineOffset(2);
149147
int middleOfLink5 = doc.getLineOffset(4) + line5visibleLength;
150148
// set visible region to 3rd + 4th + half of 5th line, link1 + link6 + link7 are completely outside
149+
viewer.disableProjection(); // avoid ProjectionViewer aligning end of visible region to end of the last line
151150
viewer.setVisibleRegion(
152151
line3Start, // TextViewer would align start of visible region to start of the line anyway
153152
middleOfLink5 - line3Start);
@@ -187,6 +186,57 @@ public void testClippedDocumentLinkReconciling() throws Exception {
187186
assertEquals(textStyle(pos += len, len = 9, COLOR_5TH_LINE), styles[6]);
188187
assertEquals(linkStyle(pos += len, 12, COLOR_5TH_LINE), styles[7]);
189188
}
189+
190+
@Test
191+
public void testClippedDocumentLinkReconciling() throws Exception {
192+
MockLanguageServer.INSTANCE.setDocumentLinks(CONTENT_LINKS);
193+
194+
ProjectionViewer viewer = (ProjectionViewer) TestUtils.openTextViewer(TestUtils.createUniqueTestFile(project, CONTENT));
195+
IDocument doc = viewer.getDocument();
196+
// set visible region to 3rd + 4th + 5th line, link1 + link6 + link7 are completely outside
197+
// (ProjectionViewer by default aligns start/end of visible region to start/end of the lines)
198+
int line3Start = doc.getLineOffset(2);
199+
var line5Region = doc.getLineInformation(4);
200+
viewer.setVisibleRegion(
201+
line3Start,
202+
line5Region.getOffset() + line5Region.getLength() - line3Start);
203+
var pos = 0;
204+
var len = 0;
205+
viewer.getTextWidget().setStyleRanges(new StyleRange[] {
206+
textStyle(pos += len, len = doc.getLineLength(2), COLOR_3RD_LINE), // whole 3rd line
207+
textStyle(pos += len, len = doc.getLineLength(3), COLOR_4TH_LINE), // whole 4th line
208+
textStyle(pos += len, doc.getLineLength(4), COLOR_5TH_LINE) // whole 5th line
209+
});
210+
viewer.addTextPresentationListener(this::textPresentationListener);
211+
212+
waitForAndAssertTextPresentations(doc);
213+
214+
assertEquals(1, getStylesCount(textPresentations.get(0)));
215+
assertEquals(2, getStylesCount(textPresentations.get(1))); // link2 spans 2 lines, invisible 2nd and visible 3rd
216+
assertEquals(1, getStylesCount(textPresentations.get(2)));
217+
assertEquals(1, getStylesCount(textPresentations.get(3)));
218+
assertEquals(1, getStylesCount(textPresentations.get(4)));
219+
assertEquals(1, getStylesCount(textPresentations.get(5)));
220+
assertEquals(1, getStylesCount(textPresentations.get(6)));
221+
222+
var styles = viewer.getTextWidget().getStyleRanges();
223+
224+
assertEquals(9, styles.length);
225+
226+
pos = 0;
227+
len = 0;
228+
assertEquals(linkStyle(pos, len = 10, COLOR_3RD_LINE), styles[0]);
229+
assertEquals(textStyle(pos += len, len = 10, COLOR_3RD_LINE), styles[1]);
230+
assertEquals(linkStyle(pos += len, len = 6, COLOR_3RD_LINE), styles[2]);
231+
assertEquals(textStyle(pos += len, len = 9 + 1, COLOR_3RD_LINE), styles[3]); // also new line char
232+
233+
assertEquals(linkStyle(pos += len, len = 6, COLOR_4TH_LINE), styles[4]);
234+
assertEquals(textStyle(pos += len, len = 1, COLOR_4TH_LINE), styles[5]); // new line char
235+
236+
assertEquals(textStyle(pos += len, len = 9, COLOR_5TH_LINE), styles[6]);
237+
assertEquals(linkStyle(pos += len, len = 23, COLOR_5TH_LINE), styles[7]);
238+
assertEquals(textStyle(pos += len, 1, COLOR_5TH_LINE), styles[8]); // new line char
239+
}
190240

191241
@Test
192242
public void testDocumentWithFoldingLinkReconciling() throws Exception {

0 commit comments

Comments
 (0)