Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade lsp4j version to 0.7.1 and fixed errors it introduced #374

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.lsp4j.FoldingRangeRequestParams;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.ReferenceParams;
import org.eclipse.lsp4j.RenameParams;
Expand Down Expand Up @@ -144,7 +145,7 @@ public void triggerValidationIfNeeded() {
private BasicCancelChecker monitor;
private boolean codeActionLiteralSupport;
private boolean hierarchicalDocumentSymbolSupport;

public XMLTextDocumentService(XMLLanguageServer xmlLanguageServer) {
this.xmlLanguageServer = xmlLanguageServer;
this.documents = new TextDocuments();
Expand Down Expand Up @@ -183,8 +184,7 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
String uri = params.getTextDocument().getUri();
TextDocument document = getDocument(uri);
DOMDocument xmlDocument = getXMLDocument(document);
CompletionList list = getXMLLanguageService().doComplete(xmlDocument, params.getPosition(),
sharedSettings);
CompletionList list = getXMLLanguageService().doComplete(xmlDocument, params.getPosition(), sharedSettings);
return Either.forRight(list);
});
}
Expand Down Expand Up @@ -311,11 +311,13 @@ public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams par
}

@Override
public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams params) {
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(
TextDocumentPositionParams params) {
return computeAsync((monitor) -> {
TextDocument document = getDocument(params.getTextDocument().getUri());
DOMDocument xmlDocument = getXMLDocument(document);
return getXMLLanguageService().findDefinition(xmlDocument, params.getPosition());
Either e = Either.forLeft(getXMLLanguageService().findDefinition(xmlDocument, params.getPosition()));
return e;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.lsp4xml.services.extensions.ICompletionRequest;
import org.eclipse.lsp4xml.services.extensions.ICompletionResponse;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.utils.StringUtils;

/**
* This class holds values that represent the XSI xsd. Can be seen at
Expand Down Expand Up @@ -124,7 +125,7 @@ private static void createCompletionItem(String attrName, boolean canSupportSnip
MarkupContent markup = new MarkupContent();
markup.setKind(MarkupKind.MARKDOWN);

markup.setValue(documentation);
markup.setValue(StringUtils.getDefaultString(documentation));
item.setDocumentation(markup);
response.addCompletionItem(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static void createCompletionItem(String attrName, boolean canSupportSnip
defaultValue, enumerationValues, settings);
MarkupContent markup = new MarkupContent();
markup.setKind(MarkupKind.MARKDOWN);
markup.setValue(documentation);
markup.setValue(StringUtils.getDefaultString(documentation));
item.setDocumentation(markup);
response.addCompletionItem(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,18 @@ public static int getNumberOfNewLines(String text, boolean isWhitespace, String
return newLineCounter;
}

/**
* Given a string will give back a non null string that is either
* the given string, or an empty string.
*
* @param text
* @return
*/
public static String getDefaultString(String text) {
if(text != null) {
return text;
}
return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.lsp4xml.services.extensions.save.AbstractSaveContext;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.utils.StringUtils;
import org.junit.Assert;

/**
Expand Down Expand Up @@ -82,6 +83,7 @@ public DOMDocument getDocument(String uri) {
public void collectDocumentToValidate(Predicate<DOMDocument> validateDocumentPredicate) {

}

}

public static void testCompletionFor(String value, CompletionItem... expectedItems) throws BadLocationException {
Expand Down Expand Up @@ -194,7 +196,8 @@ private static void assertCompletion(CompletionList completions, CompletionItem
if (expected.getTextEdit().getNewText() != null) {
Assert.assertEquals(expected.getTextEdit().getNewText(), match.getTextEdit().getNewText());
}
if (expected.getTextEdit().getRange() != null) {
Range r = expected.getTextEdit().getRange();
if (r != null && r.getStart() != null && r.getEnd() != null) {
Assert.assertEquals(expected.getTextEdit().getRange(), match.getTextEdit().getRange());
}
}
Expand All @@ -217,7 +220,7 @@ public static CompletionItem c(String label, String newText) {
}

public static CompletionItem c(String label, String newText, String filterText) {
return c(label, newText, null, filterText);
return c(label, newText, new Range(), filterText);
}

public static CompletionItem c(String label, String newText, Range range, String filterText) {
Expand Down Expand Up @@ -303,14 +306,14 @@ public static void assertDiagnostics(List<Diagnostic> actual, Diagnostic... expe
public static void assertDiagnostics(List<Diagnostic> actual, List<Diagnostic> expected, boolean filter) {
List<Diagnostic> received = actual;
final boolean filterMessage;
if(expected != null && !expected.isEmpty() && expected.get(0).getMessage() != null) {
if(expected != null && !expected.isEmpty() && !StringUtils.isEmpty(expected.get(0).getMessage())) {
filterMessage = true;
} else {
filterMessage = false;
}
if (filter) {
received = actual.stream().map(d -> {
Diagnostic simpler = new Diagnostic(d.getRange(), null);
Diagnostic simpler = new Diagnostic(d.getRange(), "");
simpler.setCode(d.getCode());
if(filterMessage) {
simpler.setMessage(d.getMessage());
Expand All @@ -322,7 +325,7 @@ public static void assertDiagnostics(List<Diagnostic> actual, List<Diagnostic> e
}

public static Diagnostic d(int startLine, int startCharacter, int endLine, int endCharacter, IXMLErrorCode code) {
return d(startLine, startCharacter, endLine, endCharacter, code, null);
return d(startLine, startCharacter, endLine, endCharacter, code, "");
}

public static Diagnostic d(int startLine, int startCharacter, int endCharacter, IXMLErrorCode code) {
Expand Down Expand Up @@ -450,21 +453,23 @@ public static void assertCodeActions(List<CodeAction> actual, CodeAction... expe
// we don't want to compare title, etc
ca.setCommand(null);
ca.setKind(null);
ca.setTitle(null);
ca.setTitle("");
if (ca.getDiagnostics() != null) {
ca.getDiagnostics().forEach(d -> {
d.setSeverity(null);
d.setMessage(null);
d.setMessage("");
d.setSource(null);
});
}
});

Assert.assertEquals(expected.length, actual.size());
Assert.assertArrayEquals(expected, actual.toArray());
}

public static CodeAction ca(Diagnostic d, TextEdit te) {
CodeAction codeAction = new CodeAction();
codeAction.setTitle("");
codeAction.setDiagnostics(Arrays.asList(d));

VersionedTextDocumentIdentifier versionedTextDocumentIdentifier = new VersionedTextDocumentIdentifier(FILE_URI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TextDocumentTest {

@Test
public void testEmptyDocument() throws BadLocationException {
TextDocument document = new TextDocument("", null);
TextDocument document = new TextDocument("", "");

Position position = document.positionAt(0);
Assert.assertEquals(0, position.getLine());
Expand All @@ -36,7 +36,7 @@ public void testEmptyDocument() throws BadLocationException {

@Test
public void testPositionAt() throws BadLocationException {
TextDocument document = new TextDocument("abcd\nefgh", null);
TextDocument document = new TextDocument("abcd\nefgh", "");

Position position = document.positionAt(0);
Assert.assertEquals(0, position.getLine());
Expand Down Expand Up @@ -65,7 +65,7 @@ public void testPositionAt() throws BadLocationException {

@Test
public void testPositionAtEndLine() throws BadLocationException {
TextDocument document = new TextDocument("abcd\n", null);
TextDocument document = new TextDocument("abcd\n", "");

Position position = document.positionAt(4);
Assert.assertEquals(0, position.getLine());
Expand All @@ -83,7 +83,7 @@ public void testPositionAtEndLine() throws BadLocationException {
}
Assert.assertNotNull(ex);

document = new TextDocument("abcd\nefgh\n", null);
document = new TextDocument("abcd\nefgh\n", "");

position = document.positionAt(9);
Assert.assertEquals(1, position.getLine());
Expand All @@ -104,7 +104,7 @@ public void testPositionAtEndLine() throws BadLocationException {

@Test
public void testOffsetAt() throws BadLocationException {
TextDocument document = new TextDocument("abcd\nefgh", null);
TextDocument document = new TextDocument("abcd\nefgh", "");

Position position = new Position(0, 0);
int offset = document.offsetAt(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public void testPreserveWhitespaceContent() {

@Test
public void elementOffsets() {
DOMDocument document = DOMParser.getInstance().parse("<a></a>", null, null);
DOMDocument document = DOMParser.getInstance().parse("<a></a>", "", null);
DOMElement a = document.getDocumentElement();
Assert.assertNotNull(a);
Assert.assertEquals(a.getTagName(), "a");
Expand Down Expand Up @@ -493,7 +493,7 @@ public void testDoctype2() {
" <!ENTITY nbsp \"&#xA0;\"> \n" +
" <!ENTITY writer \"Writer: Donald Duck.\">\n" +
" <!ENTITY copyright \"Copyright: W3Schools.\">\n ";
DOMDocument document = DOMParser.getInstance().parse(xml, null, null);
DOMDocument document = DOMParser.getInstance().parse(xml, "", null);
assertDoctype((DOMDocumentType)(document.getChild(0)), 0, 212, "html", DocumentTypeKind.SYSTEM.name(), null, "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"", internal);
}

Expand All @@ -511,7 +511,7 @@ public void testDTDEntity() {
entity.closed = true;
doctype.addChild(entity);

DOMDocument document = DOMParser.getInstance().parse(xml, null, null);
DOMDocument document = DOMParser.getInstance().parse(xml, "", null);
compareTrees(doctype, document.getChild(0));

}
Expand All @@ -538,7 +538,7 @@ public void testDTDAllTypes() {
doctype.addChild(element);
doctype.addChild(attlist);

DOMDocument document = DOMParser.getInstance().parse(xml, null, null);
DOMDocument document = DOMParser.getInstance().parse(xml, "", null);
compareTrees(doctype, document.getChild(0));

}
Expand Down Expand Up @@ -885,8 +885,8 @@ private static DOMDocumentType createDoctypeNode(int start, int end, Integer nam
Integer kindEnd, Integer publicIdStart, Integer publicIdEnd, Integer systemIdStart, Integer systemIdEnd,
Integer internalSubsetStart, Integer internalSubsetEnd) {
DOMDocumentType doctype = new DOMDocumentType(start, end, null);
doctype.name = nameStart != null ? new DTDDeclParameter(null, nameStart, nameEnd) : null;;
doctype.kind = kindStart != null ? new DTDDeclParameter(null, kindStart, kindEnd) : null;;
doctype.name = nameStart != null ? new DTDDeclParameter(null, nameStart, nameEnd) : null;
doctype.kind = kindStart != null ? new DTDDeclParameter(null, kindStart, kindEnd) : null;
doctype.publicId = publicIdStart != null ? new DTDDeclParameter(null, publicIdStart, publicIdEnd) : null;;
doctype.systemId = systemIdEnd != null ? new DTDDeclParameter(null, systemIdStart, systemIdEnd) : null;;
doctype.internalSubset = internalSubsetStart != null ? new DTDDeclParameter(null, internalSubsetStart, internalSubsetEnd) : null;;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>lsp4xml is an XML specific implementation of the Language Server Protocol (LSP), and can be used with any editor that supports LSP, to offer an outstanding XML editing experience</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lsp4j.version>0.6.0</lsp4j.version>
<lsp4j.version>0.7.1</lsp4j.version>
</properties>
<url>https://github.com/angelozerr/lsp4xml</url>
<licenses>
Expand Down