-
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.
Adjust error for cvc-complex-type.4 + code action to add required
attributes (see #71)
- Loading branch information
1 parent
ee6621e
commit 41fb0a7
Showing
7 changed files
with
143 additions
and
30 deletions.
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
66 changes: 66 additions & 0 deletions
66
...g/eclipse/lsp4xml/contentmodel/participants/codeactions/cvc_complex_type_4CodeAction.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) 2018 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.contentmodel.participants.codeactions; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4xml.commons.CodeActionFactory; | ||
import org.eclipse.lsp4xml.contentmodel.model.CMAttributeDeclaration; | ||
import org.eclipse.lsp4xml.contentmodel.model.CMElementDeclaration; | ||
import org.eclipse.lsp4xml.contentmodel.model.ContentModelManager; | ||
import org.eclipse.lsp4xml.contentmodel.utils.XMLGenerator; | ||
import org.eclipse.lsp4xml.dom.Element; | ||
import org.eclipse.lsp4xml.dom.Node; | ||
import org.eclipse.lsp4xml.dom.XMLDocument; | ||
import org.eclipse.lsp4xml.services.extensions.ICodeActionParticipant; | ||
|
||
/** | ||
* Code action to fix cvc-complex-type.2.3 error. | ||
* | ||
*/ | ||
public class cvc_complex_type_4CodeAction implements ICodeActionParticipant { | ||
|
||
@Override | ||
public void doCodeAction(Diagnostic diagnostic, Range range, XMLDocument document, List<CodeAction> codeActions) { | ||
try { | ||
int offset = document.offsetAt(range.getStart()); | ||
Node node = document.findNodeAt(offset); | ||
if (!node.isElement()) { | ||
return; | ||
} | ||
Element element = (Element) node; | ||
CMElementDeclaration elementDeclaration = ContentModelManager.getInstance().findCMElement(element); | ||
if (elementDeclaration == null) { | ||
return; | ||
} | ||
|
||
List<CMAttributeDeclaration> requiredAttributes = elementDeclaration.getAttributes().stream().filter(CMAttributeDeclaration::isRequired).collect(Collectors.toList()); | ||
if (requiredAttributes.isEmpty()) { | ||
|
||
} | ||
XMLGenerator generator = new XMLGenerator(null, "", "", true, 0); | ||
String xmlAttributes = generator.generate(requiredAttributes); | ||
|
||
// Insert content | ||
CodeAction removeContentAction = CodeActionFactory.insert("Insert required attributes", range, | ||
xmlAttributes, | ||
document.getTextDocument(), diagnostic); | ||
codeActions.add(removeContentAction); | ||
} catch (Exception e) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
} |
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
6 changes: 6 additions & 0 deletions
6
org.eclipse.lsp4xml/src/test/resources/validation/schema/cvc-complex-type_4.xml
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<bean> | ||
<property></property> | ||
</bean> | ||
</beans> |