Skip to content

Commit

Permalink
Implement textDocument/selectionRange
Browse files Browse the repository at this point in the history
Closes #1021

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed May 31, 2021
1 parent 6359bd3 commit 4497ae5
Show file tree
Hide file tree
Showing 12 changed files with 823 additions and 37 deletions.
Expand Up @@ -45,13 +45,13 @@
import org.eclipse.lemminx.settings.InitializationOptionsSettings;
import org.eclipse.lemminx.settings.ServerSettings;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lemminx.settings.XMLTelemetrySettings;
import org.eclipse.lemminx.settings.XMLCodeLensSettings;
import org.eclipse.lemminx.settings.XMLCompletionSettings;
import org.eclipse.lemminx.settings.XMLFormattingOptions;
import org.eclipse.lemminx.settings.XMLGeneralClientSettings;
import org.eclipse.lemminx.settings.XMLPreferences;
import org.eclipse.lemminx.settings.XMLSymbolSettings;
import org.eclipse.lemminx.settings.XMLTelemetrySettings;
import org.eclipse.lemminx.settings.capabilities.InitializationOptionsExtendedClientCapabilities;
import org.eclipse.lemminx.settings.capabilities.ServerCapabilitiesInitializer;
import org.eclipse.lemminx.settings.capabilities.XMLCapabilityManager;
Expand Down
Expand Up @@ -85,6 +85,8 @@
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.ReferenceParams;
import org.eclipse.lsp4j.RenameParams;
import org.eclipse.lsp4j.SelectionRange;
import org.eclipse.lsp4j.SelectionRangeParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
import org.eclipse.lsp4j.TextDocumentIdentifier;
Expand Down Expand Up @@ -459,6 +461,13 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
});
}

@Override
public CompletableFuture<List<SelectionRange>> selectionRange(SelectionRangeParams params) {
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
return getXMLLanguageService().getSelectionRanges(xmlDocument, params.getPositions(), cancelChecker);
});
}

@Override
public void didSave(DidSaveTextDocumentParams params) {
computeAsync((monitor) -> {
Expand Down
Expand Up @@ -62,6 +62,11 @@ public DOMAttr getOwnerAttr() {
return DOMAttr.this;
}

@Override
public DOMNode getParentNode() {
return DOMAttr.this;
}

@Override
public DOMDocument getOwnerDocument() {
return getOwnerAttr().getOwnerDocument();
Expand All @@ -81,7 +86,7 @@ public DOMAttr(String name, int start, int end, DOMNode ownerElement) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNodeType()
*/
@Override
Expand All @@ -91,7 +96,7 @@ public short getNodeType() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNodeName()
*/
@Override
Expand All @@ -101,7 +106,7 @@ public String getNodeName() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#getName()
*/
@Override
Expand All @@ -125,7 +130,7 @@ public String getLocalName() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#getOwnerElement()
*/
public DOMElement getOwnerElement() {
Expand All @@ -138,7 +143,7 @@ public DOMDocument getOwnerDocument() {
}

/*
*
*
* Returns the attribute's value without quotes.
*/
@Override
Expand All @@ -148,7 +153,7 @@ public String getValue() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#getSchemaTypeInfo()
*/
@Override
Expand All @@ -158,7 +163,7 @@ public TypeInfo getSchemaTypeInfo() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#getSpecified()
*/
@Override
Expand All @@ -168,7 +173,7 @@ public boolean getSpecified() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#isId()
*/
@Override
Expand All @@ -178,7 +183,7 @@ public boolean isId() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Attr#setValue(java.lang.String)
*/
@Override
Expand All @@ -200,9 +205,9 @@ public boolean hasDelimiter() {

/**
* Get original attribute value from the document.
*
*
* This will include quotations (", ').
*
*
* @return attribute value with quotations if it had them.
*/
public String getOriginalValue() {
Expand All @@ -229,7 +234,7 @@ public boolean valueContainsOffset(int offset) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getPrefix()
*/
@Override
Expand All @@ -248,7 +253,7 @@ public String getPrefix() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNamespaceURI()
*/
@Override
Expand All @@ -263,7 +268,7 @@ public String getNamespaceURI() {

/**
* Returns true if attribute name is a xmlns attribute and false otherwise.
*
*
* @param attributeName
* @return true if attribute name is a xmlns attribute and false otherwise.
*/
Expand All @@ -278,7 +283,7 @@ public static boolean isXmlns(String attributeName) {
/**
* Returns true if attribute name is the default xmlns attribute and false
* otherwise.
*
*
* @param attributeName
* @return true if attribute name is the default xmlns attribute and false
* otherwise.
Expand All @@ -300,9 +305,9 @@ public String extractPrefixFromXmlns() {

/**
* Returns the prefix if the given URI matches this attributes value.
*
*
* If the URI doesnt match, null is returned.
*
*
* @param uri
* @return
*/
Expand All @@ -323,7 +328,7 @@ public String getPrefixIfMatchesURI(String uri) {
/**
* Returns true if attribute name is the no default xmlns attribute and false
* otherwise.
*
*
* @param attributeName
* @return true if attribute name is the no default xmlns attribute and false
* otherwise.
Expand All @@ -338,7 +343,7 @@ public static boolean isNoDefaultXmlns(String attributeName) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNextSibling()
*/
@Override
Expand Down
Expand Up @@ -54,7 +54,7 @@ public String getTextContent() {

/**
* Returns the document type kind (PUBLIC or SYSTEM)
*
*
* @return the document type kind (PUBLIC or SYSTEM)
*/
public String getKind() {
Expand All @@ -63,7 +63,7 @@ public String getKind() {

/**
* Returns the node where document type kind (PUBLIC or SYSTEM) is declared
*
*
* @return the node where document type kind (PUBLIC or SYSTEM) is declared
*/
public DTDDeclParameter getKindNode() {
Expand All @@ -79,7 +79,7 @@ void setKind(int start, int end) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNodeName()
*/
@Override
Expand All @@ -89,7 +89,7 @@ public String getNodeName() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.Node#getNodeType()
*/
@Override
Expand All @@ -99,7 +99,7 @@ public short getNodeType() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.DocumentType#getEntities()
*/
@Override
Expand All @@ -118,7 +118,7 @@ public NamedNodeMap getEntities() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.DocumentType#getInternalSubset()
*/
@Override
Expand Down Expand Up @@ -147,7 +147,7 @@ public boolean isInternalSubset(DTDDeclParameter parameter) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.DocumentType#getNotations()
*/
@Override
Expand All @@ -157,7 +157,7 @@ public NamedNodeMap getNotations() {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.DocumentType#getPublicId()
*/
@Override
Expand All @@ -172,7 +172,7 @@ public String getPublicIdWithoutQuotes() {
public DTDDeclParameter getPublicIdNode() {
return publicId;
}

/**
* @param publicId the publicId to set
*/
Expand All @@ -182,7 +182,7 @@ void setPublicId(int start, int end) {

/*
* (non-Javadoc)
*
*
* @see org.w3c.dom.DocumentType#getSystemId()
*/
@Override
Expand All @@ -208,7 +208,7 @@ void setSystemId(int start, int end) {
/**
* Returns a substring of the whole document.
*
*
*
* Since offset values are relative to 'this.start' we need to subtract
* getStart() to make them relative to 'content'
*/
Expand All @@ -220,4 +220,13 @@ public String getSubstring(int start, int end) {
return textContent.substring(start - getStart(), end - getStart());
}

/**
* Returns the declaration parameter that represents the internal subset, or null if there is no internal subset
*
* @return the declaration parameter that represents the internal subset, or null if there is no internal subset
*/
public DTDDeclParameter getInternalSubsetNode() {
return this.internalSubset;
}

}
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.ReferenceContext;
import org.eclipse.lsp4j.SelectionRange;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void checkCanceled() {
private final XMLCodeLens codelens;
private final XMLCodeActions codeActions;
private final XMLRename rename;
private final XMLSelectionRanges selectionRanges;

public XMLLanguageService() {
this.formatter = new XMLFormatter(this);
Expand All @@ -100,6 +102,7 @@ public XMLLanguageService() {
this.codelens = new XMLCodeLens(this);
this.codeActions = new XMLCodeActions(this);
this.rename = new XMLRename(this);
this.selectionRanges = new XMLSelectionRanges();
}

@Override
Expand Down Expand Up @@ -225,6 +228,10 @@ public List<FoldingRange> getFoldingRanges(DOMDocument xmlDocument, XMLFoldingSe
return foldings.getFoldingRanges(xmlDocument.getTextDocument(), context, cancelChecker);
}

public List<SelectionRange> getSelectionRanges(DOMDocument xmlDocument, List<Position> positions, CancelChecker cancelChecker) {
return selectionRanges.getSelectionRanges(xmlDocument, positions, cancelChecker);
}

public WorkspaceEdit doRename(DOMDocument xmlDocument, Position position, String newText) {
return rename.doRename(xmlDocument, position, newText);
}
Expand Down

0 comments on commit 4497ae5

Please sign in to comment.