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.
Fix error range DTD declaration missing space
If a ELEMENT, ENTITY, or ATTLIST is missing a space after its declaration, i.e.: ```dtd <!ENTITYnbsp ``` The declaration keyword is used as the error range. i.e.: ```dtd <!|ENTITY|nbsp ``` Also adds a code action to add a space after these declarations. Closes eclipse-lemminx#902 Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
3 changed files
with
134 additions
and
2 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
47 changes: 47 additions & 0 deletions
47
...e/lemminx/extensions/contentmodel/participants/codeactions/FixMissingSpaceCodeAction.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,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. 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 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants.codeactions; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.lemminx.commons.BadLocationException; | ||
import org.eclipse.lemminx.commons.CodeActionFactory; | ||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.services.extensions.ICodeActionParticipant; | ||
import org.eclipse.lemminx.services.extensions.IComponentProvider; | ||
import org.eclipse.lemminx.settings.SharedSettings; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.Range; | ||
|
||
/** | ||
* Adds a space at the end of the diagnostic range | ||
* | ||
*/ | ||
public class FixMissingSpaceCodeAction implements ICodeActionParticipant { | ||
|
||
@Override | ||
public void doCodeAction(Diagnostic diagnostic, Range range, DOMDocument document, List<CodeAction> codeActions, | ||
SharedSettings sharedSettings, IComponentProvider componentProvider) { | ||
Range diagnosticRange = diagnostic.getRange(); | ||
try { | ||
int startOffset = document.offsetAt(diagnosticRange.getStart()); | ||
int endOffset = document.offsetAt(diagnosticRange.getEnd()); | ||
String text = document.getText(); | ||
String value = text.substring(startOffset, endOffset); | ||
codeActions.add(CodeActionFactory.insert("Add space after '" + value + "'", diagnosticRange.getEnd(), " ", | ||
document.getTextDocument(), diagnostic)); | ||
} catch (BadLocationException | IndexOutOfBoundsException e) { | ||
codeActions.add(CodeActionFactory.insert("Add space", diagnosticRange.getEnd(), " ", | ||
document.getTextDocument(), diagnostic)); | ||
} | ||
} | ||
|
||
} |
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