Skip to content

Commit d93a4e4

Browse files
authored
fix: add tests for NES annotation type mapping and update plugin.xml for foreign text marker (#29)
1 parent 834bcde commit d93a4e4

3 files changed

Lines changed: 83 additions & 5 deletions

File tree

com.microsoft.copilot.eclipse.ui.test/plugin.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.4"?>
33
<plugin>
4+
<extension
5+
id="foreignTextMarker"
6+
name="Foreign Text Marker"
7+
point="org.eclipse.core.resources.markers">
8+
<super
9+
type="org.eclipse.core.resources.textmarker">
10+
</super>
11+
<persistent
12+
value="false">
13+
</persistent>
14+
</extension>
15+
416
<extension
517
point="org.eclipse.ui.editors">
618
<editor
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package com.microsoft.copilot.eclipse.ui.nes;
5+
6+
import static org.junit.jupiter.api.Assertions.assertFalse;
7+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
11+
import org.eclipse.core.resources.IMarker;
12+
import org.eclipse.core.runtime.IConfigurationElement;
13+
import org.eclipse.core.runtime.IExtensionPoint;
14+
import org.eclipse.core.runtime.Platform;
15+
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
16+
import org.junit.jupiter.api.Test;
17+
18+
class NesAnnotationTypeMappingTest {
19+
20+
private static final String ANNOTATION_TYPES_EXTENSION_POINT = "org.eclipse.ui.editors.annotationTypes";
21+
private static final String FOREIGN_TEXT_MARKER =
22+
"com.microsoft.copilot.eclipse.ui.test.foreignTextMarker";
23+
private static final String NES_ANNOTATION_PREFIX = "com.microsoft.copilot.eclipse.ui.nes.";
24+
private static final String NES_CHANGE_ANNOTATION = NES_ANNOTATION_PREFIX + "change";
25+
private static final String NES_DELETE_ANNOTATION = NES_ANNOTATION_PREFIX + "delete";
26+
private static final String ROOT_TEXT_MARKER = "org.eclipse.core.resources.textmarker";
27+
28+
@Test
29+
void testForeignTextMarkerSubtypeDoesNotResolveToNesAnnotations() {
30+
AnnotationTypeLookup lookup = new AnnotationTypeLookup();
31+
32+
String annotationType = lookup.getAnnotationType(FOREIGN_TEXT_MARKER, IMarker.SEVERITY_INFO);
33+
34+
assertNotEquals(NES_CHANGE_ANNOTATION, annotationType);
35+
assertNotEquals(NES_DELETE_ANNOTATION, annotationType);
36+
}
37+
38+
@Test
39+
void testNesAnnotationTypesDoNotMapToRootTextMarker() {
40+
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
41+
.getExtensionPoint(ANNOTATION_TYPES_EXTENSION_POINT);
42+
assertNotNull(extensionPoint);
43+
assertTrue(hasNesAnnotationType(extensionPoint, NES_CHANGE_ANNOTATION));
44+
assertTrue(hasNesAnnotationType(extensionPoint, NES_DELETE_ANNOTATION));
45+
assertFalse(hasNesRootTextMarkerMapping(extensionPoint));
46+
}
47+
48+
private boolean hasNesAnnotationType(IExtensionPoint extensionPoint, String annotationType) {
49+
for (IConfigurationElement element : extensionPoint.getConfigurationElements()) {
50+
if ("type".equals(element.getName()) && annotationType.equals(element.getAttribute("name"))) {
51+
return true;
52+
}
53+
}
54+
return false;
55+
}
56+
57+
private boolean hasNesRootTextMarkerMapping(IExtensionPoint extensionPoint) {
58+
for (IConfigurationElement element : extensionPoint.getConfigurationElements()) {
59+
String annotationType = element.getAttribute("name");
60+
if ("type".equals(element.getName()) && annotationType != null
61+
&& annotationType.startsWith(NES_ANNOTATION_PREFIX)
62+
&& ROOT_TEXT_MARKER.equals(element.getAttribute("markerType"))) {
63+
return true;
64+
}
65+
}
66+
return false;
67+
}
68+
}

com.microsoft.copilot.eclipse.ui/plugin.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,10 @@
10481048
<!-- Annotation types for Next Edit Suggestions -->
10491049
<extension point="org.eclipse.ui.editors.annotationTypes">
10501050
<type
1051-
name="com.microsoft.copilot.eclipse.ui.nes.change"
1052-
markerType="org.eclipse.core.resources.textmarker">
1051+
name="com.microsoft.copilot.eclipse.ui.nes.change">
10531052
</type>
10541053
<type
1055-
name="com.microsoft.copilot.eclipse.ui.nes.delete"
1056-
markerType="org.eclipse.core.resources.textmarker">
1054+
name="com.microsoft.copilot.eclipse.ui.nes.delete">
10571055
</type>
10581056
</extension>
10591057

@@ -1113,4 +1111,4 @@
11131111
<description>%theme.chatFont.description</description>
11141112
</fontDefinition>
11151113
</extension>
1116-
</plugin>
1114+
</plugin>

0 commit comments

Comments
 (0)