forked from eclipse/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.
Fixes eclipse#588 Signed-off-by: Nikolas Komonen <[email protected]>
- Loading branch information
1 parent
bc9f68b
commit e026c08
Showing
4 changed files
with
61 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
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
51 changes: 51 additions & 0 deletions
51
...4xml/extensions/contentmodel/participants/codeactions/MarkupEntityMismatchCodeAction.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,51 @@ | ||
package org.eclipse.lsp4xml.extensions.contentmodel.participants.codeactions; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4xml.commons.BadLocationException; | ||
import org.eclipse.lsp4xml.commons.CodeActionFactory; | ||
import org.eclipse.lsp4xml.dom.DOMDocument; | ||
import org.eclipse.lsp4xml.dom.DOMElement; | ||
import org.eclipse.lsp4xml.dom.DOMNode; | ||
import org.eclipse.lsp4xml.services.extensions.ICodeActionParticipant; | ||
import org.eclipse.lsp4xml.services.extensions.IComponentProvider; | ||
import org.eclipse.lsp4xml.settings.XMLFormattingOptions; | ||
|
||
/** | ||
* MarkupEntityMismatchCodeAction | ||
*/ | ||
public class MarkupEntityMismatchCodeAction implements ICodeActionParticipant { | ||
|
||
@Override | ||
public void doCodeAction(Diagnostic diagnostic, Range range, DOMDocument document, List<CodeAction> codeActions, | ||
XMLFormattingOptions formattingSettings, IComponentProvider componentProvider) { | ||
|
||
|
||
try { | ||
int offset = document.offsetAt(diagnostic.getRange().getStart()); | ||
DOMNode node = document.findNodeAt(offset); | ||
if(!node.isElement()) { | ||
return; | ||
} | ||
|
||
DOMElement element = (DOMElement) node; | ||
int startOffset = element.getStartTagOpenOffset(); | ||
Position startPosition = document.positionAt(startOffset); | ||
Position endPosition = document.positionAt(document.getEnd()); | ||
endPosition.setCharacter(startPosition.getCharacter()); | ||
String elementName = element.getTagName(); | ||
CodeAction action = CodeActionFactory.insert("Close with '</" + elementName + ">'", endPosition, "</" + elementName + ">", document.getTextDocument(), diagnostic); | ||
codeActions.add(action); | ||
} catch (BadLocationException e) { | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
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