Skip to content
Merged
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
12 changes: 12 additions & 0 deletions com.microsoft.copilot.eclipse.ui.test/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="foreignTextMarker"
name="Foreign Text Marker"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.textmarker">
</super>
<persistent
value="false">
</persistent>
</extension>

<extension
point="org.eclipse.ui.editors">
<editor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

package com.microsoft.copilot.eclipse.ui.nes;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
import org.junit.jupiter.api.Test;

class NesAnnotationTypeMappingTest {

private static final String ANNOTATION_TYPES_EXTENSION_POINT = "org.eclipse.ui.editors.annotationTypes";
private static final String FOREIGN_TEXT_MARKER =
"com.microsoft.copilot.eclipse.ui.test.foreignTextMarker";
private static final String NES_ANNOTATION_PREFIX = "com.microsoft.copilot.eclipse.ui.nes.";
private static final String NES_CHANGE_ANNOTATION = NES_ANNOTATION_PREFIX + "change";
private static final String NES_DELETE_ANNOTATION = NES_ANNOTATION_PREFIX + "delete";
private static final String ROOT_TEXT_MARKER = "org.eclipse.core.resources.textmarker";

@Test
void testForeignTextMarkerSubtypeDoesNotResolveToNesAnnotations() {
AnnotationTypeLookup lookup = new AnnotationTypeLookup();

String annotationType = lookup.getAnnotationType(FOREIGN_TEXT_MARKER, IMarker.SEVERITY_INFO);

assertNotEquals(NES_CHANGE_ANNOTATION, annotationType);
assertNotEquals(NES_DELETE_ANNOTATION, annotationType);
}

@Test
void testNesAnnotationTypesDoNotMapToRootTextMarker() {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(ANNOTATION_TYPES_EXTENSION_POINT);
assertNotNull(extensionPoint);
assertTrue(hasNesAnnotationType(extensionPoint, NES_CHANGE_ANNOTATION));
assertTrue(hasNesAnnotationType(extensionPoint, NES_DELETE_ANNOTATION));
assertFalse(hasNesRootTextMarkerMapping(extensionPoint));
}

private boolean hasNesAnnotationType(IExtensionPoint extensionPoint, String annotationType) {
for (IConfigurationElement element : extensionPoint.getConfigurationElements()) {
if ("type".equals(element.getName()) && annotationType.equals(element.getAttribute("name"))) {
return true;
}
}
return false;
}

private boolean hasNesRootTextMarkerMapping(IExtensionPoint extensionPoint) {
for (IConfigurationElement element : extensionPoint.getConfigurationElements()) {
String annotationType = element.getAttribute("name");
if ("type".equals(element.getName()) && annotationType != null
&& annotationType.startsWith(NES_ANNOTATION_PREFIX)
&& ROOT_TEXT_MARKER.equals(element.getAttribute("markerType"))) {
return true;
}
}
return false;
}
}
8 changes: 3 additions & 5 deletions com.microsoft.copilot.eclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,10 @@
<!-- Annotation types for Next Edit Suggestions -->
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
name="com.microsoft.copilot.eclipse.ui.nes.change"
markerType="org.eclipse.core.resources.textmarker">
name="com.microsoft.copilot.eclipse.ui.nes.change">
</type>
<type
name="com.microsoft.copilot.eclipse.ui.nes.delete"
markerType="org.eclipse.core.resources.textmarker">
name="com.microsoft.copilot.eclipse.ui.nes.delete">
</type>
</extension>

Expand Down Expand Up @@ -1113,4 +1111,4 @@
<description>%theme.chatFont.description</description>
</fontDefinition>
</extension>
</plugin>
</plugin>
Loading