Skip to content

Commit

Permalink
Add tagname to code action
Browse files Browse the repository at this point in the history
Signed-off-by: Omar Farag <omarfarag74@gmail.com>
  • Loading branch information
o-farag committed Sep 5, 2023
1 parent cb2175b commit 2767b99
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@


import org.eclipse.lsp4j.Range;
import org.eclipse.lemminx.commons.BadLocationException;
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.dom.DOMElement;
import org.eclipse.lemminx.dom.DOMNode;
import org.eclipse.lemminx.services.extensions.codeaction.ICodeActionParticipant;
import org.eclipse.lemminx.services.extensions.codeaction.ICodeActionRequest;

Expand All @@ -20,15 +23,27 @@ public void doCodeAction(ICodeActionRequest request, List<CodeAction> codeAction
Diagnostic diagnostic = request.getDiagnostic();
DOMDocument document = request.getDocument();
Range diagnosticRange = diagnostic.getRange();
String codeActionText;

// Attempt to get tag name
try {
int startOffset = document.offsetAt(diagnosticRange.getStart()) + 1;
DOMNode node = document.findNodeAt(startOffset);
DOMElement element = (DOMElement) node;
String tagName = element.getTagName();
codeActionText = "Replace '" + tagName + "' with ";
} catch (BadLocationException e) {
codeActionText = "Replace with ";
}


// Replace with "appinfo"
CodeAction replaceAction_appinfo = CodeActionFactory.replace("Replace with \"appinfo\"", diagnosticRange,
CodeAction replaceAction_appinfo = CodeActionFactory.replace(codeActionText + "'xs:appinfo'", diagnosticRange,
"xs:appinfo",
document.getTextDocument(), diagnostic);

// Replace with "documentation"
CodeAction replaceAction_documentation = CodeActionFactory.replace("Replace with \"documentation\"", diagnosticRange,
CodeAction replaceAction_documentation = CodeActionFactory.replace(codeActionText + "'xs:documentation'", diagnosticRange,
"xs:documentation",
document.getTextDocument(), diagnostic);

Expand Down

0 comments on commit 2767b99

Please sign in to comment.