|
36 | 36 | import org.eclipse.lsp4j.Range; |
37 | 37 | import org.eclipse.swt.custom.StyleRange; |
38 | 38 | import org.eclipse.swt.graphics.Color; |
39 | | -import org.junit.jupiter.api.Disabled; |
40 | 39 | import org.junit.jupiter.api.Test; |
41 | 40 |
|
42 | 41 | public class DocumentLinkReconcilingTest extends AbstractTestWithProject { |
@@ -138,16 +137,16 @@ public void testFullDocumentLinkReconciling() throws Exception { |
138 | 137 | } |
139 | 138 |
|
140 | 139 | @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 { |
143 | 141 | MockLanguageServer.INSTANCE.setDocumentLinks(CONTENT_LINKS); |
144 | 142 |
|
145 | | - TextViewer viewer = (TextViewer) TestUtils.openTextViewer(TestUtils.createUniqueTestFile(project, CONTENT)); |
| 143 | + ProjectionViewer viewer = (ProjectionViewer) TestUtils.openTextViewer(TestUtils.createUniqueTestFile(project, CONTENT)); |
146 | 144 | IDocument doc = viewer.getDocument(); |
147 | 145 | int line5visibleLength = 21; |
148 | 146 | int line3Start = doc.getLineOffset(2); |
149 | 147 | int middleOfLink5 = doc.getLineOffset(4) + line5visibleLength; |
150 | 148 | // 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 |
151 | 150 | viewer.setVisibleRegion( |
152 | 151 | line3Start, // TextViewer would align start of visible region to start of the line anyway |
153 | 152 | middleOfLink5 - line3Start); |
@@ -187,6 +186,57 @@ public void testClippedDocumentLinkReconciling() throws Exception { |
187 | 186 | assertEquals(textStyle(pos += len, len = 9, COLOR_5TH_LINE), styles[6]); |
188 | 187 | assertEquals(linkStyle(pos += len, 12, COLOR_5TH_LINE), styles[7]); |
189 | 188 | } |
| 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 | + } |
190 | 240 |
|
191 | 241 | @Test |
192 | 242 | public void testDocumentWithFoldingLinkReconciling() throws Exception { |
|
0 commit comments