-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ICompletionParticipant#onXMLContent is not called for CDATA (#1699)
* fix: ICompletionParticipant#onXMLContent is not called for CDATA Signed-off-by: Christoph Läubrich <[email protected]>
- Loading branch information
Showing
3 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...inx/src/test/java/org/eclipse/lemminx/services/extensions/XMLCompletionExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import org.eclipse.lemminx.AbstractCacheBasedTest; | ||
import org.eclipse.lemminx.XMLAssert; | ||
import org.eclipse.lemminx.commons.BadLocationException; | ||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.dom.DOMNode; | ||
import org.eclipse.lemminx.services.XMLLanguageService; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionParticipant; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse; | ||
import org.eclipse.lsp4j.CompletionItem; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
import org.junit.jupiter.api.Test; | ||
import org.w3c.dom.CDATASection; | ||
|
||
/** | ||
* XML completion tests which uses the {@link ICompletionParticipant} | ||
*/ | ||
public class XMLCompletionExtensionTest extends AbstractCacheBasedTest { | ||
|
||
private static final CompletionItem HELLO_WORLD_ITEM = XMLAssert.c("World", "World"); | ||
|
||
private final class TestCompletionParticipant implements ICompletionParticipant { | ||
@Override | ||
public void onXMLContent(ICompletionRequest request, ICompletionResponse response, CancelChecker cancelChecker) | ||
throws Exception { | ||
if ("hello".equals(request.getCurrentTag())) { | ||
response.addCompletionAttribute(HELLO_WORLD_ITEM); | ||
} else { | ||
DOMNode node = request.getNode(); | ||
if (node instanceof CDATASection) { | ||
DOMElement element = node.getParentElement(); | ||
String tagName = element.getTagName(); | ||
if ("hello".equals(tagName)) { | ||
response.addCompletionAttribute(HELLO_WORLD_ITEM); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onTagOpen(ICompletionRequest completionRequest, ICompletionResponse completionResponse, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onDTDSystemId(String valuePrefix, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onAttributeName(boolean generateValue, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
} | ||
|
||
/** | ||
* Test that | ||
* {@link ICompletionParticipant#onXMLContent(ICompletionRequest, ICompletionResponse, CancelChecker)} | ||
* is called for a simple content tag | ||
* | ||
* @throws BadLocationException | ||
*/ | ||
@Test | ||
public void testSimpleCompletion() throws BadLocationException { | ||
XMLLanguageService service = new XMLLanguageService(); | ||
service.registerCompletionParticipant(new TestCompletionParticipant()); | ||
XMLAssert.testCompletionFor(service, "<hello>|</hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
} | ||
|
||
/** | ||
* Test that | ||
* {@link ICompletionParticipant#onXMLContent(ICompletionRequest, ICompletionResponse, CancelChecker)} | ||
* is called for a CDATA content tag | ||
* | ||
* @throws BadLocationException | ||
*/ | ||
@Test | ||
public void testCDATACompletion() throws BadLocationException { | ||
XMLLanguageService service = new XMLLanguageService(); | ||
service.registerCompletionParticipant(new TestCompletionParticipant()); | ||
// check cursor is at the end of cdata section | ||
XMLAssert.testCompletionFor(service, "<hello><![CDATA[ |]]></hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
// check cursor is at start of section | ||
XMLAssert.testCompletionFor(service, "<hello><![CDATA[| ]]></hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
// check cursor is inside of section | ||
XMLAssert.testCompletionFor(service, "<hello><![CDATA[ | ]]></hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
// check cursor is inside completely empty section | ||
XMLAssert.testCompletionFor(service, "<hello><![CDATA[|]]></hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
} | ||
|
||
} |