-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code action to insert missing ="" for attribute value.
- Loading branch information
1 parent
90bd091
commit 492212a
Showing
3 changed files
with
68 additions
and
5 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
56 changes: 56 additions & 0 deletions
56
...clipse/lsp4xml/contentmodel/participants/codeactions/EqRequiredInAttributeCodeAction.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,56 @@ | ||
/** | ||
* 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 org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4xml.commons.BadLocationException; | ||
import org.eclipse.lsp4xml.commons.CodeActionFactory; | ||
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; | ||
import org.eclipse.lsp4xml.settings.XMLFormattingOptions; | ||
|
||
/** | ||
* Code action to fix EqRequiredInAttribute error. | ||
* | ||
*/ | ||
public class EqRequiredInAttributeCodeAction implements ICodeActionParticipant { | ||
|
||
@Override | ||
public void doCodeAction(Diagnostic diagnostic, Range range, XMLDocument document, List<CodeAction> codeActions, | ||
XMLFormattingOptions formattingSettings) { | ||
Range diagnosticRange = diagnostic.getRange(); | ||
|
||
// Insert ="" | ||
try { | ||
int offset = document.offsetAt(range.getStart()); | ||
Node node = document.findNodeAt(offset); | ||
if (node != null && node.isElement()) { | ||
String tagName = ((Element) node).getTagName(); | ||
if (tagName != null) { | ||
String insertText = "=\"\""; | ||
CodeAction insertEqualsAndQuotesAction = CodeActionFactory.insert( | ||
"Insert '" + insertText + "'", diagnosticRange, insertText, | ||
document.getTextDocument(), diagnostic); | ||
codeActions.add(insertEqualsAndQuotesAction); | ||
} | ||
} | ||
} catch (BadLocationException 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