Skip to content

Commit

Permalink
Hover markup kind response ignores the hover client capability
Browse files Browse the repository at this point in the history
Fix #525

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 22, 2019
1 parent 0f276b8 commit b2a37e6
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.eclipse.lsp4xml.logs.LogHelper;
import org.eclipse.lsp4xml.services.IXMLDocumentProvider;
import org.eclipse.lsp4xml.services.XMLLanguageService;
import org.eclipse.lsp4xml.services.extensions.CompletionSettings;
import org.eclipse.lsp4xml.settings.AllXMLSettings;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.InitializationOptionsSettings;
import org.eclipse.lsp4xml.settings.LogsSettings;
import org.eclipse.lsp4xml.settings.ServerSettings;
Expand Down Expand Up @@ -141,7 +141,7 @@ public synchronized void updateSettings(Object initializationOptionsSettings) {
xmlTextDocumentService.getSharedFormattingSettings().merge(formatterSettings);
}

CompletionSettings newCompletions = xmlClientSettings.getCompletion();
XMLCompletionSettings newCompletions = xmlClientSettings.getCompletion();
if (newCompletions != null) {
xmlTextDocumentService.updateCompletionSettings(newCompletions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
import org.eclipse.lsp4xml.dom.DOMParser;
import org.eclipse.lsp4xml.extensions.contentmodel.settings.XMLValidationSettings;
import org.eclipse.lsp4xml.services.XMLLanguageService;
import org.eclipse.lsp4xml.services.extensions.CompletionSettings;
import org.eclipse.lsp4xml.services.extensions.save.AbstractSaveContext;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLCodeLensSettings;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
import org.eclipse.lsp4xml.utils.XMLPositionUtility;
Expand Down Expand Up @@ -148,8 +148,9 @@ public void updateClientCapabilities(ClientCapabilities capabilities,
ExtendedClientCapabilities extendedClientCapabilities) {
TextDocumentClientCapabilities textDocumentClientCapabilities = capabilities.getTextDocument();
if (textDocumentClientCapabilities != null) {
// Completion settings
sharedSettings.getCompletionSettings().setCapabilities(textDocumentClientCapabilities.getCompletion());
sharedSettings.getFoldingSettings().setCapabilities(textDocumentClientCapabilities.getFoldingRange());
sharedSettings.getHoverSettings().setCapabilities(textDocumentClientCapabilities.getHover());
codeActionLiteralSupport = textDocumentClientCapabilities.getCodeAction() != null
&& textDocumentClientCapabilities.getCodeAction().getCodeActionLiteralSupport() != null;
hierarchicalDocumentSymbolSupport = textDocumentClientCapabilities.getDocumentSymbol() != null
Expand Down Expand Up @@ -180,7 +181,8 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams params) {
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
return getXMLLanguageService().doHover(xmlDocument, params.getPosition(), cancelChecker);
return getXMLLanguageService().doHover(xmlDocument, params.getPosition(), sharedSettings.getHoverSettings(),
cancelChecker);
});
}

Expand Down Expand Up @@ -438,7 +440,7 @@ private XMLLanguageService getXMLLanguageService() {
return xmlLanguageServer.getXMLLanguageService();
}

public void updateCompletionSettings(CompletionSettings newCompletion) {
public void updateCompletionSettings(XMLCompletionSettings newCompletion) {
sharedSettings.getCompletionSettings().merge(newCompletion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.eclipse.lsp4xml.dom.DOMDocument;
import org.eclipse.lsp4xml.dom.DOMNode;
import org.eclipse.lsp4xml.extensions.contentmodel.utils.XMLGenerator;
import org.eclipse.lsp4xml.services.extensions.CompletionSettings;
import org.eclipse.lsp4xml.services.extensions.ICompletionRequest;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.utils.StringUtils;
Expand All @@ -29,7 +29,7 @@
*/
class CompletionRequest extends AbstractPositionRequest implements ICompletionRequest {

private final CompletionSettings completionSettings;
private final XMLCompletionSettings completionSettings;

private final XMLFormattingOptions formattingSettings;

Expand Down Expand Up @@ -62,7 +62,7 @@ public XMLFormattingOptions getFormattingSettings() {
}

@Override
public CompletionSettings getCompletionSettings() {
public XMLCompletionSettings getCompletionSettings() {
return completionSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
import org.eclipse.lsp4xml.dom.DOMNode;
import org.eclipse.lsp4xml.services.extensions.IHoverRequest;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.XMLHoverSettings;

/**
* Hover request implementation.
*
*/
class HoverRequest extends AbstractPositionRequest implements IHoverRequest {

private final XMLHoverSettings settings;

private final XMLExtensionsRegistry extensionsRegistry;

private Range tagRange;

private boolean open;

public HoverRequest(DOMDocument xmlDocument, Position position, XMLExtensionsRegistry extensionsRegistry)
throws BadLocationException {
public HoverRequest(DOMDocument xmlDocument, Position position, XMLHoverSettings settings,
XMLExtensionsRegistry extensionsRegistry) throws BadLocationException {
super(xmlDocument, position);
this.settings = settings;
this.extensionsRegistry = extensionsRegistry;
}

Expand Down Expand Up @@ -74,7 +78,9 @@ public <T> T getComponent(Class clazz) {

@Override
public boolean canSupportMarkupKind(String kind) {
// FIXME : use the hover capability to know if the given kind is supported
return true;
return settings != null && settings.getCapabilities() != null
&& settings.getCapabilities().getContentFormat() != null
&& settings.getCapabilities().getContentFormat().contains(kind);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
import org.eclipse.lsp4xml.dom.parser.TokenType;
import org.eclipse.lsp4xml.dom.parser.XMLScanner;
import org.eclipse.lsp4xml.extensions.prolog.PrologModel;
import org.eclipse.lsp4xml.services.extensions.CompletionSettings;
import org.eclipse.lsp4xml.services.extensions.ICompletionParticipant;
import org.eclipse.lsp4xml.services.extensions.ICompletionRequest;
import org.eclipse.lsp4xml.services.extensions.ICompletionResponse;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.utils.StringUtils;

Expand Down Expand Up @@ -513,7 +513,7 @@ private void collectOpenTagSuggestions(boolean hasOpenBracket, Range replaceRang
xml.append(" />");
} else {
xml.append(">");
CompletionSettings completionSettings = completionRequest.getCompletionSettings();
XMLCompletionSettings completionSettings = completionRequest.getCompletionSettings();

if (completionSettings.isCompletionSnippetsSupported()) {
xml.append("$0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.regex.Pattern;

import org.eclipse.lsp4j.FoldingRange;
import org.eclipse.lsp4j.FoldingRangeCapabilities;
import org.eclipse.lsp4j.FoldingRangeKind;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.eclipse.lsp4xml.commons.BadLocationException;
Expand All @@ -32,6 +31,7 @@
import org.eclipse.lsp4xml.dom.parser.TokenType;
import org.eclipse.lsp4xml.dom.parser.XMLScanner;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.XMLFoldingSettings;

/**
* XML folding support.
Expand Down Expand Up @@ -59,7 +59,8 @@ public TagInfo(int startLine, String tagName) {
}
}

public List<FoldingRange> getFoldingRanges(TextDocument document, FoldingRangeCapabilities context, CancelChecker cancelChecker) {
public List<FoldingRange> getFoldingRanges(TextDocument document, XMLFoldingSettings context,
CancelChecker cancelChecker) {
Scanner scanner = XMLScanner.createScanner(document.getText());
TokenType token = scanner.scan();
List<FoldingRange> ranges = new ArrayList<>();
Expand Down Expand Up @@ -153,10 +154,10 @@ public List<FoldingRange> getFoldingRanges(TextDocument document, FoldingRangeCa
}
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Foldings received a BadLocation while scanning the document", e);
}
catch(StackOverflowError e) {
} catch (StackOverflowError e) {
// This exception occurs with large file, why?
// For the moment we catch it.
LOGGER.log(Level.SEVERE, "Foldings received a StackOverflowError while scanning the document", e);
}
return ranges;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.lsp4xml.dom.parser.XMLScanner;
import org.eclipse.lsp4xml.services.extensions.IHoverParticipant;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.XMLHoverSettings;

/**
* XML hover support.
Expand All @@ -42,10 +43,11 @@ public XMLHover(XMLExtensionsRegistry extensionsRegistry) {
this.extensionsRegistry = extensionsRegistry;
}

public Hover doHover(DOMDocument xmlDocument, Position position, CancelChecker cancelChecker) {
public Hover doHover(DOMDocument xmlDocument, Position position, XMLHoverSettings settings,
CancelChecker cancelChecker) {
HoverRequest hoverRequest = null;
try {
hoverRequest = new HoverRequest(xmlDocument, position, extensionsRegistry);
hoverRequest = new HoverRequest(xmlDocument, position, settings, extensionsRegistry);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Failed creating HoverRequest", e);
return null;
Expand All @@ -72,7 +74,7 @@ public Hover doHover(DOMDocument xmlDocument, Position position, CancelChecker c
}
} else if (node.isAttribute()) {
DOMAttr attr = (DOMAttr) node;
if(attr.valueContainsOffset(offset)) {
if (attr.valueContainsOffset(offset)) {
return getAttrValueHover(hoverRequest, null);
}
// Attribute is hover
Expand Down Expand Up @@ -129,12 +131,12 @@ private Range getTagNameRange(TokenType tokenType, int startOffset, int offset,
* Returns the LSP hover from the hovered attribute.
*
* @param hoverRequest the hover request.
* @param attrRange the attribute range
* @param attrRange the attribute range
* @return the LSP hover from the hovered attribute.
*/
private Hover getAttrNameHover(HoverRequest hoverRequest, Range attrRange) {
//hoverRequest.setTagRange(tagRange);
//hoverRequest.setOpen(open);
// hoverRequest.setTagRange(tagRange);
// hoverRequest.setOpen(open);
for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
try {
Hover hover = participant.onAttributeName(hoverRequest);
Expand All @@ -152,12 +154,12 @@ private Hover getAttrNameHover(HoverRequest hoverRequest, Range attrRange) {
* Returns the LSP hover from the hovered attribute.
*
* @param hoverRequest the hover request.
* @param attrRange the attribute range
* @param attrRange the attribute range
* @return the LSP hover from the hovered attribute.
*/
private Hover getAttrValueHover(HoverRequest hoverRequest, Range attrRange) {
//hoverRequest.setTagRange(tagRange);
//hoverRequest.setOpen(open);
// hoverRequest.setTagRange(tagRange);
// hoverRequest.setOpen(open);
for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
try {
Hover hover = participant.onAttributeValue(hoverRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.lsp4j.DocumentLink;
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.FoldingRange;
import org.eclipse.lsp4j.FoldingRangeCapabilities;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
Expand All @@ -47,7 +46,9 @@
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLCodeLensSettings;
import org.eclipse.lsp4xml.settings.XMLFoldingSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLHoverSettings;
import org.eclipse.lsp4xml.uriresolver.CacheResourceDownloadingException;
import org.eclipse.lsp4xml.utils.XMLPositionUtility;

Expand Down Expand Up @@ -135,12 +136,13 @@ public CompletionList doComplete(DOMDocument xmlDocument, Position position, Sha
return completions.doComplete(xmlDocument, position, settings, cancelChecker);
}

public Hover doHover(DOMDocument xmlDocument, Position position) {
return doHover(xmlDocument, position, NULL_CHECKER);
public Hover doHover(DOMDocument xmlDocument, Position position, XMLHoverSettings settings) {
return doHover(xmlDocument, position, settings, NULL_CHECKER);
}

public Hover doHover(DOMDocument xmlDocument, Position position, CancelChecker cancelChecker) {
return hover.doHover(xmlDocument, position, cancelChecker);
public Hover doHover(DOMDocument xmlDocument, Position position, XMLHoverSettings settings,
CancelChecker cancelChecker) {
return hover.doHover(xmlDocument, position, settings, cancelChecker);
}

public List<Diagnostic> doDiagnostics(DOMDocument xmlDocument, CancelChecker monitor,
Expand Down Expand Up @@ -193,11 +195,11 @@ private static void publishOneDiagnosticInRoot(DOMDocument document, String mess
publishDiagnostics.accept(new PublishDiagnosticsParams(uri, diagnostics));
}

public List<FoldingRange> getFoldingRanges(DOMDocument xmlDocument, FoldingRangeCapabilities context) {
public List<FoldingRange> getFoldingRanges(DOMDocument xmlDocument, XMLFoldingSettings context) {
return getFoldingRanges(xmlDocument, context, NULL_CHECKER);
}

public List<FoldingRange> getFoldingRanges(DOMDocument xmlDocument, FoldingRangeCapabilities context,
public List<FoldingRange> getFoldingRanges(DOMDocument xmlDocument, XMLFoldingSettings context,
CancelChecker cancelChecker) {
return foldings.getFoldingRanges(xmlDocument.getTextDocument(), context, cancelChecker);
}
Expand All @@ -219,13 +221,14 @@ public List<? extends LocationLink> findTypeDefinition(DOMDocument xmlDocument,
CancelChecker cancelChecker) {
return typeDefinition.findTypeDefinition(xmlDocument, position, cancelChecker);
}

public List<? extends Location> findReferences(DOMDocument xmlDocument, Position position, ReferenceContext context,
CancelChecker cancelChecker) {
return reference.findReferences(xmlDocument, position, context, cancelChecker);
}

public List<? extends CodeLens> getCodeLens(DOMDocument xmlDocument, XMLCodeLensSettings settings, CancelChecker cancelChecker) {
public List<? extends CodeLens> getCodeLens(DOMDocument xmlDocument, XMLCodeLensSettings settings,
CancelChecker cancelChecker) {
return codelens.getCodelens(xmlDocument, settings, cancelChecker);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.extensions.contentmodel.utils.XMLGenerator;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.utils.MarkupContentFactory.IMarkupKindSupport;

Expand All @@ -26,7 +27,7 @@ public interface ICompletionRequest extends IPositionRequest, IMarkupKindSupport

XMLFormattingOptions getFormattingSettings();

CompletionSettings getCompletionSettings();
XMLCompletionSettings getCompletionSettings();

XMLGenerator getXMLGenerator() throws BadLocationException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ public interface IHoverRequest extends IPositionRequest, IMarkupKindSupport {
Range getTagRange();

boolean isOpen();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@

package org.eclipse.lsp4xml.settings;

import org.eclipse.lsp4j.FoldingRangeCapabilities;
import org.eclipse.lsp4xml.extensions.contentmodel.settings.XMLValidationSettings;
import org.eclipse.lsp4xml.services.extensions.CompletionSettings;

/**
* SharedSettings
*/
public class SharedSettings {

private final CompletionSettings completionSettings;
private final FoldingRangeCapabilities foldingSettings;
private final XMLCompletionSettings completionSettings;
private final XMLFoldingSettings foldingSettings;
private final XMLFormattingOptions formattingSettings;
private final XMLValidationSettings validationSettings;
private final XMLSymbolSettings symbolSettings;
private final XMLCodeLensSettings codeLensSettings;
private final XMLHoverSettings hoverSettings;

public SharedSettings() {
this.completionSettings = new CompletionSettings();
this.foldingSettings = new FoldingRangeCapabilities();
this.completionSettings = new XMLCompletionSettings();
this.foldingSettings = new XMLFoldingSettings();
this.formattingSettings = new XMLFormattingOptions(true);
this.validationSettings = new XMLValidationSettings();
this.symbolSettings = new XMLSymbolSettings();
this.codeLensSettings = new XMLCodeLensSettings();
this.hoverSettings = new XMLHoverSettings();
}

public CompletionSettings getCompletionSettings() {
public XMLCompletionSettings getCompletionSettings() {
return completionSettings;
}

public FoldingRangeCapabilities getFoldingSettings() {
public XMLFoldingSettings getFoldingSettings() {
return foldingSettings;
}

Expand All @@ -59,4 +59,8 @@ public XMLCodeLensSettings getCodeLensSettings() {
return codeLensSettings;
}

public XMLHoverSettings getHoverSettings() {
return hoverSettings;
}

}
Loading

0 comments on commit b2a37e6

Please sign in to comment.