forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust unit tests accordingly. Fixes eclipse-lemminx#699. Signed-off-by: Balduin Landolt <balduin.landolt@hotmail.com>
- Loading branch information
1 parent
3342ed0
commit 3a5fe37
Showing
6 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
.../main/java/org/eclipse/lemminx/services/snippets/ProcessingInstructionSnippetContext.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,66 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Balduin Landolt 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: | ||
* Balduin Landolt - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
|
||
package org.eclipse.lemminx.services.snippets; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.dom.DOMNode; | ||
import org.eclipse.lemminx.services.extensions.ICompletionRequest; | ||
import org.eclipse.lemminx.utils.DOMUtils; | ||
|
||
/** | ||
* Snippet context used to filter if Processing Instruction Snippets should be triggered or not. | ||
* | ||
*/ | ||
public class ProcessingInstructionSnippetContext implements IXMLSnippetContext { | ||
|
||
public static IXMLSnippetContext DEFAULT_CONTEXT = new ProcessingInstructionSnippetContext(); | ||
|
||
@Override | ||
public boolean isMatch(ICompletionRequest request, Map<String, String> model) { | ||
DOMNode node = request.getNode(); | ||
int offset = request.getOffset(); | ||
if ((node.isComment() || node.isDoctype() || node.isProlog() || node.isProcessingInstruction()) && offset < node.getEnd()) { | ||
// completion was triggered inside comment, doctype, prolog or processing instruction | ||
return false; | ||
} | ||
|
||
if (node.getParentNode() != null && node.getParentNode().isDoctype()) { | ||
// completion was triggered after element inside doctype | ||
return false; | ||
} | ||
|
||
DOMDocument document = request.getXMLDocument(); | ||
DOMElement documentElement = document.getDocumentElement(); | ||
|
||
if (document.isDTD() || DOMUtils.isXSD(document)) { | ||
// triggered in a DTD or XSD file | ||
return false; | ||
} | ||
|
||
if (document.hasProlog() && offset == 0){ | ||
// triggered before prolog | ||
return false; | ||
} | ||
|
||
if (documentElement != null && documentElement.getTagName() != null) { | ||
return offset <= documentElement.getStart(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
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
24 changes: 24 additions & 0 deletions
24
...main/resources/org/eclipse/lemminx/services/snippets/processing-instruction-snippets.json
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,24 @@ | ||
{ | ||
"Insert XML Model: XSD": { | ||
"prefix": [ | ||
"<?xml-model" | ||
], | ||
"suffix": "?>", | ||
"body": [ | ||
"<?xml-model href=\"${1:file.xsd}\" type=\"application/xml\" schematypens=\"http://www.w3.org/2001/XMLSchema\"?>${0}" | ||
], | ||
"label": "Insert XML Schema association", | ||
"description": "Insert XML Model Processing Instruction to Associate XSD Schema" | ||
}, | ||
"Insert XML Model: DTD": { | ||
"prefix": [ | ||
"<?xml-model" | ||
], | ||
"suffix": "?>", | ||
"body": [ | ||
"<?xml-model href=\"${1:file.dtd}\" type=\"application/xml-dtd\"?>${0}" | ||
], | ||
"label": "Insert DTD association", | ||
"description": "Insert XML Model Processing Instruction to Associate Document Type Description (DTD)" | ||
} | ||
} |
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
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